Skip to content

Instantly share code, notes, and snippets.

@detunized
detunized / ExampleCommand.py
Created October 23, 2017 22:46
Sublime Text 3 plugin to wrap long string literals in languages that support + for strings
import sublime
import sublime_plugin
# TODO: Rename this
# TODO: Configure the wrap column
# TODO: Add join and reformat
class ExampleCommand(sublime_plugin.TextCommand):
WRAP_COLUMN = 75
def run(self, edit):
@detunized
detunized / split-binary.rb
Created September 13, 2017 10:27
Split binary file on hex pattern
File.binread("filename.bin").split(/(?=\x15\x01)/).each_with_index do |data, i|
File.open("filename-%02d.bin" % i, "wb") do |io|
io.write data
end
end
@detunized
detunized / run.sh
Created September 4, 2017 11:02
Mount a read-only folder inside a Docker container with OverlayFS on top
# On the host to run the container
docker run --privileged -i -t -v ~/host-folder-to-mount:/root/folder-ro:ro ubuntu
# Inside the container
# Need to create the upper and work dirs inside a tmpfs.
# Otherwise OverlayFS complains about AUFS folders.
mkdir -p /tmp/overlay && \
mount -t tmpfs tmpfs /tmp/overlay && \
mkdir -p /tmp/overlay/{upper,work} && \
mkdir -p /root/folder && \
@detunized
detunized / zshrc
Created August 12, 2017 08:13
Zplug zshrc
# Aliases
alias ll='ls -lha'
# Zplug is managed by Homebrew
export ZPLUG_HOME=/usr/local/opt/zplug
source $ZPLUG_HOME/init.zsh
# Prezto
zplug "modules/environment", from:prezto
zplug "modules/completion", from:prezto
@detunized
detunized / map_to.cpp
Created May 15, 2017 08:07
Map a container to set and vector
template < typename Container, typename Function >
auto map_to_set( const Container& c, Function f ) -> std::set< decltype( f( *c.begin( ) ) ) >
{
std::set< decltype( f( *c.begin( ) ) ) > result;
for ( auto&& i : c )
result.insert( f( i ) );
return result;
}
@detunized
detunized / duplicate-line.lua
Created May 6, 2017 20:02
Duplicate line Far Manager editor macro
-- Copyright (C) 2017 Dmitry Yakimenko ([email protected]).
-- Licensed under the terms of the MIT license. See LICENCE for details.
-- Duplicate line Far Manager editor macro
Macro {
description = "Duplicate line";
area = "Editor";
key = "CtrlD";
action=function()
@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"
@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 / 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 / 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.