Skip to content

Instantly share code, notes, and snippets.

@dfeng
dfeng / p458.py
Last active August 29, 2015 13:56
458
from numpy import *
# The Matrix!
x = matrix([
[1,6,0,0,0,0],
[1,1,5,0,0,0],
[1,1,1,4,0,0],
[1,1,1,1,3,0],
[1,1,1,1,1,2],
[1,1,1,1,1,1],
@dfeng
dfeng / Amazing.R
Created October 14, 2014 17:31
Amazing'r
# Source: http://stackoverflow.com/questions/11671731/in-r-how-can-i-make-a-running-count-of-runs
x <- data.frame(end.group=c(0,0,1,0,0,1,1,0,0,0,1,1,1,0,1))
# create groups
x$group <- rev(cumsum(rev(x$end.group)))
# re-number groups from smallest to largest
x$group <- abs(x$group-max(x$group)-1)
x$group.count <- ave(x$end.group, x$group, FUN=seq_along)
# Even Better: http://stackoverflow.com/questions/9961700/how-to-partition-when-ranking-on-a-particular-column
@dfeng
dfeng / marriage.txt
Created October 20, 2014 18:27
Marriage Limerickroll
marriage is a long-term contract
and if u put it in nominal terms
by eating recklessly,
he is shortening the benefits of this contract
@dfeng
dfeng / Lint.py
Created January 8, 2015 17:31
List Integer
from collections import defaultdict
class Lint(defaultdict):
def __init__(self, item):
super(Lint, self).__init__(int)
if isinstance(item, int) or isinstance(item, long):
st = str(item)[::-1]
d = {i: int(st[i]) for i in xrange(len(st))}
elif isinstance(item, dict):
d = item
else:
@dfeng
dfeng / grade.R
Created May 9, 2015 04:46
roster + grades -> ug + gs
# Start R Grading Helper
# ==========================
# === Global Variables ===
# ==========================
folder <- "/Users/dfeng/Downloads/Grading"
roster_filename <- "ml_roster.csv"
grade_filename <- "ml_hw.csv"
\documentclass{article}
\usepackage[pdftex,active,tightpage]{preview}
\setlength\PreviewBorder{2mm}
\usepackage{tikz}
\usetikzlibrary{positioning, calc}
% \usepackage[minionint, loosequotes, swash]{MinionPro}
% \usepackage{lmodern}
\renewcommand{\familydefault}{\sfdefault}
\begin{document}
@dfeng
dfeng / carbon.css
Last active June 21, 2019 18:11
Reddit Carbon
@namespace url(http://www.w3.org/1999/xhtml);
@-moz-document domain('reddit.com') {
body{
background:#1a1a1a;
color:#ddd
}
.comment .usertext .md p>a:visited,.md a,.res.res-nightmode .tagline a,a,h2 a:visited{
color:#3498db;
@dfeng
dfeng / gists.zsh
Created June 9, 2015 19:19
Gist to RawGist
function gists() {
/usr/local/bin/gist $1 | sed s/gist.github/rawgit/ | sed s/.com/.com\\\/dfeng/ | sed -e "s/$/\\/raw\/$1/"
}
@dfeng
dfeng / hidden_bar.css
Created June 18, 2015 13:33
Hidden Reader Bar
@namespace url(http://www.w3.org/1999/xhtml);
@-moz-document url-prefix("about:reader");
#reader-toolbar,#reader-toolbar .button:not(:hover) {
background-color:transparent !important;
border:none!important;
}
#reader-toolbar:not(:hover)>*:not([open]){
visibility:hidden;
}
@dfeng
dfeng / userChrome.css
Created June 18, 2015 13:35
Custom Chrome for TreeStyle Tabs
#main-window .tab-close-button { display:none!important; }
#tabbrowser-tabs ~ #alltabs-button { display:none!important; }
.tabbrowser-tabs[treestyletab-mode="vertical"]
.tabbrowser-arrowscrollbox > scrollbox {
overflow-y: hidden !important;
}
/*.tabbrowser-tabs[treestyletab-mode="vertical"]
.tabbrowser-tab {