Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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 / 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 / join-onpama-repos.sh
Created December 26, 2017 15:06
Join a bunch of repos into subfolders and rewrite the history to reflect where the commits are coming from
#!/bin/bash
set -e
# Clone repos locally into original/
(
mkdir original
cd original
git clone [email protected]:detunized/lastpass-sharp.git
@detunized
detunized / leetcode-91-decode-ways.rb
Created January 7, 2018 18:34
LeetCode problem #91: Decode ways
# @param {String} s
# @return {Integer}
def num_decodings(s)
return 0 if s.empty?
n1 = 1
n2 = 0
i = 0
while i < s.size
@detunized
detunized / find-lib.rb
Created January 18, 2018 10:17
Find which library (.a or .so) exports a symbol
#!/usr/bin/env ruby
begin
require "parallel"
PARALLEL = true
rescue LoadError
PARALLEL = false
end
def each collection, &block
@detunized
detunized / t2b.rb
Last active June 13, 2018 08:34
Naive t2b (https://github.com/thosakwe/t2b) implementation proof of concept
#!/usr/bin/env ruby
#
# DSL implementation
#
$stack = [""]
def emit x
$stack.last << x