Skip to content

Instantly share code, notes, and snippets.

View narfdotpl's full-sized avatar

Maciej Konieczny aka narf narfdotpl

View GitHub Profile
@narfdotpl
narfdotpl / gist:5524302
Created May 6, 2013 10:05
good guy git
> g t
git: 't' is not a git command. See 'git --help'.

Did you mean one of these?
    tag
    a
    b
    c
    d

e

<?xml version="1.0"?>
<root>
<item>
<name>F19 → Backspace/Hyper</name>
<identifier>narfdotpl.hyper</identifier>
<autogen>
__KeyOverlaidModifier__
KeyCode::F19,
@narfdotpl
narfdotpl / gist:6568808
Created September 15, 2013 08:09
integer allocation in Python
$ python2.7
Python 2.7.2 (default, Oct 17 2011, 00:04:42)
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.1.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> result = None
>>> for n in range(1000):
... m = int(str(n))
... previous_result = result
... result = n is m
... if result != previous_result:
Python 2.7.2 (default, Oct 17 2011, 00:04:42)
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.1.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from dis import dis
>>> def short(xs):
... xs[0] += 1
...
>>> dis(short)
2 0 LOAD_FAST 0 (xs)
3 LOAD_CONST 1 (0)
@narfdotpl
narfdotpl / private
Created June 11, 2014 12:58 — forked from Ciechan/private
class Counter {
let inc: () -> Int
let dec: () -> Int
init(start: Int) {
var n = start
inc = { ++n }
dec = { --n }
}

Deckset feature request


println("\"Normal\" code.")

@narfdotpl
narfdotpl / gist:2a919667bc5f98a1c666
Created June 20, 2014 10:05
Swift: get substring
let email = "hello@narf.pl"
let domain = email[find(email, "@")!.succ()..email.endIndex] // WTF
println(domain)
def f(s):
return '%.3f' % (int(s, 16) / 255.0)
def rgb(s):
print '[UIColor colorWithRed:%s green:%s blue:%s alpha:1],' % \
tuple(f(s.lstrip('#')[i : i + 2]) for i in range(0, 6, 2))
rgb('ffffff') # [UIColor colorWithRed:1.000 green:1.000 blue:1.000 alpha:1],
rgb('ff0000') # [UIColor colorWithRed:1.000 green:0.000 blue:0.000 alpha:1],
@narfdotpl
narfdotpl / gist:78860a9ce5dbc3e19633
Created January 23, 2015 07:05
Swift job interview idea: implement Dictionary.map
@narfdotpl
narfdotpl / gist:3f52f720d3c9f311528a
Created February 9, 2015 19:52
if-let-with-multiple-optionals-is-lazy.swift
// Of course, `if let` with multiple optionals is lazy.
//
// Tested on 2015-02-09 in Xcode 6.3 Beta 1, Swift 1.2.
func foo() -> Int? {
println("foo")
return 0
}