Skip to content

Instantly share code, notes, and snippets.

View daurnimator's full-sized avatar

daurnimator

View GitHub Profile
@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.
----------------------------------------------------
@tclementdev
tclementdev / libdispatch-efficiency-tips.md
Last active April 26, 2024 10:15
Making efficient use of the libdispatch (GCD)

libdispatch efficiency tips

The libdispatch is one of the most misused API due to the way it was presented to us when it was introduced and for many years after that, and due to the confusing documentation and API. This page is a compilation of important things to know if you're going to use this library. Many references are available at the end of this document pointing to comments from Apple's very own libdispatch maintainer (Pierre Habouzit).

My take-aways are:

  • You should create very few, long-lived, well-defined queues. These queues should be seen as execution contexts in your program (gui, background work, ...) that benefit from executing in parallel. An important thing to note is that if these queues are all active at once, you will get as many threads running. In most apps, you probably do not need to create more than 3 or 4 queues.

  • Go serial first, and as you find performance bottle necks, measure why, and if concurrency helps, apply with care, always validating under system pressure. Reuse

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

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
@daurnimator
daurnimator / rock_to_PKGBUILD.lua
Last active October 8, 2022 15:51
Script to convert LuaRocks to Arch Linux PKGBUILDs
#!/usr/bin/env lua
local rockspec_name = assert(arg[1])
local function log(level, fmt, ...)
io.stderr:write(level .. "\t" .. string.format(fmt, ...) .. "\n")
end
local function append(tbl, ...)
for _, v in ipairs {...} do
@jhass
jhass / .gitignore
Last active July 24, 2022 23:15
powerdns remote backend for hashbang.sh
python/
*.log
@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
@a-dma
a-dma / yubitouch.sh
Last active March 10, 2022 14:43
Bash script for setting or clearing touch requirements for cryptographic operations in the OpenPGP application on a YubiKey 4.
#!/bin/bash
# Bash script for setting or clearing touch requirements for
# cryptographic operations the OpenPGP application on a YubiKey 4.
#
# Author: Alessio Di Mauro <alessio@yubico.com>
GCA=$(which gpg-connect-agent)
DO=0
UIF=0
@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
@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 = { }