Skip to content

Instantly share code, notes, and snippets.

View harlanhaskins's full-sized avatar
🦅
Swifting

Harlan Haskins harlanhaskins

🦅
Swifting
View GitHub Profile
static func systemLogs(count: Int = 30) -> [LogEntry] {
let q = asl_new(UInt32(ASL_TYPE_QUERY))
var logs = [LogEntry]()
let r = asl_search(nil, q)
var m = asl_next(r)
let keysNeeded = [ASL_KEY_MSG, ASL_KEY_TIME, ASL_KEY_LEVEL]
while logs.count < count && m != nil {
var logDict = [String: String]()
for key in keysNeeded {
if let val = String.fromCString(asl_get(m, key)) {
static func systemLogs() -> [[String: String]] {
let q = asl_new(UInt32(ASL_TYPE_QUERY))
var logs = [[String: String]]()
let r = asl_search(nil, q)
var m = asl_next(r)
while m != nil {
var logDict = [String: String]()
var i: UInt32 = 0
while true {
if let key = String.fromCString(asl_key(m, i)) {
\documentclass{article}
% Change "article" to "report" to get rid of page number on title page
\usepackage{amsmath,amsfonts,amsthm,amssymb}
\usepackage{setspace}
\usepackage{fancyhdr}
\usepackage{lastpage}
\usepackage{extramarks}
\usepackage{chngpage}
\usepackage{soul}
\usepackage[usenames,dvipsnames]{color}
@harlanhaskins
harlanhaskins / harlan.asm
Created October 21, 2015 20:21
harlan.asm - Prints "Harlan Haskins\n" to stdout.
global _main
bits 64
default rel
section .text
_main:
mov r8, array
add byte [r8], 8
loop_0:
cmp byte [r8], 0
je loop_0_end
@harlanhaskins
harlanhaskins / facts.c
Created October 27, 2015 04:12
C Factorials
#include <stdio.h>
char mem[30000];
char *p = mem;
int main() {
p += 1;
*p += 10;
p += 3;
*p += 1;
p += 1;
*p += 1;
harlan@nietzsche ~/D/C/S/grmustache-example> swift build
Cloning Packages/GRMustache.swift
Compiling Swift Module 'MustacheTVOSTests' (1 sources)
Compiling Swift Module 'DemoApps' (7 sources)
Compiling Swift Module 'Mustache' (32 sources)
Compiling Swift Module 'MustacheTests' (44 sources)
<unknown>:0: error: filename "AppDelegate.swift" used twice: '/Users/harlan/Documents/Code/Swift/grmustache-example/Packages/GRMustache.swift-0.12.0/DemoApps/MustacheDemoiOS/MustacheDemoiOS/AppDelegate.swift' and '/Users/harlan/Documents/Code/Swift/grmustache-example/Packages/GRMustache.swift-0.12.0/DemoApps/MustacheDemoiOS7/MustacheDemoiOS7/AppDelegate.swift'
<unknown>:0: note: filenames are used to distinguish private declarations with the same name
<unknown>:0: error: filename "ViewController.swift" used twice: '/Users/harlan/Documents/Code/Swift/grmustache-example/Packages/GRMustache.swift-0.12.0/DemoApps/MustacheDemoiOS/MustacheDemoiOS/ViewController.swift' and '/Users/harlan/Documents/Code/Swift/grmustache-example/Pac
fatal error: Test!: file fatalErrorTest/main.swift, line 3
Current stack trace:
0 libswiftCore.dylib 0x000000011af5910a reportBacktrace() + 42
1 libswiftCore.dylib 0x000000011af58d8d reportOnCrash(char const*) + 45
2 libswiftCore.dylib 0x000000011af58ece swift_reportFatalErrorInFile + 190
3 libswiftCore.dylib 0x000000011ab76cf0 Swift.(_assertionFailed (Swift.StaticString, Swift.String, Swift.StaticString, Swift.UInt) -> ()).(closure #1).(closure #1).(closure #1) + 336
4 libswiftCore.dylib 0x000000011af0fc17 partial apply forwarder for Swift.(_assertionFailed (Swift.StaticString, Swift.String, Swift.StaticString, Swift.UInt) -> ()).(closure #1).(closure #1).(closure #1) + 103
5 libswiftCore.dylib 0x000000011ab761b7 reabstraction thunk helper from @callee_owned (@unowned Swift.UnsafeBufferPointer<Swift.UInt8>) -> (@unowned ()) to @callee_owned (@unowned Swift.UnsafeBufferPointer<Swift.UInt8>) -> (@o
Current stack trace:
0 libswiftCore.dylib 0x000000011040010a reportBacktrace() + 42
1 libswiftCore.dylib 0x00000001103ffd8d reportOnCrash(char const*) + 45
2 libswiftCore.dylib 0x00000001103ffece swift_reportFatalErrorInFile + 190
3 libswiftCore.dylib 0x000000011001dcf0 Swift.(_assertionFailed (Swift.StaticString, Swift.String, Swift.StaticString, Swift.UInt) -> ()).(closure #1).(closure #1).(closure #1) + 336
4 libswiftCore.dylib 0x00000001103b6c17 partial apply forwarder for Swift.(_assertionFailed (Swift.StaticString, Swift.String, Swift.StaticString, Swift.UInt) -> ()).(closure #1).(closure #1).(closure #1) + 103
5 libswiftCore.dylib 0x000000011001d1b7 reabstraction thunk helper from @callee_owned (@unowned Swift.UnsafeBufferPointer<Swift.UInt8>) -> (@unowned ()) to @callee_owned (@unowned Swift.UnsafeBufferPointer<Swift.UInt8>) -> (@out ()) + 23
6 libswiftCore.dylib 0x00000
import CCairo
class Surface {
private let surface: COpaquePointer
private let cr: COpaquePointer
init(format: cairo_format_t, width: Int, height: Int) {
self.surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 240, 80)
self.cr = cairo_create(surface)
}
func writeToPNG(filename: String) {
import qualified Data.ByteString.Lazy.Char8 as L8
import Data.Digest.Pure.MD5 (md5)
md5List l = zip (map (md5 . L8.pack . ("yzbqklnj" ++) . show) l) l
main = print $ filter (\(x,_) -> "00000" == take 5 (show x)) (md5List [0..])