This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--=================================================== | |
--= 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>; |
OlderNewer