Skip to content

Instantly share code, notes, and snippets.

@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")
{-# 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 / 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)
@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
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 / 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),
@aymanosman
aymanosman / challenges.md
Last active November 15, 2016 20:20
Challenges

Sum

sum1(1, 2, 3) == 6

Fizzbuzz

1 1
2 2
3 Fizz

4 4

@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 / 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 / nginx_auto_start.sh
Created August 1, 2014 12:11
Nginx: Start nginx on boot on Mac
# brew install nginx
sudo ln -s /usr/local/opt/nginx/homebrew.mxcl.nginx.plist /Library/LaunchDaemons/
sudo chown root:wheel /usr/local/opt/nginx/homebrew.mxcl.nginx.plist
sudo launchctl load /Library/LaunchDaemons/homebrew.mxcl.nginx.plist
# Why do you need sudo?
# If you want nginx to be able to bind to port 80, it will need superuser privileges