Skip to content

Instantly share code, notes, and snippets.

View houshuang's full-sized avatar

Stian Håklev houshuang

View GitHub Profile
replacelist <- list(
list(c("18-25 years"), "18-25"),
list(c("26-35","26-35 years", "26-45 years", "36-45", "36-45 years"), "26-45"),
list(c("46-65 years", "46-55", "56-65", "56-65 years"), "46-65"),
list(c("66 years or older","66-75", "66-75 years", "76 and over", "76-85", "76-85 years", "86 years or older"), "66 or older"))
for(e in replacelist) {
for(f in e[[1]]) {
db$age <- replacefact(db$age, f, e[[2]])}}
ggplot(db[db$gender %in% c("Male", "Female"), ],
aes(x=course, fill=gender, stat="identity")) +
geom_bar(position="fill", width = .5) +
geom_bar(data=db,mapping=aes(x="All Courses",fill=gender)) +
labs(title="Gender distribution") +
coord_flip() +
scale_x_discrete(labels = course.titles) +
scale_y_continuous(labels = percent)
2013-09-28 18:02:20.051 [NotebookApp] KernelRestarter: restarting kernel (1/5)
ERROR: Pkg2 not defined
in include at boot.jl:238
in include_from_node1 at loading.jl:96
in reload_path at loading.jl:121
in require at loading.jl:50
in include at boot.jl:238
in include_from_node1 at loading.jl:96
in include at boot.jl:238
@houshuang
houshuang / gist:6748566
Created September 29, 2013 01:45
Automatically open function in Sublime Text (first Julia macro)
macro whichs(ex)
ex = expand(ex)
exret = Expr(:call, :error, "expression is not a function call")
if !isa(ex, Expr)
# do nothing -> error
elseif ex.head == :call
exret = Expr(:call, :whichs, map(esc, ex.args)...)
elseif ex.head == :body
a1 = ex.args[1]
if isa(a1, Expr) && a1.head == :call
@houshuang
houshuang / gist:6799251
Created October 2, 2013 19:29
Various plot likert functions for use with HH's likert
PlotLikert <- function(var1, var2, ...) {
likert(data.frame
(t
(unclass
(prop.table
(table(var1, var2),2)))), ...)
}
reshape.likert <- function(x, factors=c("Strongly Disagree", "Disagree", "Neutral", "Agree", "Strongly Agree"), columns="ALL") {
row.names(x) <- NULL
@houshuang
houshuang / gist:7034026
Created October 17, 2013 23:19
utility function for R to make it easier to add to a hash value without checking whether it exists first
class Object
def add_safe(var,val)
if val.class == Fixnum
if self[var].nil?
self[var] = val
else
self[var] = self[var] + val
end
else
@houshuang
houshuang / gist:7034117
Created October 17, 2013 23:28
Output from Ruby Russian stats on Серёжа by Вера Панова
Total words: 26463
Total stems: 4719
Stems occurring more than 10 times: 391
Stems occuring more than 10 times represent 67.0% of the text
Top stems:
и 1292
он 842
не 645
--
-- Sudoku solver using constraint propagation. The algorithm is by
-- Peter Norvig http://norvig.com/sudoku.html; the Haskell
-- implementation is by Manu and Daniel Fischer, and can be found on
-- the Haskell Wiki http://www.haskell.org/haskellwiki/Sudoku
--
-- The Haskell wiki license applies to this code:
--
-- Permission is hereby granted, free of charge, to any person obtaining
-- this work (the "Work"), to deal in the Work without restriction,
(.py3) ~|⇒ cat ~/.ihaskell/ipython/bin/ipython
#!/Users/Stian/.py3/bin/python
# This script was automatically generated by setup.py
if __name__ == '__main__':
from IPython import start_ipython
start_ipython()
Debugger entered--Lisp error: (error "el-get: make el-get could not build jedi [make requirements]")
signal(error ("el-get: make el-get could not build jedi [make requirements]"))
error("el-get: %s %s" "make" "el-get could not build jedi [make requirements]")
byte-code("\203\261@A\306 \307\"\306 \310\"\306 \311\"\312
!\205\"\313
!@\306 \314\"A\306 \315\"B\306 \316\"\211C\203D\317\320\306 \321\"\"\202H\306 \321\"D\322 \323E#F\306 \324\"G \203d\325\326 !!\202fHHF\203;\327\330\"\210C\203{\331\202|\332IG\205\206\333\334!\211J\205\263J\335\336\337!!KL\340\216rKq\210\341G!c)rKq\210\342\343\211L\343\344%\210,M\345\346\f\"M\347IBJ
\350D&N\306 \351\"%\306 \352\"OP\203\346\345\353r
q\210\354 )\"\210N\344=\203\366\345\355%\"\210\202\356\357
\"\210\360\361\fO#\210J\203
\362J!\210