Skip to content

Instantly share code, notes, and snippets.

View alexbosworth's full-sized avatar

Alex Bosworth alexbosworth

View GitHub Profile
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({
func localizedStringForNumber(number: Int) -> String {
let numberFormatter = NSNumberFormatter()
numberFormatter.locale = NSLocale.currentLocale()
numberFormatter.numberStyle = .NoStyle
return numberFormatter.stringFromNumber(number) ?? String(number)
}
import UIKit
/** Helper methods for CGAffineTransform
*/
extension CGAffineTransform {
/** Make a vertical flip transformation
*/
static func flipVertical() -> CGAffineTransform {
return CGAffineTransformMakeScale(1, -1)
}
import UIKit
/** Alert controller that can be presented in any context and it will appear on top
*/
class GlobalAlertController: UIAlertController {
// MARK: - Properties (Private Mutable)
/** Window to present alert controller in
*/
private lazy var _window: UIWindow = {
@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('');
@alexbosworth
alexbosworth / grayscale_uicolor.swift
Created September 8, 2015 04:01
convert a ui color to grayscale
var (hue, saturation, brightness, alpha) = (CGFloat(0.0), CGFloat(0.0), CGFloat(0.0), CGFloat(0.0))
let originalColor = UIColor.redColor()
if originalColor.getHue(&hue, saturation: &saturation, brightness: &brightness, alpha: &alpha) {
let grayscale = UIColor(hue: hue, saturation: 0, brightness: brightness, alpha: alpha)
}
//: Bitcoin Script Interpreter
import Foundation
/** Script Operation
*/
enum Operation {
case checkMultisig
case checkSig
case dup
package main
import (
"fmt"
"math"
)
func Sqrt(x float64) float64 {
guess := 1.0
package main
import (
"golang.org/x/tour/pic"
)
func Pic(dx, dy int) [][]uint8 {
// Create pixels
pixels := make([][]uint8, dy)
package main
import (
"golang.org/x/tour/wc"
"strings"
)
func WordCount(s string) map[string]int {
countForWord := make(map[string]int)