Skip to content

Instantly share code, notes, and snippets.

// <label for={this.props.label}>{this.props.label}</label>
// compiles to...
React.DOM.label( {for:this.props.label}, this.props.label)
// should be...
React.DOM.label( {"for":this.props.label}, this.props.label)
// Because IE doesn't allow language keywords to appear unquoted in object literal keys
@aymanosman
aymanosman / fizzbuzz.hs
Last active August 29, 2015 14:09
fizzbuzz.hs
import Data.Maybe
import Data.Monoid
import Control.Applicative
-- Mostly stolen from an answer found posted on reddit.
-- This formulation achieves a high level of modularity and clarity.
-- It is modular with respect to adding more numbers to fizz and buzz against,
-- and captures the idea of `show`ing the number by default elegantly.
t m s n = if mod n m == 0 then Just s else Nothing
-- instance Applicative ((->) a) where (<*>) f g x = f x (g x)
@aymanosman
aymanosman / install_zmq.sh
Last active August 29, 2015 14:11
Install zeromq
#install zeromq
wget http://download.zeromq.org/zeromq-4.0.5.tar.gz
tar -xzf zeromq-4.0.5.tar.gz
cd zeromq-4.0.5
./configure
make
sudo make install
@aymanosman
aymanosman / fz.py
Last active August 29, 2015 14:17
fz.py
def fizz(n):
for i in xrange(1, n+1):
print i, fz(i)
def t(m, s, n):
return s if (n%m==0) else ''
def fz(n):
s = ''.join([
t(3, 'Fizz', n),
echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.bashrc
. ~/.bashrc
mkdir ~/local
mkdir ~/node-latest-install
cd ~/node-latest-install
curl http://nodejs.org/dist/node-latest.tar.gz | tar xz --strip-components=1
./configure --prefix=~/local
make install # ok, fine, this step probably takes more than 30 seconds...
curl https://www.npmjs.org/install.sh | sh
@aymanosman
aymanosman / pg_restore_command.sh
Last active August 29, 2015 14:17
pg_restore command
createdb dbname
pg_restore -d dbname -Ocxv db.dump
# -c Clean, -O no owner, -v verbose, -x no privileges no acl
@aymanosman
aymanosman / postgres_index_varchar
Last active August 29, 2015 14:18
Explain select on uuid::varchar
EXPLAIN select * from tablename where uuid LIKE 'as%';
QUERY PLAN
-----------------------------------------------------------------------------------------------------------------------
Index Scan using tablename_uuid_like on tablename (cost=0.14..8.16 rows=1 width=1476)
Index Cond: (((uuid)::text ~>=~ 'as'::text) AND ((uuid)::text ~<~ 'at'::text))
Filter: ((uuid)::text ~~ 'as%'::text)
{-# LANGUAGE OverloadedStrings #-}
import Control.Concurrent
import Web.Growler
import Web.Growler.EventSource
import Network.Wai.EventSource
main = growl id defaultConfig $ get "/" $ eventSource es
@aymanosman
aymanosman / growler2.hs
Last active August 29, 2015 14:19
growler2
-- :set -XOverloadedStrings
import Web.Growler
import Network.Wai.Handler.Warp as Warp
Warp.run 3001 =<< growler id defaultConfig (get "/" $ text "Hello")
@aymanosman
aymanosman / elm-events.elm
Created October 30, 2015 12:23
Demonstrate custom event capture in Elm
import Dict exposing (Dict)
import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (..)
import String
import Debug exposing (log)
import Json.Decode as Json
import Signal exposing (Address)
import StartApp.Simple
import Json.Decode as Json