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
#!/usr/bin/env python | |
import sys | |
import locale | |
locale.setlocale(locale.LC_ALL, 'en_US') | |
def is_prime_brute(n): | |
for x in range(2, n / 2 + 1): | |
if n % x == 0: | |
return False |
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
library(rjson) | |
graph <- fromJSON(paste(readLines("friends.json"), collapse="")) | |
gender <- as.factor( | |
sapply(graph$data, function(f) { | |
ifelse(is.null(f$gender), "na", f$gender) | |
}) | |
) |
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
#!/usr/bin/env python | |
def invalid(msg): | |
print msg | |
exit() | |
def getFloat(prompt): | |
print prompt + ":", | |
input = raw_input() | |
if len(input) > 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
h1 = {a: 1, b: 2} | |
h2 = h1.keep_if{|k,v| k == :a} | |
p h1.inspect # => {a: 1} | |
p h2.inspect # => {a: 1} |
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
require 'rubygems' | |
require 'statemachine' | |
class MowerContext | |
def cut_mode | |
puts "blade start spinning" | |
end | |
def idle_mode | |
puts "engine idling" |
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
chooseCRANmirror() | |
install.packages("Rcmdr", dependencies = TRUE) | |
library("Rcmdr") |
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
help(topic) # help on a topic | |
help.start() # browser-based help tool | |
source("someRFile.R") # load a file | |
a = 1 + 3 | |
rm(a) # remove the variable a | |
odd_digits <- c(1,3,5,7,9) | |
total = sum(odd_digits) |
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
#!/usr/bin/env bash | |
apply () { | |
for node in '' 2 3 | |
do | |
launchctl $1 ~/Library/LaunchAgents/homebrew.mxcl.elasticsearch${node}.plist | |
done | |
} | |
status () { |
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
<?xml version="1.0" encoding="UTF-8"?> | |
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | |
<plist version="1.0"> | |
<dict> | |
<key>Label</key> | |
<string>homebrew.mxcl.elasticsearch2</string> | |
<key>ProgramArguments</key> | |
<array> | |
<string>/usr/local/bin/elasticsearch</string> | |
<string>--config=/usr/local/opt/elasticsearch/config/elasticsearch.yml</string> |
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
elements <- c('the','story','was','the','point','of','the', | |
'story', 'a', 'quick','brown','fox','the','a', | |
'jumped','fence','over') | |
words <- sample(elements, 20000, replace = TRUE) | |
count <- function(word) { | |
sum(words == word) | |
} | |
# unique |
OlderNewer