Skip to content

Instantly share code, notes, and snippets.

@outro56
outro56 / call-graph.awk
Created June 21, 2018 12:06
Parse lua code and print call graph
#!/usr/bin/awk -f
#
# call_graph.awk
#
# Usage:
# ./call_graph.awk my_program.lua | dot -Tpng > call_graph.png
#
# This is a script that generates a visual call graph for a Lua file.
# This script only shows calls made to functions defined within the
# input Lua file; that is, it excludes calls such as standard library
@outro56
outro56 / git lol.md
Last active January 9, 2024 14:58
git lol
git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
git config --global alias.lol "log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
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 / 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)
@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: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

progrium/bashstyle

Bash is the JavaScript of systems programming. Although in some cases it's better to use a systems language like C or Go, Bash is an ideal systems language for smaller POSIX-oriented or command line tasks. Here's three quick reasons why:

  • It's everywhere. Like JavaScript for the web, Bash is already there ready for systems programming.
  • It's neutral. Unlike Ruby, Python, JavaScript, or PHP, Bash offends equally across all communities. ;)
  • It's made to be glue. Write complex parts in C or Go (or whatever!), and glue them together with Bash.

This document is how I write Bash and how I'd like collaborators to write Bash with me in my open source projects. It's based on a lot of experience and time collecting best practices. Most of them come from these two articles, but here integrated, slightly modified, and focusing on the most bang for buck items. Plus some ne

--===================================================
--= 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: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) {