Skip to content

Instantly share code, notes, and snippets.

@camertron
camertron / build_cldr.sh
Created July 19, 2024 15:12
Build CLDR from source
#! /bin/bash
export ANT_HOME=~/Downloads/apache-ant-1.9.16
export PATH=$JAVA_HOME/bin:$ANT_HOME/bin:$PATH
export ANT_OPTS="-Xmx4096m"
export CLDR_DIR=~/workspace/unicode-org/cldr
export ICU4C_DIR=~/workspace/unicode-org/icu/icu4c
export ICU4J_ROOT=~/workspace/unicode-org/icu/icu4j
export TOOLS_ROOT=~/workspace/unicode-org/icu/tools
export CLDR_TMP_DIR=$CLDR_DIR/../cldr-staging
@camertron
camertron / build_ruby_ios.sh
Created July 19, 2024 15:05
Build Ruby for iOS
#!/bin/bash
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 \
--build=x86_64-apple-darwin20 \
--target=aarch64-apple-darwin20 \
const fs = require('fs')
const { createAppAuth } = require('@octokit/auth-app')
async function main() {
const auth = createAppAuth({
appId: 905201,
privateKey: fs.readFileSync('/path/to/private-key.pem', 'utf8')
});
const appAuth = await auth({
@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):