YUJI TOMITA

Tech Consultant. Backend Developer. Frontend Developer. Designer. Adventure Time Super Fan.

Get Instagram oAuth Token

This should be rather simple but there are no 3 step tutorials to do this. I’ve even done it multiple times in the past. Bullet points:

1: Register an application in instagram’s developer page. https://instagram.com/developer/clients/manage

2: Take the CLIENT ID from the newly created app.

3: Log into the instagram account of the client that you want access to

4: Visit the following URL, replacing client_id and redirect_uri with the ones you defined in your application. https://instagram.com/oauth/authorize/?client_id=*****************&redirect_uri=*************&response_type=token

5: Accept. NOTE: If you are using this to use a javascript / frontend / non serverside method of communicating with the API, ensure you add &scope=basic to the URL https://instagram.com/oauth/authorize/?client_id=*****************&redirect_uri=*************&response_type=code&scope=basic So that a publicly available key can’t be abused.

6: You will get your token in the redirect_url in the form of a hash (#<ACCESS_TOKEN>)

7: Profit

Removing Shopify Admin Bar

The admin bar keeps adding new tricks, like adding top: 40px to any fixed elements.

Try this:

&lt;script&gt;
try {
document.addEventListener(&quot;DOMContentLoaded&quot;, function(event) {
try {
var element = document.getElementById(&quot;admin_bar_iframe&quot;);
var html = document.getElementsByTagName(&quot;html&quot;)[0];
element.parentNode.removeChild(element);
html.style.paddingTop = &quot;0&quot;

} catch(ex) {}
})
} catch(ex) {};

function removeShopifyAdminBarHeights() {
$('[style=&quot;top: 40px;&quot;]').css('top', '');
}
$(function() {
removeShopifyAdminBarHeights();
});
setTimeout(removeShopifyAdminBarHeights, 500);
&lt;/script&gt;

Using Jinja from string with django 1.8 – undocumented

Django documents how to specify a template engine via

django.template.engines

But not what custom template engines are named.

You can specify a "NAME" parameter to your template configuration to reference it from django.template.engines.

template = engines['jinja'].from_string(template_code)

Wacom Alternative – Huion h610 Pro is Amazing

I have owned many Wacom tablets.

I own 3 right now, an Intuos Pro Medium, Intuos 4 Wide (wish they kept this dimension), and a Bamboo.

My Pro broke after a month, and while I trust it will be replaced with the warranty, I need a tablet now, and I didn’t want to drop another $350 while I wait.

I finally tried a Wacom alternative, and it is quite frankly amazing. The Huion H610 Pro for $80 or roughly 1/4th the price.

It works out of the box on my Retina MBP with Yosemite (Q1 2015 latest) with no drivers necessary. This is huge. Tablet driver issues even between Wacoms is a pain. Reinstalls, clearing crazy folders via command line, etc.

The only cons is that it requires you plug in the pen (which feels no different to me than a Wacom tablet), but you’re not fumbling with batteries. It’s just another simple USB cord that plugs directly into the battery.

Wacom has a patent on the most effective wireless/powerless pen technology, and is why they have a stronghold on the market and can control prices at will. Going third party means adopting a battery powered pen.. which until now I thought would be a huge bother. It’s not bad at all. The pen is the same size and light.

In general the whole thing is lighter / has slightly lower build quality, but that doesn’t matter to me. My Wacom’s get abused and especially the new, black PRO line gets ugly fast from use.

If you’re looking for a tablet, just get this thing. Buy the Wacom when you can afford it. It’s kind of like buying a nice car vs an economy car. They both do similar things, and both have justifications.

I like to buy top of the line for things I use for work. I will go back to a Wacom when mine is repaired, but this Huion is nothing short of impressive! Give it a shot and let me know what you think.

Here’s my referral link:
Huion H610 Pro Graphics Tablet

For the price, just buy it. I expect 0 support on this thing, or warranty. It’s 1/4 the price.

Django – basehttp.py UnicodeDecodeError at msg = “%s %s\n” % (self.log_date_time_string(), format % args)

This error is likely caused by accessing the django development server via https.

Django Admin Attribute Decorator

Due to the extremely repetitive nature of setting method attributes for django’s admin, I’ve thought of coming up with a better way to manage those for years.

Finally implemented a decorator that does such a thing gracefully:

def admin_method_attributes(**outer_kwargs):
    """ Wrap an admin method with passed arguments as attributes and values.
    DRY way of extremely common admin manipulation such as setting short_description, allow_tags, etc.
    """
    def method_decorator(func):
        for kw, arg in outer_kwargs.items():
            setattr(func, kw, arg)
        return func
    return method_decorator


# usage
class ModelAdmin(admin.ModelAdmin):
	@admin_method_attributes(short_description='Some Short Description', allow_tags=True)
	def my_admin_method(self, obj):
		return '''<em>obj.id</em>'''

Mailchimp API how to submit booean values via form post data

Mailchimp’s API can be a bit of a nightmare if some systems are relying on raw encoded form data, while the API often works best with JSON.

Merge vars in the following format are valid via form post: merge_vars[foo][0][bar] but very difficult to convert to a JSON payload on the server side if one needs to modify it slightly.

If you absolutely want to retain the form data and not convert to JSON, just know that you can send a boolean "false" via the existence of a post key with a blank value.

I’m not sure how it’s done for boolean "true".

AngularJS slideDown or slideUp on ng-if

First massive angular roadblock.

I needed to use an ng-if due to many directives needing initialization on demand (most directives assume DOM is visible for calculating offsets, sizes), but all solutions I’ve encountered online did not work with ng-if. They typically work with ng-show, but not ng-if.

The problem ended out to be simple: ng-if can be used with ng-animate using a custom JS animation which triggers enter and leave animations which provide you the element being animated at exactly the right moments.

Add the below to your project to understand all the animation hooks firing upon an ng-if element becoming visible.

<div ng-if=”isVisible” class=”my-crazy-animation”>
Ng-If Block
</div>

app.animation('.my-crazy-animation', function() {
return {
enter: function(element, done) {
//run the animation here and call done when the animation is complete
console.log(&quot;entering&quot;);
element.hide().slideDown();
return function(cancelled) {
//this (optional) function will be called when the animation
//completes or when the animation is cancelled (the cancelled
//flag will be set to true if cancelled).
};
},
leave: function(element, done) {
element.slideUp();
console.log(&quot;leaving&quot;);
}
};
});

Who knew it would be so easy. I’ve spent literally 4+ hours on this with multiple solutions. CSS based, JS based directives which don’t fire in correct priority for ng-if, all solved by this one liner. Incredible!

Shopify collection ordering

There is no way to order collections in Shopify without using a manually defined LinkList, which can’t be exported via API or saved in themes. It’s always admin configured.

An alternative is a method to hard code collection handles, then iterate through all collections, only pulling matching collections handles.

It may "feel" inefficient, but Shopify pages are massively cached, and a few for loops are the least of our problems. Unless we have impossibly more collections.

{% assign collection_handles = 'sport,casual,dress,bespoke' | split: &quot;,&quot; %}

{% for collection_handle in collection_handles %}
{% for collection in collections %}
{% if collection.handle == collection_handle %}
{{ collection.title }}

Serve Django HTTPS over localhost

The easiest way to do this is to use an app called django-sslserver.

It adds a new management command that serves content over SSL, and generates its own certificates.

I had tried things like stunnel… and ultimately this was the easiest solution.

I need it purely to test a Shopify app which must be served over HTTPS.

Follow

Get every new post delivered to your Inbox.

Join 116 other followers