Skip to content

Instantly share code, notes, and snippets.

View NicolasT's full-sized avatar

Nicolas Trangez NicolasT

View GitHub Profile
(defn fact1 [n]
(loop [cnt n acc 1]
(if (zero? cnt)
acc
(recur (dec cnt) (* acc cnt)))))
(defn fact2 [n]
(loop [cnt n acc 1]
(do
(println cnt acc)
# <License type="Sun Cloud BSD" version="2.2">
#
# Copyright (c) 2005-2009, Sun Microsystems, Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or
# without modification, are permitted provided that the following
# conditions are met:
#
# 1. Redistributions of source code must retain the above copyright
module Test.Datastore (Datastore, runDatastore, get, put, delete) where
import qualified Control.Monad.Reader as R
import qualified Database.TokyoCabinet as TC
import Control.Monad.Trans (liftIO)
import Data.ByteString.Char8 (ByteString)
type Key = ByteString
type Value = ByteString
module Main (main) where
import Control.Concurrent (forkIO, threadDelay)
import Control.Concurrent.MVar (MVar, modifyMVar_, newMVar, newEmptyMVar,
putMVar, takeMVar)
import Control.Exception (finally)
import Control.Monad (forM_)
import qualified IO
import IO (BufferMode(..))
{-# LANGUAGE BangPatterns #-}
module Main (main) where
import Control.Concurrent (forkIO)
import Control.Concurrent.MVar (newEmptyMVar, putMVar, takeMVar)
import Control.Exception (finally)
import Control.Monad (forM_)
import qualified Data.ByteString.Lazy as LB
import math
import itertools
def system():
clock = itertools.count()
constant_signal = lambda t: math.sin(t)
controllable_signal1 = lambda (a, o): lambda t: a * math.sin((t + o) / 2)
controllable_signal2 = lambda (a, o): lambda t: a * math.sin((t + o) * 2)
/*
* A "devnull" module
*
* Cheers @ KDW
*
* Makefile:
*
* obj-m := devnull.o
*
* KERNELDIR ?= /lib/modules/$(shell uname -r)/build
@NicolasT
NicolasT / quickcheck_c.hs
Created October 18, 2010 00:57
A demonstration of using QuickCheck to test C code
-- This is a snippet cut-and-paste from a larger code body, might not compile or
-- work as expected as such
import Prelude hiding (pi)
import Data.Bits
import Data.Word (Word32)
import Foreign.C.Types (CSize)
import Foreign.Marshal.Array (withArrayLen)
'''
A solution for http://www.quora.com/How-to-move-all-negative-numbers-before-positive-numbers-and-preserve-their-original-orders-at-the-same-time-O-n-time-and-O-1-space-are-required
'''
import operator
class Node(object):
'''Linked list node representation'''
__slots__ = '_data', '_next',
@NicolasT
NicolasT / gist:737518
Created December 11, 2010 18:01
clutter_gst.js
const Clutter = imports.gi.Clutter,
ClutterGst = imports.gi.ClutterGst,
Gst = imports.gi.Gst,
Lang = imports.lang,
Mainloop = imports.mainloop;
/* Thanks ebassi */
let _animations = new Array();