Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
offline

evandrix evandrix

💭
offline
View GitHub Profile
@evandrix
evandrix / read-file.sh
Created Jun 26, 2013
Correct way to read file line-by-line
View read-file.sh
k=1
while read line;do
echo "Line # $k: $line"
((k++))
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))
View encrypted-git-repo.md

Transparent Git Encryption

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

Description

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

@evandrix
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="http://codepen.io/stuffit/pen/fhjvk" id="p">New pen: Like playing with physics? Click here!</a>
<div id="info">
<div id="top">
<a target="_blank" id="site" href="http://lonely-pixel.com">my website</a>
<a id="close" href="">close</a>
</div>
<p>
View pr.md

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 = git@github.com:joyent/node.git

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:

View README
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
evandrix / pyqt4-uic.py
Created Mar 4, 2013
PyQt4 + load pyuic4-generated *.ui -> *.py
View pyqt4-uic.py
import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from <REPLACE_BY_PYUI_DESIGN> import <REPLACE_BY_WINDOW_CLASS_IN_PYUI_DESIGN>
class MainWindow(QMainWindow, <REPLACE_BY_WINDOW_CLASS_IN_PYUI_DESIGN>):
# custom slot
@evandrix
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
*filter
# 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 127.0.0.0/8 -j REJECT
# Accept all established inbound connections
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
# Allow all outbound traffic - you can modify this to only allow certain traffic
You can’t perform that action at this time.