Skip to content

Instantly share code, notes, and snippets.

@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
@aymanosman
aymanosman / joi_objectid.js
Last active August 3, 2016 10:11
Validate ObjectIds with Joi
m = require('mongojs')
J = require('joi')
x = J.string().hex().length(24)
i = m.ObjectId().toString()
// '57a1c20202ccc41cd8d84834'
x.validate(i)
// { error: null, value: '57a1c20202ccc41cd8d84834' }
# Sexp equivalent, modulo infix arithmetic expression
# (defmodule M
# (def foo (lol)
# 2+lol))
# Starting from the "true", most verbose form and applying syntactic rules to
# obtain the final form
# "true" expression, notice there are no vararg functions
defmodule(M,
@aymanosman
aymanosman / Makefile
Created April 2, 2017 02:48
Haskell Makefile
HC = ghc
HC_OPTS = -cpp $(EXTRA_HC_OPTS)
SRCS = Main.lhs Foo.lhs Bar.lhs
OBJS = Main.o Foo.o Bar.o
.SUFFIXES : .o .hs .hi .lhs .hc .s
cool_pgm : $(OBJS)
rm -f $@
@aymanosman
aymanosman / 4clojure-30.clj
Last active November 26, 2018 23:32
4clojure-30.clj
(defn f
([xs] (if (empty? xs) () (f (first xs) (rest xs))))
([x xs]
(cond
(empty? xs) (list x)
:else
(let [y (first xs)]
(cond
(= x y)
@aymanosman
aymanosman / Exercise 3.4.rkt
Last active February 4, 2020 01:42
The Little Typer Exercise 3.4
#lang pie
(claim >
(-> Nat Nat Nat))
(define >
(lambda (n)
(rec-Nat n
(the (-> Nat Nat) (lambda (m) 0))
(lambda (n-1 n-1>)
(lambda (m)