Skip to content

Instantly share code, notes, and snippets.

@noahlt
noahlt / pick.py
Created November 17, 2015 18:12
Pick keys/values from dict
def pick(d, filter_tree):
'''Returns a new dictionary by picking keys/values from d per filter_tree.
Works recursively: values in filter_tree can be either True or dictionaries
which are their own filters.
>>> d = {'a': 1, 'b': 2, 'c': {'foo': -1, 'bar': -2}, 'd': {'r': 'red', 'b': 'blue'}}
>>> pick(d, {'a': True, 'b': True})
{'a': 1, 'b': 2}
>>> pick(d, {'a': True, 'b': True, 'd': True})
{'a': 1, 'b': 2, 'd': {'r': 'red', 'b': 'blue'}}
@noahlt
noahlt / react_dont_update_children.html
Created October 17, 2015 00:52
Hack to block re-rendering child when parent was updated
<!DOCTYPE html>
<html>
<head>
<title>Hack to block re-rendering child when parent was updated</title>
<script src="https://fb.me/react-0.13.0.js"></script>
<script src="https://fb.me/JSXTransformer-0.13.0.js"></script>
</head>
<body>
</body>
@noahlt
noahlt / lintjs.sh
Created August 3, 2015 18:49
semiautomatic semicolon insertion
#!/usr/bin/env bash
# lintjs.sh
REPO_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." && pwd )
JS_FILES=$(find . \
-not -path '*node_modules*' \
-not -path '*module-cache*' \
-not -path '*/lib/*' \
-not -name '*.min.js' \
@noahlt
noahlt / .flowconfig
Last active August 29, 2015 14:19
flow check: declare module
[ignore]
[include]
[libs]
./lib.js
[options]
/*
* TOA = TON + NPI
* See TS 24.008 section 10.5.4.7 for details.
* These are the only really useful TOA values
*/
public static final int TOA_International = 0x91;
public static final int TOA_Unknown = 0x81;
@noahlt
noahlt / fizzbuzz.hs
Created December 18, 2013 02:21
FizzBuzz in Haskell — I'm sure this has been done before, but this one is mine.
mapM_ putStrLn [ if x `mod` 15 == 0 then "fizzbuzz" else if x `mod` 3 == 0 then "fizz" else if x `mod` 5 == 0 then "buzz" else show x | x <- [1..100]]
<html>
<!--
Copyright (c) 2013 Noah Tye <[email protected]>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
@noahlt
noahlt / killport.sh
Last active September 15, 2017 16:25
killport - kill whatever process is running on a given port
# add this to your .bash_profile to use it
# source: https://gist.github.com/noahlt/2662634
function killport {
if [ ! -n "$1" ] || [ $1 == '--help' ] || [ $1 == '-h' ]
then
echo '`killport <PORT>` finds the process listening to the specified port and kills it.'
else
process_line=`sudo lsof -i :$1 | tail -1`
if [ "$process_line" == "" ]
then
@noahlt
noahlt / hi.html
Created April 22, 2012 18:25
why doesn't `body *:hover` work?
<html>
<head>
<style>
body * { background-color: #FCF0AD; }
body *:hover { background-color: blue; }
*:hover { background-color: blue; }
body li:hover { background-color: red; }
</style>
<body>
@noahlt
noahlt / summary.md
Created October 23, 2011 21:35
How do I extract a particular column from text (like the output of ps)?

awk has a command for this:

$ awk '{print $2}' <filename>

You can, of course, also pipe in text output from another program:

$ who
noah     console  Oct 21 14:06 
noah     ttys000  Oct 23 13:08 

noah ttys001 Oct 23 14:00