Skip to content

Instantly share code, notes, and snippets.

View nh2's full-sized avatar

Niklas Hambüchen nh2

View GitHub Profile
@nh2
nh2 / redo.sh
Created June 19, 2013 02:32
redo: Saves the last command and runs it again when run with no arguments
#!/bin/bash
if [[ -z $@ ]]; then bash .redo; else echo $@ > .redo; $@; fi
@nh2
nh2 / ghc-api-annoyances.hs
Created August 20, 2013 06:43
GHC api annoyances - I just want to show some things
module List (listModules) where
import Control.Applicative
import Control.Monad
import Data.List
import GHC
import GHCApi
import GhcMonad
import Packages
import Types
@nh2
nh2 / ghc-7.7-type-a-a-a-families.hs
Created August 22, 2013 00:59
GHC 7.7 conflicting (a -> a) vs (a -> a -> a) type families
{-# LANGUAGE TypeFamilies #-}
module Test where
type family BoundsOf x
type instance BoundsOf (a->a) = Int
type instance BoundsOf (a->a->a) = (Int,Int)
-- | Compute CRC16 checksums using a lookup table.
module CRC16 (crc16, crc16File) where
import Data.Word
import Data.Array
import Data.Bits
import Data.ByteString.Lazy as BS
tableList :: [Word16]
tableList =
@nh2
nh2 / BenchmarkForce.hs
Created September 4, 2013 11:03
Some experiments with how long a deepseq takes
{-# LANGUAGE DeriveGeneric #-}
module Main where
import Control.DeepSeq
import Control.Exception (evaluate)
import Data.Time (diffUTCTime, getCurrentTime)
import GHC.Generics (Generic)
-- import Control.DeepSeq.Generics (genericRnf) -- from deepseq-generics
@nh2
nh2 / haskell-cucumber-syntax.feature
Created September 10, 2013 07:16
Haskell Cucumber syntax - an alternative syntax proposed for Haskell along with normal Haskell and Literate Haskell
Feature: The Data.List module
In order to be able to use lists
As a programmer
I want a module that defines list functions
Scenario: Defining the function foldl
Given I want do define foldl
Which has the type (in brackets) a to b to a (end of brackets), to a, to list of b, to a
And my arguments are called f, acc, and l
@nh2
nh2 / filter-tags.html
Last active December 23, 2015 10:39
Javascript serializable object filters. Filters a list of objects, with easy selection of the field and value to filter on using regexes.
<!-- An examples of how filter tags can be visualized, here in Angular.js -->
<div class="filters">
<li class="filterTag " ng-repeat="filter in filters">
<!-- Negation button and field -->
<span class="filterLeft ">
<a href="" class="invert" ng-class="{ inverted: filter.inverted }" title="invert" ng-click="filter.inverted = !filter.inverted">¬</a>
<input type="text" class="filterField" ng-model="filter.field" placeholder="field" title="which column to filter (regex)" autosize />
</span>
<!-- Rexex to apply to that field -->
@nh2
nh2 / cpd-sum.py
Created October 27, 2013 18:14
Counts total number of duplicate lines from a CPD output
# Counts total number of duplicate lines from a CPD output.
# Example:
# pmd-bin-5.0.5/bin/run.sh cpd --minimum-tokens 100 --files ../mysource --format text --language java | python cpd-sum.py
import fileinput
import re
nlines = 0
places = 0
total_dups = 0
@nh2
nh2 / copytoclipboard.js
Created November 11, 2013 01:26
Copying to clipboard in JS (worked with older Firefox versions)
function copyToClipboard(text) {
// ask for permission to access clipboard
try {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
} catch(e) {
alert(
gettext("Copy to clipboard failed because your browser prevents it.\n")
+ interpolate(gettext("For Mozilla Firefox, go to about:config and set the value of %s to 'true'."), ["signed.applets.codebase_principal"])
@nh2
nh2 / plot3.m
Created November 19, 2013 08:22
Simple way to plot a function taking 2 arguments in Matlab
% Simple way to plot a function taking 2 arguments.
% Usage:
% plot3d( @(x,y) x^2+y^2, range1, range2 )
function plot3d(f, range1, range2)
% mesh really wants it in this order :(
r = zeros(length(range2), length(range1));
[X, Y] = meshgrid(range1, range2);
s1 = size(range1)
s2 = size(range2)