Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am christiansakai on github.
  • I am christiansakai (https://keybase.io/christiansakai) on keybase.
  • I have a public key whose fingerprint is 74E8 F9E2 876B F233 180C 298F B187 A3C8 EE48 EE85

To claim this, I am signing this object:

@Exegetech
Exegetech / choir.exs
Created June 29, 2017 16:49
Concurrency vs Parallelism in Elixir
defmodule Choir do
@voices ["Bells", "Good News", "Pipe Organ", "Cellos", "Bad News"]
# Concurrency
def sing do
{:ok, pid} = Singer.start_link
Enum.map 1..20, fn x ->
voice = Enum.random @voices
Singer.sing_it pid, voice
@Exegetech
Exegetech / pg_import_csv_to_heroku.sh
Created August 8, 2017 15:32 — forked from jboesch/pg_import_csv_to_heroku.sh
Importing a CSV dump of Postgres data into Heroku
# You have your csv data and it looks like so... It's in a file named "my_data.csv" and we want to import it into a table named "my_things".
"1", "Something", "0.50", "2013-05-05 10:00:00"
"2", "Another thing", "1.50", "2013-06-05 10:30:00"
# Now you want to import it, go to the command line and type:
$ PGPASSWORD=PWHERE psql -h HOSTHERE -U USERHERE DBNAMEHERE -c "\copy my_things FROM 'my_data.csv' WITH CSV;"
# Voila! It's impoted. Now if you want to wipe it out and import a fresh one, you would do this:
@Exegetech
Exegetech / debug_cors
Created October 11, 2017 19:25
How to debug CORS using `curl`
# How to Debug CORS
# Use this Shell script for example.
# * Intentionally add the wrong Origin, e.g. http://localhost below
# but <AllowedOrigin>http://somedomain.com</AllowedOrigin> in your CORS policy.
# * Run this script. The `--verbose` should give you back the response.
# * Check if the CORS policy is being returned with response.
# For example, the Access-Control-Allow-Origin should give you back your Origin that you used below.
# The actual resource (e.g., CSS, JS, font, image) files will still be returned because this is a non-browser request.
# (Keep in mind that CURL, POSTMAN, or any other non-browser related request
@Exegetech
Exegetech / update_column_type.sql
Created November 27, 2017 18:28 — forked from mmasashi/update_column_type.sql
How to change the column type for Redshift.
BEGIN;
LOCK table_name;
ALTER TABLE table_name ADD COLUMN column_new column_type;
UPDATE table_name SET column_new = column_name;
ALTER TABLE table_name DROP column_name;
ALTER TABLE table_name RENAME column_new TO column_name;
END;
-- varchar -> integer
-- UPDATE cpvbeacon_dev SET column_new = CAST (nullif(column_name, '') AS INTEGER);
@Exegetech
Exegetech / Json.hs
Created January 6, 2018 06:25 — forked from soupi/Json.hs
A simple JSON EDSL
{- | An EDSL for defining and printing JSON values
-}
import Data.List (intercalate)
----------------
-- JSON Model --
----------------
-- | The JSONValue data type represents a JSON Value
@Exegetech
Exegetech / Less.hs
Created January 6, 2018 06:25 — forked from soupi/Less.hs
a file reader similar to less
module Main where
import System.IO (hSetBuffering, stdin, BufferMode(NoBuffering))
import Control.Monad (unless)
import System.Process (system)
import System.Environment (getArgs)
stepSize :: Int
stepSize = 30
@Exegetech
Exegetech / Lisp.hs
Created January 6, 2018 06:25 — forked from soupi/Lisp.hs
A transpiler from a simple S-expression language to JS
{-# LANGUAGE LambdaCase #-}
-- http://gilmi.xyz/post/2016/10/14/lisp-to-js
module Main where
import Control.Applicative (Alternative, empty, (<|>))
import Control.Arrow (first, (***))
import Data.Bool (bool)
import Data.List (intercalate)
@Exegetech
Exegetech / concat.hs
Created January 6, 2018 06:25 — forked from soupi/concat.hs
simple concatenative interpreter
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE LambdaCase #-}
import Control.Monad
import Data.Data
import Data.Typeable
import System.IO
import System.Exit
type Stack = [Lit]
@Exegetech
Exegetech / channel.js
Created March 5, 2018 23:06 — forked from srikumarks/channel.js
CSP-style channel implementation for Javascript on top of ES6-style Promises.
"use strict";
// Channel is a simple object that can be used for
// CSP-style concurrency in Javascript. In JS code,
// the act of taking a value from a channel looks
// like a blocking call and therefore is not appropriate
// for single-process/single-thread environments like
// NodeJS. To address that, Channel produces promises
// for values.
//