Skip to content

Instantly share code, notes, and snippets.

@seawolf
seawolf / git-dedupe.rb
Created April 6, 2021 09:08
Dedupe a list of Git commits, from/to rebase-todo format, fixing-up duplicates into the first.
require 'fileutils'
FILE = '.git/rebase-merge/git-rebase-todo'
FILE_BACKUP = '.git/rebase-merge/git-rebase-todo.backup'
FILE_TEMPORARY = '.git/rebase-merge/git-rebase-todo.edited'
=begin
Dedupe a list of Git commits, from/to rebase-todo format, fixing-up duplicates into the first.
Turns this:
{
"swagger": "2.0",
"info": {
"title": "API V1",
"version": "v1"
},
"paths": {
"/api/v1/builds": {
"post": {
"summary": "Receives information on a new Build",
@seawolf
seawolf / list-join.js
Last active January 31, 2018 15:46
List Join
function joinListOfStrings(list = [], separator = ',', conjunction = 'and', oxfordComma = false) {
switch (list.length) {
case 0:
return '';
case 1:
return list[0];
case 2:
return list.join( (oxfordComma ? ', ' : ' ') + conjunction + ' ');
@seawolf
seawolf / callbacks.rb
Created May 8, 2017 11:04
Callbacks for all models & controllers in a Rails (5) app
# Not all classes will load when this starts, but we need them!
Rails.application.eager_load!
# Collect our classes so we don't have to loop through files
my_app = OpenStruct.new({
models: ActiveRecord::Base.descendants.sort_by(&:name),
controllers: ActionController::Base.descendants.sort_by(&:name)
})
# Models
@seawolf
seawolf / benchmark.rb
Created April 26, 2017 16:23
Hash Serialisation in Ruby between Marshal, JSON and YAML
my_hash = { symbol_key: 'string value', 'string key' => :symbol_value, 123 => 456, nil => true }
def do_this #&blk
last_result = nil
(1..10_000).map { |i| last_result = yield(i) }
last_result
end
def factor(this, compared_to_this, precision=2)
(this / compared_to_this).round(precision)
@seawolf
seawolf / download-certs.sh
Created September 17, 2013 08:09
I use DavMail to get KMail to pull e-mail down from the Exchange server at work, but they use certificates that change often (seems like when they reboot the server or something). This pull down the certificates from the servers (hits it multiple times as load-balanced servers may use different certificates), check to make sure they're different…
#!/bin/bash
#
# TODO: make the diff'ing capable of more than two possible certificates!
max_attempts=10
max=2 # how many possible certificates we need to fetch
fetched="" # all the numbers of the certificate filenames that we've successfully fetched (those that are different, so one per server)
keystore="/usr/lib/jvm/java-7-oracle/jre/lib/security/cacerts"
server="exchange-owa-server.mycompany.com"
>> 1, 2
SyntaxError: compile error
>> x = 1, y = 2
=> [1, 2]
>> x
=> [1, 2]
>> y
=> 2
@seawolf
seawolf / gnu-screen_to_tmux.md
Last active December 16, 2015 02:59
I'm moving from GNU Screen to tmux.

This is how I'm moving from GNU Screen to tmux, updated as I go. I run Arch Linux at home and on my servers, kUbuntu at work. My config. files are in my Dropbox (I'm moving over to ownCloud too, once I find a small CLI sync client) and symlinked, so I can have a consistent environment.

I don't consider myself a power user of the shell by any means, partly because I don't tend to concentrate on the shell itself too much and partly because it's less pain when I can't have it my way. I like my tools to be just enough to solve my problems.

Installation

As I did with Screen, I started with nothing and looked for a solution when I came across a problem. My first task was to start it without me having to do anything. I switched Konsole's default shell from Screen to tmux by copying ~/.kde4/apps/konsole/Screen.profile to ~/.kde4/apps/konsole/tmux.profile and changing the name and command lines in ~/.kde4/share/config/konsolerc.

I used to have screen -AdR,which would do a few things:

@seawolf
seawolf / android-compile.bash
Last active December 15, 2015 23:58
Building and Deploying an Android app from the Shell
#!/bin/bash
#
# android-compile.bash
# Cleans, compiles, installs and starts your Android project.
#
# Copyright (C) 2013 Ben Arnold
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
@seawolf
seawolf / unpack_directories.bash
Created October 22, 2012 18:31
Moves and renames files inside every subdirectory to the top-level, named sequentially after their original directory
#!/bin/bash
#
# unpack_directories.bash
# Moves and renames files inside every subdirectory to the top-level,
# named sequentially after their original directory
#
# Copyright (C) 2012 Ben Arnold
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by