Skip to content

Instantly share code, notes, and snippets.

View berkus's full-sized avatar
🎯
Practice your desensitization exercises to remain unfazed by enemy atrocities

Berkus Decker berkus

🎯
Practice your desensitization exercises to remain unfazed by enemy atrocities
View GitHub Profile
@lpereira
lpereira / partial.c
Last active January 29, 2023 20:12
Partial functions in C This program illustrates a hack to create partial functions in C. The way it works is that it generates a template function (partial_template_function) with known pointers, that is later copied to a region of memory obtained with mmap(), patched up with the address and data to be passed to the real function, and then made …
/*
* Partial applied functions in C
* Leandro Pereira <[email protected]>
*/
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <stdbool.h>
@timruffles
timruffles / tmux_perms_fix.md
Last active April 17, 2020 03:48
fix for tmux not starting up due to permissions issues

If you try to run tmux and get:

$ tmux
create session failed: : No such file or directory
$ strace -f -e trace=file tmux
...
[pid 15852] open("/dev/ptyp0", O_RDWR)  = -1 EACCES (Permission denied)

You don't have perms for the pseudoterminals. Add your user to the tty group

@mikelikespie
mikelikespie / NSData+PIOAdditions.h
Created February 14, 2013 06:35
Zero-Copy bridging between dispatch_data_t and NSData
//
// NSData+PIOAdditions.h
// PonyExpress
//
// Created by Michael Lewis on 2/13/13.
//
//
#import <Foundation/Foundation.h>
-- Primer on representing non-printable characters in Lua code
function assert_equal(a, b)
if a ~= b then
error(a .. ' is not equal to ' .. b)
end
end
-- Escape sequences in string use decimal character codes, i.e.
assert_equal('\97\98\99', 'abc')
@piscisaureus
piscisaureus / pr.md
Created August 13, 2012 16:12
Checkout github pull requests locally

Locate the section for your github remote in the .git/config file. It looks like this:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = [email protected]:joyent/node.git

Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to this section. Obviously, change the github url to match your project's URL. It ends up looking like this:

@pyrtsa
pyrtsa / any_visitor.cpp
Created June 17, 2012 19:09
Visitor pattern for boost::any in C++11
#include <boost/any.hpp>
#include <unordered_map>
#include <functional>
#include <iostream>
#include <vector>
struct type_info_hash {
std::size_t operator()(std::type_info const & t) const {
return t.hash_code();
}
@yamaya
yamaya / xcode-clang-vers
Last active April 2, 2025 00:16
Xcode clang version record
# Xcode 4.3.3
Apple clang version 3.1 (tags/Apple/clang-318.0.61) (based on LLVM 3.1svn)
Target: x86_64-apple-darwin11.4.0
Thread model: posix
# Xcode 4.3.2
Apple clang version 3.1 (tags/Apple/clang-318.0.58) (based on LLVM 3.1svn)
Target: x86_64-apple-darwin11.4.0
Thread model: posix
@berkus
berkus / gist:2651413
Created May 10, 2012 06:25 — forked from axelav/gist:1839777
Sublime Text 2 - Useful Shortcuts

Sublime Text 2 – Useful Shortcuts (Mac OS X)

General

⌘T go to file
⌘⌃P go to project
⌘R go to methods
⌃G go to line
⌘KB toggle side bar
⌘⇧P command prompt
@wanderrful
wanderrful / gist:2592498
Created May 4, 2012 06:13
Euclidean Algorithm in C++
=begin
I found this randomly and wanted to save it for future reference.
Let a, b denote the numerator and denomator, respectively. Let 'gcd' denote the Greatest Common Divisor of both a and b.
=end
if(a==0 || b==0)
return gcd = 1;
else
@masak
masak / explanation.md
Last active April 10, 2025 16:42
How is git commit sha1 formed

Ok, I geeked out, and this is probably more information than you need. But it completely answers the question. Sorry. ☺

Locally, I'm at this commit:

$ git show
commit d6cd1e2bd19e03a81132a23b2025920577f84e37
Author: jnthn <[email protected]>
Date:   Sun Apr 15 16:35:03 2012 +0200

When I added FIRST/NEXT/LAST, it was idiomatic but not quite so fast. This makes it faster. Another little bit of masak++'s program.