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
watch -n 0.1 "ps aux | awk 'NR>1{print \$2 \"\t\" \$3 \"\t\" \$10 \"\t\" \$11}' | sort -nrk 2" |
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
x = set(['a', 'b']) | |
y = {} | |
y.update({r:'' for r in x if r is not ''}) |
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
f_K_fold <- function(Nobs,K=5){ | |
rs <- runif(Nobs) | |
id <- seq(Nobs)[order(rs)] | |
k <- as.integer(Nobs*seq(1,K-1)/K) | |
k <- matrix(c(0,rep(k,each=2),Nobs),ncol=2,byrow=TRUE) | |
k[,1] <- k[,1]+1 | |
l <- lapply(seq.int(K),function(x,k,d) | |
list(train=d[!(seq(d) %in% seq(k[x,1],k[x,2]))], | |
test=d[seq(k[x,1],k[x,2])]),k=k,d=id) | |
return(l) |
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
reduce(operator.add,map(lambda x: math.sqrt(x**3), range(4+1))) | |
# http://ua.pycon.org/static/talks/kachayev/#/11 |
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
mylist = c('www.google.com','www.google.comascascasdasdnasmdamsd') | |
isgoodURL <- function(url){if(system(paste('curl -o /dev/null --silent --head --fail ', url)) == 0) return(TRUE) else return(FALSE)} | |
Filter(isgoodURL,mylist) |
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
add <- function(x,y)(return(x+y)) | |
Reduce(add,c(1,2,3,4,5)) |
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
>>> from __future__ import print_function | |
>>> class People: pass | |
>>> | |
>>> Fred = People() | |
>>> Fred.has_pants = True | |
# Now I'd like to create a method that says "I have pants" if Fred has pants. I make the function: | |
>>> f = lambda self: print("I have pants") if self.has_pants else None |
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
def getByDot(obj, ref): | |
""" | |
Use MongoDB style 'something.by.dot' syntax to retrieve objects from Python dicts. | |
This also accepts nested arrays, and accommodates the '.XX' syntax that variety.js | |
produces. | |
Usage: | |
>>> x = {"top": {"middle" : {"nested": "value"}}} | |
>>> q = 'top.middle.nested' |
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 Superclass(object): | |
def __init__(self): | |
print 'Do something' | |
class Subclass(Superclass): | |
def __init__(self): | |
super(Subclass, self).__init__() | |
print 'Do something else' |
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
def ensure(name, validate, doc=None): | |
def decorator(Class): | |
privateName = "__" + name | |
def getter(self): | |
return getattr(self, privateName) | |
def setter(self, value): | |
validate(name, value) | |
setattr(self, privateName, value) | |
setattr(Class, name, property(getter, setter, doc=doc)) | |
return Class |
OlderNewer