Skip to content

Instantly share code, notes, and snippets.

@outro56
outro56 / MiniOrm.cs
Last active September 29, 2021 06:14 — forked from SamSaffron/gist:893878
Mini C# Orm
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Reflection.Emit;
using System.Collections.Concurrent;
using System.Data;
using System.Reflection;
@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

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

@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];