Skip to content

Instantly share code, notes, and snippets.


evandrix evandrix

View GitHub Profile
evandrix /
Created Jun 26, 2013
Correct way to read file line-by-line
while read line;do
echo "Line # $k: $line"
done < $FILE
echo "Total number of lines in file: $k"
View free-monad-transform.hs
data FreeF f a x = Pure a | Free (f x)
newtype FreeT f m a =
FreeT { runFreeT :: m (FreeF f a (FreeT f m a)) }
instance (Functor f, Monad m) => Monad (FreeT f m) where
return a = FreeT (return (Pure a))
FreeT m >>= f = FreeT $ m >>= \v -> case v of
Pure a -> runFreeT (f a)
Free w -> return (Free (fmap (>>= f) w))

Transparent Git Encryption

This document has been modified from its [original format][m1], which was written by Ning Shang ( It has been updated and reformatted into a [Markdown][m2] document by [Woody Gilk][m3] and [republished][m4].


When working with a remote git repository which is hosted on a third-party storage server, data confidentiality sometimes becomes

evandrix / index.html
Created Apr 23, 2013
A CodePen by suffick. Tear-able Cloth - Javascript cloth simulation.
View index.html
<canvas id = "c" > </canvas>
<a target="_blank" href="" id="p">New pen: Like playing with physics? Click here!</a>
<div id="info">
<div id="top">
<a target="_blank" id="site" href="">my website</a>
<a id="close" href="">close</a>

Locate the section for your github remote in the .git/config file. It looks like this:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url =

Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to this section. Obviously, change the github url to match your project's URL. It ends up looking like this:

In order to use segtree class defined above, you will need to create a datatype(a struct most likely), which will implement the function merge(). It can also additionally implement split, if you need to define the split operation.
A sample is shown as "struct segtree_node" in the code above.
The segtree has to be instantiated with this defined data type. For example,as
segtree<segtree_node> s;
You have to first call the init function of the class, which will take
int n=number of elements in your array,
node[] = your inital array,
identity = an element such that merge(y,identity) = merge(identity,y) = y for all y's.
evandrix /
Created Mar 4, 2013
PyQt4 + load pyuic4-generated *.ui -> *.py
import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *
# custom slot
evandrix / int_partition.cpp
Created Feb 26, 2013
Generating all partitions of a given number: A partition of a positive integer number "n" is a way of writing "n" as a sum of positive integers.
View int_partition.cpp
#include <iostream>
// Output a partition:
void output_partition(const int n, const int *x, const int how_many_partitions)
std::cout << "Partition(" << how_many_partitions << ")" << " = ";
for (int i = 1; i <= n; i++)
// Can't show negative numbers:
if (x[i] > 0)
View iptables.firewall.rules
# Allow all loopback (lo0) traffic and drop all traffic to 127/8 that doesn't use lo0
-A INPUT -i lo -j ACCEPT
-A INPUT ! -i lo -d -j REJECT
# Accept all established inbound connections
# Allow all outbound traffic - you can modify this to only allow certain traffic
You can’t perform that action at this time.