Skip to content

Instantly share code, notes, and snippets.

View wjlafrance's full-sized avatar
🐶
Wondering if Github is becoming a social network.

William LaFrance wjlafrance

🐶
Wondering if Github is becoming a social network.
View GitHub Profile
@wjlafrance
wjlafrance / ttyUSB0.conf
Created June 16, 2014 15:14
/etc/init/ttyUSB0.conf
## ttyUSB0 - getty
##
## This service maintains a getty on ttyUSB0 from the point the system is
## started until it is shut down again.
start on stopped rc or RUNLEVEL=[12345]
stop on runlevel [!12345]
respawn
exec /sbin/getty ttyUSB0 115200
func max1(numbers: [Int]) -> Int {
var maximumSoFar: Int = 0
for i in numbers {
maximumSoFar = max(maximumSoFar, i)
}
return maximumSoFar
}
Compiled with -Ofast -emit-assembly:
@wjlafrance
wjlafrance / Sign.java
Last active August 29, 2015 14:05
CSR Racing hack
/**
Using iExplorer, navigate to CSR Racing and extract the file from
/Library/Caches/pp.
$ mv user85500672{,.gz}
$ gunzip user85500672.gz
$ edit user85500672
Remove the signature (first line). Edit "caea", "casp", "goea", and "gosp"
to modify your cash earned, cash spent, gold earned, and gold spent
@wjlafrance
wjlafrance / gist:2ed930fc69e089d3a1b2
Created October 22, 2014 22:46
Generic where type is constrained by class and protocol
protocol MyProtocol {
func methodFromProtocol()
}
class MyClass {
func methodFromClass() {
println("hello class")
}
}
// http://stackoverflow.com/questions/26868663/switch-statement-in-objective-c
#include <stdio.h>
int main() {
int myVar = 2;
switch (myVar) {
case 1: {
printf("one\n");
typedef NS_OPTIONS(NSUInteger, LSRBorderSide) {
LSRBorderSideNone = 1 << 0,
LSRBorderSideLeft = 1 << 1,
LSRBorderSideRight = 1 << 2,
LSRBorderSideBottom = 1 << 3,
LSRBorderSideTop = 1 << 4
};
class IncrementorSequence : SequenceType {
func generate() -> GeneratorOf<Int> {
var value = 0
return GeneratorOf<Int> {
return value++
}
}
}
// This playground was built for Xcode 6.2 and is compatible with Xcode 6.3b3.
// The contents are true to the best of my knowledge and are not an April Fools joke.
// However, if you -actually- implement some of this stuff...
// In Swift, Void is a typealias for an empty tuple
// Cmd-Click the keyword Void to see this typealias
func example1() {
let myVoid: Void = ()
println("\(myVoid)")
}
@wjlafrance
wjlafrance / InitArgsConvention.playground.swift
Created April 2, 2015 15:33
Init argument naming conventions
// Which convention for init args do you prefer?
// Naming the arguments the same as the fields requires explicitly naming self
class MyFirstClass {
var i: Int
var s: String
init(i: Int, s: String) {
self.i = i
self.s = s
@wjlafrance
wjlafrance / bitpacking.c
Last active August 29, 2015 14:18
abusing the crap out of union
#include <stdio.h>
#include <stdint.h>
union BitAccessor {
uint64_t u64;
struct {
uint32_t _0, _1;
} u32;
struct {
uint16_t _0, _1, _2, _3;