This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
import png | |
from husl import * | |
def mix(h1, h2, t): | |
return h1 * t + h2 * (1 - t) | |
def spiral(radius, degree, number): | |
n = 1.0 / number |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Execute a list of commands one by one | |
run_all = (commands) -> | |
return if commands.length is 0 | |
exec commands[0], (err, stdout, stderr) -> | |
console.log stdout + stderr | |
throw err if err | |
run_all commands.splice(1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window.App = Ember.Application.create() | |
App.Focusable = Ember.Mixin.create | |
# Don't let events spoil your Kool-Aid! | |
# Let's get these out of the way by turning them | |
# into a magical property: | |
focused: false | |
focusIn: (event) -> @set 'focused', true | |
focusOut: (event) -> @set 'focused', false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
hasher {}, (err, result) -> | |
# Save as hex strings | |
user.salt = result.salt.toString 'hex' | |
user.key = result.key.toString 'hex' | |
user.save -> | |
postmark.send | |
From: "you@example.com" | |
To: user.email | |
Subject: "Thank you for signing up with Example.com" | |
TextBody: "Your temporary password is #{result.plaintext}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Backbone.Collection.prototype.liveFilter = function(attributes) { | |
// Make a clone of the collection instantiated with all the filtered items | |
var _org = this; | |
var _new = new this.constructor(this.where(attributes)); | |
// What happens when you add to the original collection? | |
_org.on('add', function(model) { | |
// Unless one of the attributes doesn't match | |
for (key in attributes) { | |
if (model.get(key) !== attributes[key]) return; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# For a given Lightness, Hue, RGB channel, and limit (1 or 0), | |
# return Chroma, such that passing this chroma value will cause the | |
# given channel to pass the given limit. | |
maxChroma = (L, H) -> | |
hrad = H / 360 * 2 * Math.PI | |
sinH = Math.sin hrad | |
cosH = Math.cos hrad | |
sub1 = Math.pow(L + 16, 3) / 1560896 | |
sub2 = if sub1 > 0.008856 then sub1 else L / 903.3 | |
(channel) -> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CompanyResource(ModelResource): | |
class Meta: | |
resource_name = 'companies' | |
api_name = 'v1' | |
detail_uri_name = 'domain' | |
queryset = Company.objects.all() | |
def prepend_urls(self): | |
return [ | |
url(r"^(?P<resource_name>%s)/(?P<domain>[\w\d_.-]+)/$" % | |
self._meta.resource_name, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyResource(ModelResource): | |
# Workaround for this issue: | |
# https://github.com/toastdriven/django-tastypie/issues/518 | |
def hydrate(self, bundle): | |
for field_name, field_obj in self.fields.items(): | |
if field_name == 'resource_uri': | |
continue | |
if not field_obj.blank and not bundle.data.has_key(field_name): | |
raise ApiFieldError("The '%s' field has no data and doesn't allow a default or null value." % field_name) | |
return bundle |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.post '/api/verify', (req, res) -> | |
fail = -> | |
res.json status: 'failure' | |
if not req.body? | |
fail() | |
opts = { | |
host: "https://verifier.login.persona.org" | |
path: "/verify" | |
method: 'POST' | |
regectUnauthorized: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Asynchronous coding takes a bit of time to wrap your head around. | |
// I can't know for sure, but I think you misunderstand the general | |
// nature of a callback function. 'ajax.post' doesn't wait for the | |
// request to complete before returning, if it did so, there wouldn't | |
// be any need for a callback. **If you want something to happen AFTER | |
// the request completes, you have to put it in the callback function.** | |
// Don't think of a callback as some kind of icing on the cake, it is | |
// literally the continuation of your program's logic. |
OlderNewer