Skip to content

Instantly share code, notes, and snippets.

@mjc
mjc / Gemfile
Last active August 29, 2015 14:23
Class vs Struct vs OpenStruct
source 'https://rubygems.org'
gem 'benchmark-ips'
gem 'ruby-progressbar'
@mjc
mjc / primalitytest6.rb
Last active August 29, 2015 14:27 — forked from jzakiya/primalitytest6.rb
primalitytest6.rb
#!/usr/local/bin/ruby -w
require 'rational' if RUBY_VERSION =~ /^(1.8)/ # for 'gcd' method
class Integer
def primz?
residues = [1,7,11,13,17,19,23,29,31,37,41,43,47,49,53,59,61]
res1 = [1,13,17,29,37,41,49,53]
res2 = [7,19,31,43]
@mjc
mjc / bench.rb
Created November 20, 2015 22:06 — forked from jurre/bench.rb
roar vs ams
require "bundler"
require "active_model_serializers"
require "roar"
require "roar/json/json_api"
require "benchmark"
require "ffaker"
Post = Struct.new(:id, :author, :body, :draft) do
include ActiveModel::Serializers::JSON
end

Keybase proof

I hereby claim:

  • I am mjc on github.
  • I am projct (https://keybase.io/projct) on keybase.
  • I have a public key ASD4cqm9IEAT8sbSVfLXVPJNRFi66uua7_7BHZEToAf9WAo

To claim this, I am signing this object:

@mjc
mjc / fizz_buzz_test.exs
Last active July 13, 2019 14:53
test for fizzbuzz
defmodule FizzBuzzTest do
use ExUnit.Case
# to run tests: mix test
# to get an irb equivalent with your code loaded in it: iex -S mix
# to get a pry in your code: `require IEx;IEx.pry()`
# Phase 1: make the test pass.
# Phase 2: implement the fizz/buzz check as a pattern match
# Phase 3: move the pattern match into multiple function clauses.
@mjc
mjc / optimizeimages.sh
Last active October 21, 2019 22:06 — forked from mstroeck/optimizeimages.sh
Shell script to recursively optimize all image in the current directory. WARNING: THIS OVERWRITES YOUR ORIGINALS AND REMOVES METADATA!
#!/bin/sh
set -o errexit
# @TODO detect fd and fallback to find
pngs=$(fd -e png .)
jpgs=$(fd -e jpg .)
#pngs=$(find . -iname "*.png")
#jpgs=$(find . -iname "*.jpg")
optimize_a_png() {
@mjc
mjc / gist:37996785f47f565eb431dca19b56cf84
Created March 29, 2022 22:04
M1 macs: Preserving HDR, convert all mkv in a folder to 1080P using HandBrakeCLI. Uses VideoToolbox for hardware encoding.
#!/usr/bin/env bash
read -r -d '' profile <<'EOF'
{
"PresetList" : [
{
"AlignAVStart" : true,
"AudioCopyMask" : [
"copy:aac",
"copy:ac3",