Skip to content

Instantly share code, notes, and snippets.

View yaauie's full-sized avatar

Ry Biesemeyer yaauie

View GitHub Profile
@yaauie
yaauie / hello.jscript.bat
Created May 6, 2011 21:52
A Polyglot for jscript in batch
0</* :hello
@ECHO Hello, batch!
@cscript /nologo /E:jscript %~f0 %*
@goto :EOF
*/0;
WScript.Echo('Hello, jscript!');
@yaauie
yaauie / gist:1072705
Created July 8, 2011 20:11
PFTT Task list
[-] Bootstrap
[X] Autoloading, etc.
[-] Logging functionality
[X] Log levels
[X] Linear/stream logs
[-] Template logs
[X] TypedArray class
[-] Common
@yaauie
yaauie / typed-arrays-in-ruby.rfc.markdown
Created August 2, 2011 13:07
Typed Arrays in Ruby RFC

Typed Arrays in Ruby RFC

NOTE: This RFC is closed; I went ahead and implemented. If you've got a problem with that, fork the project and make it better: https://github.com/yaauie/typed-array

tl;dr: Ruby does not have an Array class that enforces the type of its members; such a class can be useful, so I have created one. I would like help in determining the interface for it.

Abstract:

module NoisyRedis
module NoisyClient
def process(commands,&b)
r = super(commands,&b)
puts "#{Process.pid}>>#{self.class.name}\#process(#{commands.inspect}#{block_given? ? ' <&block>' : ''}) \#=> #{r.inspect}"
r
end
end
def self.extended(redis)

Given: this rspec file is in PROJECT_ROOT/spec

describe 'codebase' do
  let(:lines_with_more_than_80_characters) do
    Dir.glob( File.expand_path('../../lib/**/*.rb', __FILE__ ) ).map do |path|
      File.open( path ) do |file|
        idx = 0
        file.lines.map do |line|
          idx += 1
# Extend into a hash to provide sparse and unsparse methods.
#
# {'foo'=>{'bar'=>'bingo'}}.sparse #=> {'foo.bar'=>'bingo'}
# {'foo.bar'=>'bingo'}.unsparse => {'foo'=>{'bar'=>'bingo'}}
#
# options:
module Sparsify
def sparse(options={})
self.map do |k,v|
prefix = (options.fetch(:prefix,[])+[k])
require_relative 'range-split'
(1...1000).split(3) #=> [1...334, 334...667, 667...1000]
(1..1000).split(3) #=> [1...335, 335...669, 669..1000]
module FindTransformed
def find_transformed
self.each do |item|
result = yield(item)
return result if result
end
nil
end
end

RFC: Range#empty?

Often times it is useful to know whether a Range is empty without iterating over it or converting it to an array, especially with large (read: potentially infinite) ranges. This RFC is an attempt to find an efficient, always-correct, simple implementation of Range#empty?.

Current Best Implementation

module Range::IsEmpty
 def empty?
@yaauie
yaauie / jason-voorhees.rb
Last active June 29, 2017 16:34
JSON-decode recursively until it isn't JSON anymore.
# encoding: utf-8
require 'json'
# For when someone puts JSON in your JSON
# (because MurderingRampage™)
class JasonVoorhees
def self.load(*args)
self.new(JSON).load(*args)
end