Skip to content

Instantly share code, notes, and snippets.

View Grantismo's full-sized avatar

Grant Warman Grantismo

  • Google
  • New York
View GitHub Profile
words = [w.strip() for w in open('/usr/share/dict/words').readlines()]
print([w for w in words if len(w) == 8 and w[0] == w[6]
and w[1] == w[3] and w[1] == w[5] and w[2] == w[7]])
@Grantismo
Grantismo / Option 2
Created March 18, 2015 20:25
Some json format options
{
"SOVIETSECRET": {
"exercises": [
"hangboard",
"offset pullups",
"push ups",
"100 ab wheel reps"
]
},
"MOSTLYHGH": {
//obj1 and obj2 are mongoose models
//Doesn't work
aync.parallel([obj1.save, obj2.save], function(err, results){
//do stuff after both objects save
});
//Works
aync.parallel([obj1.save.bind(obj1), obj2.save.bind(obj2)], function(err, results){
function FirstReverse(str){
var reverseBucket = "";
for(var i = 0; i < str.length; i++){
var swapNumber = str.length - 1 - i;
var showString = str[swapNumber];
reverseBucket = reverseBucket + showString ;
console.log("\ni: " + i);
console.log("swapNumber: " + swapNumber);
a b c d e f g h
0 1 2 3 4 5 6 7
stuff.length = 8
var i = 0; var tmp = stuff[0]; //a stuff[0] = stuff[7] //7 - 0 = 7
var i = 1; var tmp = stuff[1]; //b stuff[1] = stuff[6] //7 - 1 = 6
var i = 2; var tmp = stuff[2]; //c stuff[2] = stuff[5] //7 - 2 = 5
var i = 3; var tmp = stuff[3]; //d stuff[3] = stuff[4] //7 - 3 = 4
@Grantismo
Grantismo / Optional+omap.swift
Last active August 29, 2015 14:02
Optional chaining for arbitrary operations
extension Optional{
func omap<K:Any>(optionalBlock:(T)->(K?))->K?{
if self{
return optionalBlock(self!)
}
return nil
}
}
@Grantismo
Grantismo / git_branch_bashrc
Created September 20, 2013 15:28
adds current branch to console
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'
}
if [ "$color_prompt" = yes ]; then
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\] ($(parse_git_branch))\$ '
else
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
@Grantismo
Grantismo / extract_pgn.js
Last active December 23, 2015 09:59
Bookmarklet for extracting PGN from live chess.com game
javascript:(function(){ pgn = ""; currentBoard = $(".boardContainer:not(.chess_com_hidden, .visibilityHidden)"); pgn += '[White "' + currentBoard.find("[id^=white_player_name_]").text() + '"]\n[Black "' + currentBoard.find("[id^=black_player_name_]").text() + '"]\n[Result "*"]\n\n'; $(".dijitVisible").find('.gotomove').each(function(index, element){if(index % 2 == 0){pgn += ((index + 2) / 2) + ". "};pgn += $(this).text() + " "});pgn += " *"; alert(pgn); })();