Skip to content

Instantly share code, notes, and snippets.

#include <pthread.h>
#include <stdio.h>
#include <unistd.h>
#define TOTAL_THREADS 2
#define MAX 10
int shared = 0;
int turn = 0;
int started = 0;
@minhnhdo
minhnhdo / quicksort.hs
Created December 31, 2011 14:33
quicksort in haskell
quicksort :: (Ord a) => [a] -> [a]
quicksort [] = []
quicksort (x:xs) = smaller ++ equal ++ greater
where smaller = quicksort (filter (<x) xs)
equal = x:(filter (==x) xs)
greater = quicksort (filter (>x) xs)
@minhnhdo
minhnhdo / natnum.hs
Created January 1, 2012 13:03
recursive natural number generator in Haskell
addStream :: (Num a) => [a] -> [a] -> [a]
addStream (x:xs) (y:ys) = x + y : addStream xs ys
natural :: [Integer]
natural = 1 : addStream natural (repeat 1)
@minhnhdo
minhnhdo / sp2011.sh
Created April 15, 2012 15:51
answer to a friend's friend's question
#!/bin/bash
error () {
# USAGE: error <message> <is_fatal>
echo -n "!!ERROR!! " 1>&2
echo "$1" 1>&2
if (( "$2" )); then
exit 1
fi
}
@minhnhdo
minhnhdo / mkentry.sh
Created November 28, 2012 17:02
A helper script for keeping my journal
#! /bin/sh
FILENAME=`date +'%Y%m%d'`
if test ! -e $FILENAME; then
touch $FILENAME
fi
if test -s $FILENAME; then
cat >> $FILENAME <<HORIZONTAL
@minhnhdo
minhnhdo / ledis.md
Last active December 6, 2015 16:50

Update (10am)

  • RPUSH, SADD needs to support multiple values
  • Command names are case-insensitive, parameter and values are case-sensitive and must be all lowercase.
  • If a command doesn't specify return value, please return OK if successful, or follow the error code.
  • Updated sample tests (see link in the sample tests section)
  • SET will always overwrite the value for that key

Grokking Challenge Finale

/*
* Copyright (c) 2012 Stefano Sabatini
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
@minhnhdo
minhnhdo / set-operations.lisp
Last active December 16, 2015 15:58
Set operations in Common Lisp
(defun powerset (list)
"powerset returns the list of sublists of list"
(reduce #'(lambda (e l)
(nconc (mapcar #'(lambda (l) (cons e l)) l)
l))
list
:from-end t
:initial-value '(nil)))
(defun permutation (list)
@minhnhdo
minhnhdo / infix-postfix.lisp
Created April 25, 2013 12:26
Infix to postfix expression conversion
(defun precedence (op)
(cond
((or (eq op '*) (eq op '/)) 20)
((or (eq op '+) (eq op '-)) 10)
(t 0)))
(defun infix->postfix (infix-exp)
"infix->postfix returns a postfix version of the infix expression passed to it. Currently, it does no error checking and does not support expressions with brackets."
(labels ((helper (acc op el iexp)
(cond
#! /usr/local/bin/guile \
-e main -s
!#
(use-modules ((sxml xpath)
#:select (sxpath))
(ice-9 getopt-long)
(ice-9 ftw))
(define *processors* '())