Skip to content

Instantly share code, notes, and snippets.

Map without reserve
size: 0
bucket_count: 23
load_factor: 0
Allocation count: 0
size: 0
bucket_count: 23
@detunized
detunized / run
Created December 17, 2013 16:32
Strange compile error Clang vs GCC
$ clang -c test.cpp; gcc -c test.cpp
test.cpp:10:7: error: read-only variable is not assignable
x = 0;
~ ^
test.cpp:26:7: note: in instantiation of member function 'A<float>::f' requested here
a.f(0);
^
1 error generated.
@detunized
detunized / build.sh
Created February 7, 2014 19:21
Build and run a command line application on Android
#!/bin/sh
arm-linux-gnueabi-g++ -o yo -static main.cpp
adb push yo /storage/sdcard0/Android/data/
adb shell su -c "cd /storage/sdcard0/Android/data; cp yo /data/local/; rm yo; cd /data/local; chmod 751 yo; ./yo; rm yo"
@detunized
detunized / hg-to-git.rb
Created February 17, 2014 12:28
Converts a Mercurial repository to Git
#!/usr/bin/env ruby
require "rake"
require "colored"
abort "Usage: to-git hg-repo git-repo" if ARGV.size != 2
SOURCE = ARGV[0]
DESTINATION = ARGV[1]
def hg params
@detunized
detunized / pre-print.rb
Last active August 29, 2015 13:59
Prepare images for printing
#!/usr/bin/env ruby
min_width = `identify *.jpg`
.split("\n")
.map { |i| i[/JPEG (\d+x\d+)/, 1] }
.map { |i| i.split "x" }
.transpose[0]
.map { |i| i.to_i }
.min
@detunized
detunized / sort-libs.rb
Last active March 26, 2025 00:40
Sort static libraries in the topological order
#!/usr/bin/env ruby
# This script sorts static libraries in the topological order suitable for
# passing to ld. No need for --start-group/--end-group anymore. Should speed
# up the linking a bit. When the libraries contain actual circular dependecies
# the script will detect minimal groups of those and surround them with
# --start-group/--end-group.
#
# To run you need Linux (maybe OS X), Ruby 1.9+ and the rgl gem installed:
#
@detunized
detunized / rotate-aws-keys.rb
Last active August 29, 2015 14:06
Rotate AWS credentials
#!/usr/bin/env ruby
# This script rotates AWS credentials.
# It's very quick and dirty and unsafe.
# It's possible that something is gonna fail along the way and you're
# gonna end up with broken or no credentials at all. You can always fix
# them from the AWS dashboard later.
# The script expects ~/bin/aws-credentials to be present and executable.
# This file is overwritten with the new credentials at the end.
@detunized
detunized / hex-dump.js
Created September 1, 2016 08:44
Hex dump for Node
function printHexDump(s) {
const W = 16
let bytes = Buffer.from(s)
for (let i = 0; i < bytes.length;) {
let hexRow = []
let asciiRow = []
let rowOffset = i
@detunized
detunized / forkpool.cpp
Created September 22, 2016 15:53
Run a lambda in parallel processes
#include <functional>
#include <set>
#include <string>
#include <vector>
#include <iostream>
#include <unistd.h>
#include <sys/wait.h>
void
run_all( const std::vector< std::string >& source_files,
@detunized
detunized / make-posters.rb
Created November 23, 2016 20:49
Makes a series of A3 posters for cutting from a bunch of images
#!/usr/bin/env ruby
# This script makes a series of A3 posters for cutting from a bunch of images.
require "rational"
R_4_3 = Rational(4, 3)
R_3_4 = Rational(3, 4)
system "rm -rf out"