Skip to content

Instantly share code, notes, and snippets.

import urllib2
# Add basic authentication handler to urllib2
mgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
mgr.add_password(None, 'example.com', 'username', 'password')
auth_handler = urllib2.HTTPBasicAuthHandler(mgr)
opener = urllib2.build_opener(auth_handler)
urllib2.install_opener(opener)
#import <Cocoa/Cocoa.h>
int main() {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSURLProtectionSpace *space = [[NSURLProtectionSpace alloc]
initWithHost:@"www.tumblr.com"
port:0
protocol:@"http"
realm:nil
@uasi
uasi / gist:214109
Last active September 11, 2015 03:06
Show branch name in Zsh's right prompt
#
# Show branch name in Zsh's right prompt
#
autoload -Uz VCS_INFO_get_data_git; VCS_INFO_get_data_git 2> /dev/null
setopt prompt_subst
function rprompt-git-current-branch {
local name st color gitdir action
grammar MyInteger {
token TOP {
| 0b(<[01]>+) {*} #= binary
| \d+ {*} #= decimal
}
}
class Twice {
multi method TOP($/, $tag) {
my $text = ~$/;
class A {
has ($.foo, $.bar, $.baz, $.qux, $.blahblahblah);
# Is there a way to define a constructor that takes positional arguments
# and initializes attributes of the same name
# (I assume the definition looks like this)
#
method NEW ($!foo, $!bar, $!baz, $!qux, $!blahblahblah) { }
# ... instead of repeating variables to bless?
use v6;
multi sub grep ($cond, @array, :@between where { .elems == 2 }) {
my $level = 0;
gather for @array {
$level-- if $level && $_ ~~ @between[1];
take $_ if $level && $_ ~~ $cond;
$level++ if $_ ~~ @between[0];
}
}
" A .vimrc snippet that allows you to move around windows beyond tabs
nnoremap <Tab> :call NextWindowOrTab()<CR>:echo<CR>
nnoremap <S-Tab> :call PreviousWindowOrTab()<CR>:echo<CR>
function! NextWindowOrTab()
if winnr() < winnr("$")
execute "normal \<C-W>\<C-W>"
else
tabnext
@uasi
uasi / gist:376530
Created April 23, 2010 13:25 — forked from tyru/gist:376501
もしあなたが新しいプログラム、例えばテキストエディタを作るとしたら、どの言語で作る?
Suppose you want to write a new program, something like a text editor. What language would you write it in?
* できるだけ速く。なのでインタプリタ言語はダメ。
* It has to be as fast as possible, so interpreted languages are out.
* メモリ管理なんてしたくない。だからCはダメ。
* You don't want to micro manage memory, so C is out.
* プログラマに知識((FIXME))を求めたくない。だからC++はダメ。
* You don't want to require programmers to have a degree, so C++ is out.
* できるだけ起動を速く、ランタイムには依存させたくない。だからJavaはダメ。
@uasi
uasi / fastpack.sh
Created April 30, 2010 19:42
fastpack - a simple App::FatPacker helper
#!/bin/sh
#
# fastpack - a simple App::FatPacker helper
#
if [ -z "$1" ]; then
echo "usage: fastpack script.pl > script.packed.pl"
exit 0
fi
use v6;
use MONKEY_TYPING;
class C {}
role R {
method perl() { 'perl' }
method foo() { 'foo' }
}