Skip to content

Instantly share code, notes, and snippets.

@exallium
exallium / thread.cpp
Created March 5, 2012 03:38
Boost Multithread Example with shared lock
#include <iostream>
#include <boost/thread.hpp>
using namespace std;
using boost::thread;
using boost::mutex;
using boost::shared_lock;
using boost::shared_mutex;
using boost::upgrade_lock;
using boost::upgrade_to_unique_lock;
@exallium
exallium / millerrabin.py
Created May 26, 2011 02:01
Modular Exponential and Miller Rabin Algorithms
# Please note, this is not my work, but the work of a fellow redditer.
# I am simply placing it here for future use.
def MillerRabin(n,k=5):
'''
Performs the Miller-Rabin primality test on n to an error bound of 4^-k
(i.e. performs the test k times). True indicates a probable prime while a
false result indicates a definite composite number.
Inputs:
n - Number to be tested for primality
@exallium
exallium / index.html
Created January 5, 2012 19:18
Tab Layout in HTML/CSS/Javascript
<head>
<link rel="stylesheet" type="css" href="css/tab.css" />
<script src="js/tab.js" type="text/javascript"></script>
</head>
<body>
<div class="tab-wrapper">
<div class="tab-button-wrapper">
<ul>
<li><a class="tab-button-first"
id="tab-button1"
@exallium
exallium / reverse.asm
Created March 10, 2012 20:53
YASM/NASM Reverse a string w.o. copy for x64 Linux
; ------------------------
; reverse.asm - Reverse a string without copying it
; Max length of string is 64 bytes
; This is for an x86_64 Linux System
; Assemble with:
; yasm -f elf64 reverse.asm
; Link with:
; ld -o reverse reverse.o
; Note: Also perfectly capable of swapping yasm for nasm without changing code
; ------------------------
@exallium
exallium / thread.cpp
Created February 19, 2012 16:37
Boost Multithread Example
#include <iostream>
#include <boost/thread.hpp>
using namespace std;
using boost::thread;
using boost::mutex;
mutex a;
const int THREAD_COUNT = 10;
data Parser = WebParser | DbParser
class ParseStrategy p where
parse :: p -> String -> String
instance ParseStrategy Parser where
parse WebParser s = "code for parsing web stuff goes here"
parse DbParser s = "code for parsing db stuff goes here"
fromDB = parse DbParser
@exallium
exallium / .vimrc
Created July 24, 2011 23:02
My Current .vimrc and .zshrc
filetype plugin on
filetype plugin indent on
syntax on
set t_Co=256
set bg=dark
colorscheme solarized
set backspace=indent,eol,start
bd = branch --delete
bm = branch --merged
cbr = rev-parse --abbrev-ref HEAD
cm = commit -m
co = checkout
cob = checkout -b
comit = commit
g = grep --break --heading --line-number
lol = log --pretty=oneline --abbrev-commit --graph --decorate
ship = push
@exallium
exallium / Promise.kt
Created February 14, 2019 19:57
Quick and dirty Promise in Kotlin
sealed class Either<out L, out R> {
data class Left<out L>(val l: L) : Either<L, Nothing>()
data class Right<out R>(val r: R) : Either<Nothing, R>()
}
fun asdf() {
val p = Promise<Int> { resolve, reject ->
resolve(Either.Left(4))
}
@exallium
exallium / formdata.kt
Last active February 14, 2018 16:41
Attempt at expressing form input a little more concisely
import android.databinding.BindingAdapter
import android.support.design.widget.TextInputEditText
import android.support.design.widget.TextInputLayout
data class FormData<out D, R>(
val data: D,
val reason: R?,
private val _reasonToString: (R?) -> String = { "$it" }
) {
val isValid = reason != null