Skip to content

Instantly share code, notes, and snippets.

View parambirs's full-sized avatar
👋

Parambir Singh parambirs

👋
View GitHub Profile
putStrLn
putStr
putChar
print
getChar
sequence
mapM
mapM_
@parambirs
parambirs / tsconfig.json
Last active August 26, 2016 02:43
TypeScript init
{
"compileOnSave": true,
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"noImplicitAny": true,
"removeComments": true,
"preserveConstEnums": true,
"sourceMap": true,
"outDir": "compiled",
@parambirs
parambirs / readchar.c
Created July 23, 2016 01:03
Reading a character in C
char firstCh, secondCh;
printf("Enter first character: ");
scanf(" %c", &firstCh); // Note: a space before %c
printf("Enter second character: ");
scanf(" %c", &secondCh);
// The following WON'T work as the newline entered as part of the first scanf would be consumed by the next scanf call:
printf("Enter first character: ");
scanf("%c", &firstCh); // Will not work correctly!
@parambirs
parambirs / HelloCompletableFuturesWithFailures.java
Created April 29, 2016 03:28
An example of composing CompletableFutures where the underlying future can fail.
import java.time.Duration;
import java.time.temporal.ChronoUnit;
import java.util.concurrent.CompletableFuture;
import static java.lang.System.err;
import static java.lang.System.out;
public class HelloCompletableFuturesWithFailures {
public static void main(String[] args) {
CompletableFuture<String> future = new Async().thinkOfSomething();
@parambirs
parambirs / HelloCompletableFutures.java
Created April 29, 2016 02:17
An example of using CompletableFutures and how it's easy to compose functionality (compared to callbacks).
import java.time.Duration;
import java.time.temporal.ChronoUnit;
import java.util.concurrent.CompletableFuture;
import static java.lang.System.err;
import static java.lang.System.out;
public class HelloCompletableFutures {
public static void main(String[] args) {
CompletableFuture<String> future = new Async().thinkOfSomething();
@parambirs
parambirs / link
Created April 15, 2016 00:26
While working on npm cli app, use npm link to make the global symlink point to your working files.
@parambirs
parambirs / readlink
Created April 15, 2016 00:22
Read a unix link
@parambirs
parambirs / postgres_create_db
Created January 18, 2016 22:27
Postgres create db
% cd /usr/local/Cellar/postgresql/9.4.5_2/bin
% ./createdb --owner db_user --encoding utf8 db_name
@parambirs
parambirs / create_postgres_user
Created January 18, 2016 22:25
Create postgres user
% cd /usr/local/Cellar/postgresql/9.4.5_2/bin
# -d user can create databases
# -P prompt for user password
# -E encrypt user's password
% createuser -d -P -E db_user
@parambirs
parambirs / sleep.js
Created January 6, 2016 12:24
Sleep in JS
function sleep(milliSeconds) {
var startTime = new Date().getTime();
while (new Date().getTime() < startTime + milliSeconds);
}
sleep(10000);