Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / output.txt
Created July 2, 2012 16:11
List all subsets of a given set
[[], [1], [2], [1, 2], [3], [1, 3], [2, 3], [1, 2, 3], [4], [1, 4], [2, 4], [1, 2, 4], [3, 4], [1, 3, 4], [2, 3, 4], [1, 2, 3, 4]]
@detunized
detunized / main.m
Created October 15, 2012 08:42
Redirect stderr into a pipe, filter and then write to stdout (for NSLog filtering)
int main(int argc, char *argv[])
{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^(void) {
size_t const BUFFER_SIZE = 2048;
// Create a pipe
int pipe_in_out[2];
if (pipe(pipe_in_out) == -1)
return;
@detunized
detunized / suspend-on-power-button.sh
Created October 19, 2012 09:28
Make Gnome Shell suspend on hardware power button without asking questions
gsettings set org.gnome.settings-daemon.plugins.power button-power suspend
// A solution for http://www.geeksforgeeks.org/archives/25739
//
// Given two numbers represented by two linked lists, write a function that
// returns sum list. The sum list is linked list representation of addition of
// two input numbers. It is not allowed to modify the lists. Also, not allowed
// to use explicit extra space (Hint: Use Recursion).
//
// Example:
//
// Input:
@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)
{}
@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