Skip to content

Instantly share code, notes, and snippets.

View sfcgeorge's full-sized avatar
🦔

Simon George sfcgeorge

🦔
View GitHub Profile
# Syntax sugar
class ArrayValidator < EnumValidator
end
@sfcgeorge
sfcgeorge / Gemfile
Created October 8, 2014 00:08
Blink(1) Minitest Reporter
group :test do
gem 'minitest-reporters'
gem 'rb-blink1'
end
@sfcgeorge
sfcgeorge / tail_call_optimization.rb
Last active August 29, 2015 14:18
MRI Ruby optional tail call optimization
# Comment the below compile_options out and
# this will crash with stack level too deep.
# Based on http://timelessrepo.com/tailin-ruby
RubyVM::InstructionSequence.compile_option = {
tailcall_optimization: true,
trace_instruction: false
}
RubyVM::InstructionSequence.new(<<-CODE).eval
@sfcgeorge
sfcgeorge / terminal_commands
Last active August 29, 2015 14:20
Compile Crystal code from external app
crystal run test.cr
#=> "foo"
crystal build test.cr
export CRYSTAL_PATH=/usr/local/Cellar/crystal/0.7.1/src
./test
#=>
ld: library not found for -levent
clang: error: linker command failed with exit code 1 (use -v to see invocation)
@sfcgeorge
sfcgeorge / buttons.java
Created June 2, 2015 14:25
Different ways to add an ActionListener to a JButton.
import java.awt.FlowLayout;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JButton;
import javax.swing.JFrame;
public class Buttons {
public static void main(String[] args) {
new JFrame("Different ways of creating JButtons") {{
@sfcgeorge
sfcgeorge / game_of_life.rb
Created August 8, 2015 22:13
Conway's Game of Life in Ruby, aiming to be short but readable
class String
def reverse_color; "\033[7m#{self}\033[27m" end
end
class Cell
attr_accessor :alive
def initialize(neighbors)
@neighbors = neighbors
@alive = @fate = [false, true].sample
@sfcgeorge
sfcgeorge / DynamicMethodCall.java
Last active February 12, 2017 20:29
Java class to call methods on objects/classes when given the method name as a String with actual parameters.
import java.lang.reflect.Method;
import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
/**
* We wrote DynamicMethodCall as a helper class to allow writing wrapper
* classes in Java by passing methods as data to call later.
* It allows you to call methods on an object where the method name is passed
* as a String. This is useful for simplifying anonymous method usage like GUI
* event handler, for example. It is capable of calling inherited methods,
@sfcgeorge
sfcgeorge / wcg_ascii.txt
Last active January 11, 2022 09:09
Classic river crossing problem with both Python and Ruby implementations and ASCII output.
_##_
(..)
/ ~ \
|| ||
m|||m
|||
n^n
_.
)''
@sfcgeorge
sfcgeorge / ackermann.py
Created September 18, 2015 17:32
Various simple AI search algorithms in Python from uni
# Classic Ackermann explosively exponential function
# some attempt at optimization though better optimizations are known
import sys
from sys import setrecursionlimit
sys.setrecursionlimit(50000)
depthM = 5
depthN = 1
answers = []
@sfcgeorge
sfcgeorge / packed-pixels-switchresx.md
Created December 9, 2015 16:13
Packed Pixels HiDPI Retina using SwitchResX

On OS X the Packed Pixels display won't automatically show up as "Retina" or "HiDPI" resolution, instead the OS will use the full resolution of the display making everything tiny. This can be changed using the 3rd party app (non-free) SwitchResX.

First, download SwitchResX.

You can play with the resolutions for the Packed Pixels which is probably listed as Color LCD (2). However not all of the HiDPI resolutions work due to an OS X bug. If you are happy with any of the ones that do work then stop here, else continue.

If you're on El Capitan or later you need to disable System Integrity Protection (temporarily) to add a custom resolution for Packed Pixels. Follow the instructions from SwitchResX creator.

Now add a Custom Resolution that is "scaled". It must be 2 pixels bigger or smaller than the native resolution in one direction (this is the OS X quirk). I found bigger makes it slightly blurry so go w