Skip to content

Instantly share code, notes, and snippets.

@camertron
camertron / interactive_branch_cleaner.rb
Created April 20, 2023 18:32
Interactive branch cleaner
# frozen_string_literal: true
branches = `git branch`.strip.split("\n").map(&:strip).reject { |b| b.start_with?("*") }
branches.each_with_index do |branch, idx|
STDOUT.write("[#{idx + 1}/#{branches.size}] Delete '#{branch}' (y/n)? ")
answer = gets
if answer.strip =~ /[yY]/
system("git branch -D #{branch}")
@camertron
camertron / bench.rb
Last active August 15, 2022 20:46
Speeding up ActionView::OutputBuffer (Vitesse)
# frozen_string_literal: true
require "benchmark/ips"
require "allocation_stats"
require "/Users/camertron/workspace/camertron/vitesse/ext/vitesse/vitesse"
TIMES = 100
actionview_trace = AllocationStats.trace do
output_buffer = ActionView::OutputBuffer.new
@camertron
camertron / gifify.sh
Created June 17, 2022 22:29
Easily create a gif
#!/bin/bash
# Usage: gifify.sh <input file> <output file>
ffmpeg -i $1 -vf "fps=10,scale=320:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" $2
@camertron
camertron / top_dirs_by_size.rb
Created November 14, 2021 22:22
Lists top directories by file size
#! /usr/bin/env ruby
require 'shellwords'
$cache = {}
def file_sizes_in(path)
$cache[path] ||= begin
raw = `du -d 1 2>/dev/null #{Shellwords.shellescape(path)}`
# exclude current dir
@camertron
camertron / build_ruby_for_ios.sh
Created September 18, 2021 20:04
Compile ruby for iPhone SDK
#!/bin/bash
# First, install Xcode and accompanying command-line tools
wget https://cache.ruby-lang.org/pub/ruby/3.0/ruby-3.0.2.tar.gz
tar -zxvf ruby-3.0.2.tar.gz
cd ruby-3.0.2
./configure --prefix=/tmp \
Single-threaded
┌───────┬─────────────────────┬──────────┬────────────────────────────────────────────┬────────┬───────────┬─────────┬───────────┬──────────┬──────┬───────────────┐
│ Index │ Implementation │ Solution │ Label │ Passes │ Duration │ Threads │ Algorithm │ Faithful │ Bits │ Passes/Second │
├───────┼─────────────────────┼──────────┼────────────────────────────────────────────┼────────┼───────────┼─────────┼───────────┼──────────┼──────┼───────────────┤
│ 1 │ PrimeCPP │ 3 │ flo80_constexpr │ 37737 │ 5.00010 │ 1 │ base │ no │ 1 │ 7547.25207 │
│ 2 │ PrimeCython │ 1 │ ssovest-cy │ 20838 │ 5.00015 │ 1 │ other │ yes │ 1 │ 4167.47164 │
│ 3 │ PrimeC │ 2 │ danielspaangberg_5760of30030_owrb │ 20255 │ 5.00021 │
@camertron
camertron / enumerable.py
Created July 21, 2020 17:09
Python implementation of Ruby's enumerable module
import unittest
def enum(obj):
if type(obj) == list:
return EnumList(obj)
elif type(obj) == dict:
return EnumDict(obj)
class Enumerable(object):
def each(self, cb):
@camertron
camertron / git-extract.py
Last active July 10, 2020 22:49
Quick-and-dirty script to move lines from one source file to a new source file, preserving git authorship along the way. The new file will be made up of a number of commits, each one attributed to the original author and at the original date and time.
import argparse
from datetime import (datetime, timedelta)
import os
import re
import subprocess
class Commit(object):
def __init__(self, commit_id, fields):
self.commit_id = commit_id
-- Crash Report log information --------------------------------------------
See Crash Report log file under the one of following:
* ~/Library/Logs/DiagnosticReports
* /Library/Logs/DiagnosticReports
for more details.
Don't forget to include the above Crash Report log file in bug reports.
-- Control frame information -----------------------------------------------
c:0001 p:0000 s:0003 E:001120 (none) [FINISH]
@camertron
camertron / NullObjectListTerminator.java
Last active September 2, 2019 22:17
Using a null object as a list terminator
interface INode<T> {
boolean hasNext();
Node<T> getNext();
T getValue();
}
class Node<T> implements INode<T> {
private T value;
private INode<T> next;