Skip to content

Instantly share code, notes, and snippets.

@jiaaro
jiaaro / script.bash
Created April 24, 2013 14:45
Embed Python in a bash script
#!/bin/bash
export FOO=100
python - <<END
import os
print "foo:", os.environ['FOO']
END
@jiaaro
jiaaro / simpleTarget.js
Last active December 16, 2015 06:39
Partially de-obfuscated simpleTarget() from nodewar.com
// nodewar.com library function…
// o.lib.targeting.simpleTarget(ship, pos)
//
// mostly deobfuscated/deminified
//
function simpleTarget(ship, pos) {
var i, r, h,
torque = 0,
thrust = 0,
dir = o.lib.targeting.dir(ship, pos);
@spookylukey
spookylukey / gist:fc9fa268de67fd19a567
Last active August 29, 2015 14:22
How to post code snippets (especially Python) into comment systems that don't preserve whitespace
#!/usr/bin/env python
# How to post code snippets (especially Python) into comment systems
# that don't preserve whitespace.
# Save this as a script called 'convert_leading_spaces_to_nonbreaking'
# in your PATH and do "chmod +x" on it.
#
# In Linux, you can then use it by installing xsel and doing:
#
@natecook1000
natecook1000 / randomInt.swift
Created October 9, 2014 16:43
Random integers without shuttling between UInt32 and Int
func arc4random_uniform<T: SignedIntegerType>(max: T) -> T {
let max32: Int32 = numericCast(max)
return T(Int64(arc4random_uniform(UInt32(max32))))
}
func arc4random_uniform<T: UnsignedIntegerType>(max: T) -> T {
let max32: UInt32 = numericCast(max)
return T(UInt64(arc4random_uniform(max32)))
}
@RoyalIcing
RoyalIcing / example.playground
Created July 13, 2014 09:03
Using enum for getting/setting value and modification date – Inessential · Swift Structs and valueForKey:
import Swift
import Cocoa
// Properties you need as an enum - problem of key value coding is it allows you to type *anything*, typos compile fine.
enum SyncObjectPropertyName {
case Archived
case Title
}
// Protocol shared both for local and server