Skip to content

Instantly share code, notes, and snippets.

@outro56
outro56 / vagrant-devenv-provision.sh
Last active August 29, 2015 14:21
Provision development image
#!/usr/bin/env bash
echo "Provisioning virtual machine..."
sudo apt-get update
sudo apt-get install -y python-software properties
sudo apt-get install -y software-properties-common
sudo add-apt-repository -y ppa:webupd8team/java
@outro56
outro56 / .profile
Last active August 29, 2015 14:21 — forked from tamlyn/.profile
Terminal setup for windows using Console2 (http://sourceforge.net/projects/console/)
# always list in long format
alias ls='ls -la --color'
alias clear=cls
# set dynamic prompt and window/tab title
PS1='\[\e]0;${PWD##*/}\a\]\n' # set window title
#PS1="$PS1"'\u@\h ' # user@host<space>
PS1="$PS1"'\[\033[32m\]' # change color
PS1="$PS1"'\w' # current working directory
if test -z "$WINELOADERNOEXEC"
@outro56
outro56 / gist:20915d7e65ee2f27a03a
Last active August 29, 2015 14:22
Find the top X frequent numbers in a stream
//Find the top X frequent numbers in a stream
// http://www.cs.berkeley.edu/~satishr/cs270/sp11/rough-notes/Streaming-two.pdf
// Returns the top numbers k and their frequencies in the set
// Complexity:
// space = O(k)
// time = O(N)
map<int, int> getFreq(k, Set) {
A = map<int, int>
for (k : getTop(k, Set) {
--===================================================
--= Niklas Frykholm
-- basically if user tries to create global variable
-- the system will not let them!!
-- call GLOBAL_lock(_G)
--
--===================================================
function GLOBAL_lock(t)
local mt = getmetatable(t) or {}
mt.__newindex = lock_new_index
@outro56
outro56 / gist:dc35f057fe8c2643e378
Created November 25, 2015 03:19
Bittwiddling hacks
1. Check if a number is even or odd
An integer number N is even if its least significant bit is 0 otherwise it is odd
N AND 1
2. Divide by 2
Given an integer number N you can divide it by 2 by shifting all the bits to the right with one position.
N >> 1
@outro56
outro56 / MemoryMapppedIOExtensions.cs
Created January 22, 2016 23:02
quickly read bytes from a memory mapped file
// Copied from
// http://stackoverflow.com/questions/7956167/how-can-i-quickly-read-bytes-from-a-memory-mapped-file-in-net
public static MemoryMapppedIOExtensions
{
public unsafe byte[] ReadBytesFast(this MemoryMappedViewAccessor view, int offset, int num)
{
try
{
byte[] arr = new byte[num];
@outro56
outro56 / gist:3c111f72dd26c27ced47862c86e3cf65
Created August 5, 2016 15:47
Kill all docker containers
stop all containers:
docker kill $(docker ps -q)
remove all containers
docker rm $(docker ps -a -q)
remove all docker images
docker rmi $(docker images -q)
local function clone_function(fn)
local dumped = string.dump(fn)
local cloned = loadstring(dumped)
local i = 1
while true do
local name = debug.getupvalue(fn, i)
if not name then
break
end
debug.upvaluejoin(cloned, i, fn, i)
@outro56
outro56 / version1.lua
Last active August 3, 2018 04:12 — forked from randrews/hoc4.lua
Toy calculator in Lua, version 4 - http://www.playwithlua.com/?p=73#more-73
function eval(num1, operator, num2)
if operator == '+' then
return num1 + num2
elseif operator == '-' then
return num1 - num2
elseif operator == '*' then
return num1 * num2
elseif operator == '/' then
return num1 / num2
else
template<typename T, typename U>
using assign_expression = decltype(std::declval<T&>() = std::declval<U&>());
template<typename T, typename U>
constexpr bool is_assignable = is_detected<assign_expression, T, U>;