This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
grammar MyInteger { | |
token TOP { | |
| 0b(<[01]>+) {*} #= binary | |
| \d+ {*} #= decimal | |
} | |
} | |
class Twice { | |
multi method TOP($/, $tag) { | |
my $text = ~$/; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
もしあなたが新しいプログラム、例えばテキストエディタを作るとしたら、どの言語で作る? | |
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はダメ。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# | |
# fastpack - a simple App::FatPacker helper | |
# | |
if [ -z "$1" ]; then | |
echo "usage: fastpack script.pl > script.packed.pl" | |
exit 0 | |
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use v6; | |
use MONKEY_TYPING; | |
class C {} | |
role R { | |
method perl() { 'perl' } | |
method foo() { 'foo' } | |
} |
OlderNewer