Skip to content

Instantly share code, notes, and snippets.

### Keybase proof
I hereby claim:
* I am ferrous26 on github.
* I am ferrous26 (https://keybase.io/ferrous26) on keybase.
* I have a public key whose fingerprint is 1D34 82B6 1EB5 286D 8D61 E84C 1EE8 F634 208C EB3B
To claim this, I am signing this object:
@ferrous26
ferrous26 / test.java
Last active August 29, 2015 13:57
Java silliness
public class test {
public test() {
int[] a = new int['☃'];
a[1] = a[0];
}
}
@ferrous26
ferrous26 / float.rb
Last active January 3, 2016 15:49
A regular expression for validating floating point numbers
DIGITS = '(\d+)'
EXPONENT = "([eE][+-]?#{DIGITS})"
SUFFIX = '(f|F|d|D)'
PATTERN = Regexp.union [
"#{DIGITS}\\.#{DIGITS}?#{EXPONENT}?#{SUFFIX}?",
"\\.#{DIGITS}#{EXPONENT}?#{SUFFIX}?",
"#{DIGITS}#{EXPONENT}#{SUFFIX}?",
"#{DIGITS}#{EXPONENT}?#{SUFFIX}"
].map { |str| Regexp.new "\\A#{str}\\Z" }
@ferrous26
ferrous26 / ferrous26.pem
Created December 20, 2013 09:04
My Rubygems certificate
-----BEGIN CERTIFICATE-----
MIIDeDCCAmCgAwIBAgIBATANBgkqhkiG9w0BAQUFADBBMRMwEQYDVQQDDAptYXJr
cmFkYTI2MRUwEwYKCZImiZPyLGQBGRYFZ21haWwxEzARBgoJkiaJk/IsZAEZFgNj
b20wHhcNMTMxMjIwMDkwMjQ4WhcNMTQxMjIwMDkwMjQ4WjBBMRMwEQYDVQQDDApt
YXJrcmFkYTI2MRUwEwYKCZImiZPyLGQBGRYFZ21haWwxEzARBgoJkiaJk/IsZAEZ
FgNjb20wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCumG1cuUOFpjYl
ktWNO8nA1FROqLnpC6GkT1CIBOG3VgXjh5vl3uAbvg6FaSU2jA0W91i6QhSaP1Ik
ReX3o6wBUnK15pN/wBULZY772WEg0Nb5wyrzSlS3dv8Jg6aGuw1bridSO0HSARvG
oQC++a1Ks64uy++OPwglaGBOcalNxwF1TUcYzi0K3a679+/8+kwaJt0pVtbT81RW
2oHli/SGB4oFu3uYnMoKk0yczfiSBdG7oSWBAcSEPsFRsUGn3vUdwCIlVXtKmmfW
@ferrous26
ferrous26 / bf.rb
Last active December 11, 2015 07:38
Brainfuck interpreter in Ruby
#!/usr/bin/env ruby
mem = Array.new(30_000)
iptr = dptr = 0
prog = File.read ARGV.first
jmp = lambda { |op, a, b|
(iptr = iptr.send(op, 1); jmp.call(op, a, b) if prog[iptr] == a) until prog[iptr] == b
}
nop = lambda {}
cmds = {
'>' => lambda { dptr += 1 },
finder = AX::Application.finder
dock = AX::Application.dock
click dock.application_dock_item(title:"Finder")
sleep 2
type "\\SHIFT+\\COMMAND+\\G"
type "~"
click finder.window.button(id: "_NS:48")
click finder.window.radio_button(description: "icon view")
right_click finder.window.image(title: "Applications") do
findermenu = finder.standard_window.menu
@ferrous26
ferrous26 / time.c.diff
Last active December 10, 2015 13:29
MacRuby/MacRuby GH-174
diff --git a/time.c b/time.c
index 332aad9..730d0e5 100644
--- a/time.c
+++ b/time.c
@@ -10,6 +10,7 @@
#include "macruby_internal.h"
#include "ruby/node.h"
+#include "id.h"
#include "vm.h"
@ferrous26
ferrous26 / bug.rb
Created December 27, 2012 01:59
Varargs in MacRuby and MRI
def foo *args
arg = args.last
if arg.zero?
args
else
foo(args << arg - 1)
end
end
p foo 3
@ferrous26
ferrous26 / pipeline.rb
Created November 22, 2012 17:11
Trying to generalize the pipeline data flow
require 'thread'
##
# A basic, serial data flow
#
# If you have a long process for a data set, consider performing steps
# of the process concurrently. Even simply reading a file and writing it
# back out elsewhere (i.e. a socket) can have increased throughput by
# using a pipeline.
#
@ferrous26
ferrous26 / screen_recorder.rb
Created October 28, 2012 04:05
A simple screen recorder
framework 'AVFoundation'
MOUNTAIN_LION_APPKIT_VERSION = 1187
if NSAppKitVersionNumber >= MOUNTAIN_LION_APPKIT_VERSION
framework '/System/Library/Frameworks/CoreGraphics.framework'
end
##
# Screen recordings, easy as pie.