Skip to content

Instantly share code, notes, and snippets.

Started GET "/api/system_status?_=1412070154562" for 127.0.0.1 at 2014-09-30 12:42:34 +0300
Processing by Api::V1::SystemStatusesController#index as JSON
Parameters: {"_"=>"1412070154562"}
LocalUser Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."type" IN ('LocalUser') AND "users"."id" = 2 ORDER BY "users"."id" ASC LIMIT 1
Completed 500 Internal Server Error in 2ms (Views: 0.1ms | ActiveRecord: 0.2ms)
@sinelaw
sinelaw / wikinews.hs
Last active August 29, 2015 14:07
tagsoup web scraping demo
module WikiNews where
import Network.HTTP(simpleHTTP, getRequest, getResponseBody)
import Data.List(isInfixOf, intersperse)
import Data.Char(isSpace, toLower)
import Control.Category((>>>))
import System.Random(getStdGen)
-- from package tagsoup:
@sinelaw
sinelaw / debounce.js
Created November 13, 2014 14:20
debouncer
function debounce(f, millis) {
var ready = true;
var timeoutId;
var lastMissed;
function resetTimeout(){
window.clearTimeout(timeoutId);
timeoutId = window.setTimeout(function() {
if (lastMissed) {
lastMissed();
}
@sinelaw
sinelaw / test.js
Last active August 29, 2015 14:10
inference
// (c -> c)
// c
var id = function(x) { return x; };
// (i -> i)
// TNumber
var num = id(3);
// (n -> n)
// TString
var str = id('a');
@sinelaw
sinelaw / FixT.hs
Created December 25, 2014 20:45
fixed-point type
{-# LANGUAGE FlexibleContexts, FlexibleInstances #-}
module FixT where
data Expr = Val
| Divide Expr Expr
| Times Expr Expr
deriving Show
flipDivide :: Expr -> Expr
flipDivide Val = Val
@sinelaw
sinelaw / gen_files_json.hs
Created January 13, 2015 11:16
Generates a json file describing the directory structure
module Main where
import System.Directory (getDirectoryContents)
import Control.Monad (forM_)
import Data.Functor ((<$>))
import System.Posix.Files (getSymbolicLinkStatus, isDirectory)
withIsLast :: [a] -> [(a, Bool)]
withIsLast [] = []
withIsLast [x] = [(x, True)]
#include <rfftw.h>
#include <math.h>
#include <stdio.h>
/* the out format is: */
/* r0, r1, r2, ..., rn/2, i(n+1)/2-1, ..., i2, i1 */
void fft(int n, fftw_real in[n], fftw_real power_spectrum[n/2+1])
{
fftw_real out[n];
rfftw_plan p;
;;(load "/local-home/user18/repos/thirdparty/emacs-haskell-config/init.el")
(add-to-list 'load-path "~/repos/thirdparty/emacs-haskell-config/packages/haskell-mode/")
(require 'haskell-mode-autoloads)
(add-to-list 'Info-default-directory-list "~/repos/thirdparty/emacs-haskell-config/packages/haskell-mode/")
(require 'cl)
(add-to-list 'load-path "~/.emacs.d/lisp")
(require 'cask "~/.cask/cask.el")
{-# OPTIONS -Wall #-}
{-# LANGUAGE TypeFamilies, FlexibleInstances #-}
import Data.Map
class Indexable a where
type Index a
type Result a
index :: a -> Index a -> Result a
@sinelaw
sinelaw / indexable.hs
Created February 25, 2015 00:31
Associated types without type families - why can't this work?
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
class Indexable a where
instance Indexable (String, Int, Char) where
instance Indexable ([(String, a)], String, a) where
test1 :: Indexable (a,b,c) => a -> b -> c