Skip to content

Instantly share code, notes, and snippets.

View borismus's full-sized avatar

Boris Smus borismus

View GitHub Profile
@borismus
borismus / gist:1032746
Created June 18, 2011 02:46
Convert a base64 string into a binary Uint8 Array
var BASE64_MARKER = ';base64,';
function convertDataURIToBinary(dataURI) {
var base64Index = dataURI.indexOf(BASE64_MARKER) + BASE64_MARKER.length;
var base64 = dataURI.substring(base64Index);
var raw = window.atob(base64);
var rawLength = raw.length;
var array = new Uint8Array(new ArrayBuffer(rawLength));
for(i = 0; i < rawLength; i++) {
@borismus
borismus / gist:1045685
Created June 24, 2011 21:00
JSHint Errors
function(config) {
// JSHint error on next line: "Line breaking error 'return'. Following line: "Bad escapement."
return 'https://accounts.google.com/o/oauth2/auth?\
client_id={{CLIENT_ID}}&\
redirect_uri={{REDIRECT_URI}}&\
scope={{API_SCOPE}}&\
response_type=code'
.replace('{{CLIENT_ID}}', config.clientId)
.replace('{{REDIRECT_URI}}', this.redirectURL(config))
.replace('{{API_SCOPE}}', config.apiScope);
@borismus
borismus / gist:1123866
Created August 3, 2011 21:45
shared client/server javascript for node.js
load in node:
require('../common/module.js');
load in browser:
<script src="../common/module.js"></script>
module.js:
(function(exports) {
var MyClass = function() { /* ... */ };
@borismus
borismus / argify
Created August 5, 2011 20:09
Pass arguments to any OS X launcher
#!/usr/bin/env bash
# Example usage:
# ./argify '/Applications/Google Chrome Stable.app/Contents/MacOS/Google Chrome' \
# '--user-data-dir=$HOME/.chrome-stable'
if [ $# -ne 2 ]
then
echo "Usage: `basename $0` '/Applications/Google Chrome Stable.app/Contents/MacOS/Google Chrome' '--argument=value'"
exit 1
fi
@borismus
borismus / gist:1224416
Created September 17, 2011 22:01
Autobahn KeySocket
from twisted.internet import reactor
from autobahn.websocket import WebSocketServerFactory, WebSocketServerProtocol
from threading import Thread
class KeySocketProtocol(WebSocketServerProtocol):
def __init__(self, factory):
self.factory = factory
def onOpen(self):
self.factory.clients.append(self)
#!/usr/bin/env python
import boto
AWS_ACCESS_KEY_ID = 'foo'
AWS_SECRET_ACCESS_KEY = 'bar'
bucket_name = 'baz'
conn = boto.connect_s3(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY)
bucket = conn.create_bucket(bucket_name,
p {
font-size: 110%;
}
positionView: function() {
console.log('positioning');
// TODO: Fix this nonsense.
// Check for the existence of this.element because when the transition
// value initially changes, the element doesn't actually exist!
if (this.get('element')) {
this.get('element').style.webkitTransform =
'translate(0, ' + this.get('transition') + 'px)';
}
@borismus
borismus / gist:1990752
Created March 7, 2012 03:35
Ember project setup
/static/sass/:
screen.scss: (common stylesheet)
phone.scss, tablet.scss, desktop.scss: (form factor-specific styles)
/static/js/:
libs/: (external libraries - DO NOT MODIFY)
ember-and-friends.js
jquery.js
formfactor.js
views/: (form-factor specific views)
@borismus
borismus / gist:2165681
Created March 23, 2012 00:06
dynamic template loading
/*
* Loads a handlebars.js template at a given URL. Takes an optional name, in which case,
* the template is added and is reference-able via templateName.
*/
function loadTemplate(url, name, callback) {
var contents = $.get(url, function(templateText) {
var compiledTemplate = Ember.Handlebars.compile(templateText);
if (name) {
Ember.TEMPLATES[name] = compiledTemplate
} else {