Skip to content

Instantly share code, notes, and snippets.

extension NSData {
var SHA1: NSData {
var digest = [UInt8](count: Int(CC_SHA1_DIGEST_LENGTH), repeatedValue: UInt8(0))
CC_SHA1(bytes, CC_LONG(length), &digest)
return NSData(bytes: digest, length: Int(CC_SHA1_DIGEST_LENGTH))
}
var hex: String {
var hexString = ""
let hexTable = "0123456789abcdef"
let bytes = UnsafePointer<UInt8>(self.bytes)
@qwzybug
qwzybug / janet.md
Created January 4, 2015 09:11
By episode 3, Janet and Larry's relationship remains obscure.

STEVE is a skink. JANET is a sparrow. LARRY is a beaver.


STEVE and JANET enter, continuing a conversation. LARRY is eating a sandwich.

Steve: Oh, that's Larry. Don't mind him, he's a child pornography enthusiast.

Larry (correcting him): Pedophile.

@qwzybug
qwzybug / dev_random.swift
Last active August 29, 2015 14:13
noodling with devices & generators in swift
#!/usr/bin/env swift
import Foundation
class Dev {
let desc: Int32
var data = NSMutableData(length: 1)!
init(_ name: String) {
desc = Darwin.open("/dev/\(name)", O_RDONLY)
}
@qwzybug
qwzybug / hasklike.swift
Created February 10, 2015 20:44
countdown to haskell-style commas in 3... 2... 1...
for userDict in userList {
if let
id = userDict["id"] as? Int
, name = userDict["name"] as? String
, email = userDict["email"] as? String
, address = userDict["address"] as? [String: AnyObject]
{
users.append(User(id: id, name: name, ...))
}
}

It wasn't a voice but more like something you just knew, all of a sudden, like a new sense.

Your urine flow is down 4 percent year over year. This is a common early sympton of enlarged prostate and prostate cancer. Your estimated time to further symptons is 3.2 years.

He sighed, angry at himself, like someone twenty years before might have sighed at an unpaid parking ticket come back for collections. Not that long ago it felt like 3.5, even 4 years. Anyway it wasn't hurting yet, though he supposed it probably would soon; these feelings were rarely wrong, if you gave them enough information. Anyway he didn't have enough spare cash at the moment to upgrade his medical plan to an interactive one. He fucking should though, he told himself, he was almost 30 and should be more responsible by now. Or was that just another one of those other feels, maybe a sponsored one? He thought a moment. No, this was nonspecific, a real feeling.

He finished pissing, washed and dried his hands.

He had friends who could affor

// Cons lists are kind of like linked lists
enum List<T> {
case Empty
indirect case Cons(T, List<T>) // doesn't compile yet. will soon.
mutating func add(item: T) {
switch self {
case .Empty:
self = .Cons(item, .Empty)
JIM and his GIRLFRIEND are getting
ready for THE BIG GAME. JIM is wearing
a BLUE AND WHITE JERSEY with the
FACEBOOK LOGO and the name ZUCKERBERG
across the back.
The front door opens. SAM enters,
carrying BREWSKIS.
SAM
class QuestionsController < RestfulController
model Question
end
@qwzybug
qwzybug / after.rb
Created February 25, 2009 23:30
Refactoring a Shoes widget. Needs midiator gem.
class Piano < Widget
def initialize opts = {}, &action
opts = {:width => 700, :height => 100}.merge opts
@action = action
key_width = opts[:width] / 52.0
ivory = {:bottom => 0, :width => key_width.round, :height => opts[:height] * 2 / 5}
ebony = {:top => 0, :width => (key_width * 2 / 3).round, :height => opts[:height] * 3 / 5}
last_x = -key_width
Plank = {}
Plank.new = function(world, x, y, w, h, offset)
body = love.physics.newBody(world, 0, 0, 0)
body:setAngularDamping(1000)
shape = love.physics.newRectangleShape(body, x, y, w, h)
body:setMassFromShapes()
return {
shape = shape, body = body, offset = offset,
force =
function(self, t)