Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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.
Map without reserve
size: 0
bucket_count: 23
load_factor: 0
Allocation count: 0
size: 0
bucket_count: 23
@detunized
detunized / embed-subtitles.sh
Created August 30, 2013 09:12
Embed subtitles into an .mp4 file
#!/bin/sh
ffmpeg -i input.mkv -c:v copy -c:a copy temporary-no-subtitles.mp4
mp4box temporary-no-subtitles.mp4 -add subtitles-in-utf8.srt -out output.mp4
@detunized
detunized / check_hash_less.cpp
Last active December 11, 2015 06:08
Operator < detection
#include <iostream>
#include <string>
#include <boost/type_traits/has_less.hpp>
#define HAS_LESS(type) (boost::has_less<type>::value \
? #type ": has less" \
: #type ": doesn't have less")
#define CHECK(type) (std::cout << HAS_LESS(type) << "\n")
@detunized
detunized / labyrinth.rb
Created December 19, 2012 16:18
Find path in a labyrinth
#!/usr/bin/env ruby
class Coord
attr_reader :x, :y
def initialize x, y
@x = x
@y = y
end
@detunized
detunized / dijkstra.cpp
Created November 7, 2012 22:55
Simple Dijkstra's algorithm implementation
#include <vector>
#include <limits>
#include <iostream>
struct Edge
{
Edge(size_t to, int cost)
: to(to - 1)
, cost(cost)
{}