Skip to content

Instantly share code, notes, and snippets.

View daurnimator's full-sized avatar

daurnimator

View GitHub Profile
@njonsson
njonsson / git-rebase-tags.rb
Created April 7, 2011 18:29
UPDATE: Use the `--tag-name-filter` option of `git-filter-branch`. http://blog.nilsjonsson.com/post/4421450571/rebasing-tags-in-git-repositories
#! /usr/bin/env ruby
def pluralize(word, count=2, plural_word=nil)
plural_word ||= "#{word}s"
"#{count} #{(count == 1) ? word : plural_word}"
end
unless (ARGV.length == 1) &&
(good_revision = system("git log -1 #{ARGV.first} 2>/dev/null"))
puts "Unknown revision '#{ARGV.first}'" unless good_revision
@jbenet
jbenet / current_utc_time.c
Created July 17, 2011 16:17
work around lack of clock_gettime in os x
/*
author: jbenet
os x, compile with: gcc -o testo test.c
linux, compile with: gcc -o testo test.c -lrt
*/
#include <time.h>
#include <sys/time.h>
#include <stdio.h>
@daurnimator
daurnimator / ec.lua
Created November 22, 2011 03:56
A replacement for lua errors; based on coroutines.
local select = select
local error = error
local cocreate , coresume , corunning , costatus , coyield = coroutine.create , coroutine.resume , coroutine.running , coroutine.status , coroutine.yield
local getinfo = debug.getinfo
local err_signifier = { }
local ec = { }
local function xpcall_resume ( co , hand , ok , ... )
@daurnimator
daurnimator / choose_type.lua
Created August 26, 2012 14:36
Lpeg pattern to parse a HTTP Accept Header
do
local function helper ( allowed , want )
return ( not want.type or allowed.type == "*" or ( allowed.type == want.type and
( not want.subtype or allowed.subtype == "*" or allowed.subtype == want.subtype ) )
) and allowed.q ~= 0
end
function choose_type ( allowed_list , wanted_list )
-- Remove items from allowed list that have no match (retains client ordering)
local res = { }
local allowed_wanted_map = { }
@daurnimator
daurnimator / app.lua
Created September 14, 2012 10:11
Sinatra like clone for lua
if not sinatra.incoming ( ngx.req.get_method() , ngx.var.uri ) then
return ngx.exit ( 404 )
end
@daurnimator
daurnimator / .bash_prompt.lua
Last active December 10, 2015 19:58
My bash prompt
local ret_code , n_jobs = ...
ret_code = tonumber ( ret_code )
n_jobs = tonumber ( n_jobs ) or 0
local ffi = require "ffi"
ffi.cdef [[
typedef uint32_t uid_t;
uid_t geteuid(void);
int gethostname(char *name, size_t namelen);
char *getcwd(char *buf, size_t size);
@tylerneylon
tylerneylon / learn.lua
Last active April 28, 2024 22:23
Learn Lua quickly with this short yet comprehensive and friendly script. It's written as both an introduction and a quick reference. It's also a valid Lua script so you can verify that the code does what it says, and learn more by modifying and running this script in your Lua interpreter.
-- Two dashes start a one-line comment.
--[[
Adding two ['s and ]'s makes it a
multi-line comment.
--]]
----------------------------------------------------
-- 1. Variables and flow control.
----------------------------------------------------

Exploiting Lua 5.1 on 32-bit Windows

The following Lua program generates a Lua bytecode program called ignore-unsigned-sga.fnt, which in turn loads a DLL from within an extremely locked down Lua 5.1 sandbox in a program called RelicCOH2.exe. The remainder of this document attempts to explain how this program works by a whirlwind tour of relevent bits of the Lua 5.1 virtual machine.

if string.dump(function()end):sub(1, 12) ~= "\27Lua\81\0\1\4\4\4\8\0" then
  error("This generator requires a 32-bit version of Lua 5.1")
end

local function outer()
  local magic -- In bytecode, the stack slot corresponding to this local is changed
@vishvananda
vishvananda / tunnel.sh
Created October 22, 2013 03:16
Script to set up an ipsec tunnel between two machines For Example: ./tunnel.sh 10.10.10.1 10.10.10.2 192.168.0.1 192.168.0.2 would set up an ipsec tunnel over 10.10.10.1 address using 192.168.0.1 as a virtual address passwordless sudo required for user on remote machine
#!/bin/bash
if [ "$4" == "" ]; then
echo "usage: $0 <local_ip> <remote_ip> <new_local_ip> <new_remote_ip>"
echo "creates an ipsec tunnel between two machines"
exit 1
fi
SRC="$1"; shift
DST="$1"; shift
@pims
pims / riakshell.go
Last active December 27, 2015 03:09
// tim$ go install
// tim$ cat logs | riakshell
package main
import (
"bufio"
"github.com/mrb/riakpbc"
"io"
"log"