This file contains hidden or 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
public class N { | |
N prev; | |
N(N a) { | |
this.prev = a; | |
} | |
N addOne(N a) { | |
return new N(a); | |
} |
This file contains hidden or 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
"open A_test.X if current file name is A.X | |
"open A.X if current file name is A_test.X | |
function OpenCorrespondingFile() | |
let d = split(expand("%"), '_test') | |
if len(d) == 1 | |
let name = expand("%:r") . "_test." . expand("%:e") | |
else | |
let name = d[0] . d[1] | |
endif | |
exec 'vsplit ' name |
This file contains hidden or 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
#!/usr/bin/env python2.5 | |
if __name__ == '__main__': | |
pass |
This file contains hidden or 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 X(object): | |
property = property(fget=lambda x: "property value") | |
direct_attribute = "direct_attribute" | |
def method(self): | |
return "method value: %s" % id(self) | |
@classmethod | |
def classmethod(self): | |
return "classmethod value: %s" % id(self) |
This file contains hidden or 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
x.__dict__ | |
{} | |
x.property | |
------------------------------------------------------------ | |
x.property property value | |
type(x).__dict__['property'] <property object at 0x800fc9a48> | |
type(x).__dict__['property'].__get__(x, type(x)) property value | |
x.direct_attribute |
This file contains hidden or 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
files=$(cat <<EOF | |
1st line | |
2nd line | |
3rd line | |
EOF | |
) | |
IFS=$'\n' | |
for f in $files | |
do |
This file contains hidden or 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
static boolean callMain(String className, String[] mainArgs) { | |
try { | |
Class cls = Class.forName(className); | |
Class[] parameterTypes = new Class[1]; | |
parameterTypes[0] = String[].class; | |
Method main = cls.getMethod("main", parameterTypes); | |
Object[] args = new Object[] { mainArgs }; | |
main.invoke(null, args); | |
} catch (Throwable e) { | |
System.err.println(e); |
This file contains hidden or 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
#!/usr/bin/env python2.6 | |
# -*- encoding: utf8 -*- | |
''' | |
An advanced version of Sleep Sort. | |
The original idea is from: http://coolshell.cn/articles/4883.html | |
Use the concept of radix sort to speed it up. | |
The newer version references WanCW's implementation in Ruby: |
This file contains hidden or 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
public boolean add(E e) { | |
typeCheck(e); | |
int eOrdinal = e.ordinal(); | |
int eWordNum = eOrdinal >>> 6; | |
long oldElements = elements[eWordNum]; | |
elements[eWordNum] |= (1L << eOrdinal); | |
boolean result = (elements[eWordNum] != oldElements); | |
if (result) |
This file contains hidden or 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
f = $("<div>a, b, c</div>"); // [<div>a, b, c</div>] | |
$.map(f.html().split(","), $.trim); // ["a", "b", "c"] |