Skip to content

Instantly share code, notes, and snippets.

View alexbosworth's full-sized avatar

Alex Bosworth alexbosworth

View GitHub Profile
@alexbosworth
alexbosworth / KeychainService.swift
Last active January 5, 2021 08:26
Swift Keychain Class
import UIKit
import Security
let serviceIdentifier = "com.company"
let accessGroup = "com.company.app"
let kSecClassValue = kSecClass as NSString
let kSecAttrAccountValue = kSecAttrAccount as NSString
let kSecValueDataValue = kSecValueData as NSString
let kSecClassGenericPasswordValue = kSecClassGenericPassword as NSString
@alexbosworth
alexbosworth / gist:5529907
Created May 7, 2013 02:41
Mixpanel auth signature generation
var params = _.extend({
api_key: MIXPANEL_KEY,
expire: Math.ceil(Date.now() / 1000) + 5 * 60
},
args.params);
var toSign = Object.keys(params)
.sort()
.map(function(key) { return key + '=' + params[key]; })
.join('');
var request = require('request'),
ENDPOINT = 'https://www.googleapis.com/';
exports.save = function(opt, cbk) {
var auth = 'Bearer ' + opt.access_token;
opt.mimeType = opt.mimeType || 'application/octet-stream';
request.post({
@alexbosworth
alexbosworth / responder.js
Created September 9, 2011 01:21
Micro Express.js
exports.respond = function(req, res) {
var responders = [];
for (var i = 2, arg; arg = arguments[i]; i++) responders.push(arguments[i]);
var next = function() {
var responder = responders.shift();
if (typeof(responder) != 'function') return;
@alexbosworth
alexbosworth / deferred.js
Created August 30, 2011 02:09
Deferred for Node.js
// Deferreds are useful for chaining: doSomething().success(doSomethingElse).failure(stopStuff);
function Deferred() {
this._successCbk = function() {},
this._failureCbk = function() {};
return this;
}
Deferred.prototype.success = function(cbk) {
this._successCbk = cbk;
@alexbosworth
alexbosworth / gist:1153365
Created August 18, 2011 05:41
node jquery with some added flavor bits
function now() {
return (new Date).getTime();
}
var window = {},
jsc = now(),
rscript = /<script(.|\s)*?\/script>/gi,
rselectTextarea = /select|textarea/i,
rinput = /color|date|datetime|email|hidden|month|number|password|range|search|tel|text|time|url|week/i,
jsre = /=\?(&|$)/,
Sdb.prototype.getQueryString = function(query) {
if (!query.domain) throw new Error('no domain specified');
if (!query.fields || !query.fields.length) query.fields = '*';
var str = query.fields.join() + ' from ' + query.domain;
if (query.selectors && query.selectors.length)
str+= ' where ' + query.selectors.join(' intersection ');
@alexbosworth
alexbosworth / node.page.structure.js
Created December 16, 2010 01:05
an example of doing page classes in node.js
function echo(string) { console.log(string); }
process.on('uncaughtException', function (err) {
echo(err.stack);
echo('uncaught Exception: ' + err);
});
var KEYS = require('keychain'),
$ = require('node-jquery'),
S3 = require('amazon-s3').S3;
@alexbosworth
alexbosworth / Asynchronous Patterns
Created October 25, 2010 15:23
Asynchronous Patterns For Node.JS
** Steps **
Problem:
Map asynchronous callbacks onto a multi-step process.
Centralize flow logic
object {
steps : [function, function, function]
advance : function() { this.shift(function)(); }
}
@alexbosworth
alexbosworth / parseGetArgs.js
Created October 20, 2010 07:34
in progress GET object parser
// SCRIPT IN PROGRESS! BEWARE SUPER HACKY/UGLY CODE BELOW
// takes an associative array of args "a[b][c]" = d into a : { b : { c : d } }
// use: var getArgs = parseGetArgs(url.parse(request.url, true).query);
function parseGetArgs(args) {
if (!args) return null;
var result = {};