Skip to content

Instantly share code, notes, and snippets.

Avatar

Ry Biesemeyer yaauie

View GitHub Profile
@yaauie
yaauie / hello.jscript.bat
Created May 6, 2011
A Polyglot for jscript in batch
View hello.jscript.bat
0</* :hello
@ECHO Hello, batch!
@cscript /nologo /E:jscript %~f0 %*
@goto :EOF
*/0;
WScript.Echo('Hello, jscript!');
View gist:1072705
[-] Bootstrap
[X] Autoloading, etc.
[-] Logging functionality
[X] Log levels
[X] Linear/stream logs
[-] Template logs
[X] TypedArray class
[-] Common
View typed-arrays-in-ruby.rfc.markdown

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:

View noisy_redis.rb
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)
View gist:3298674

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
View sparsify.rb
# 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])
View range-split-usage.rb
require_relative 'range-split'
(1...1000).split(3) #=> [1...334, 334...667, 667...1000]
(1..1000).split(3) #=> [1...335, 335...669, 669..1000]
View find_transformed.rb
module FindTransformed
def find_transformed
self.each do |item|
result = yield(item)
return result if result
end
nil
end
end
View range-empty.rfc.md

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 Jun 29, 2017
JSON-decode recursively until it isn't JSON anymore.
View jason-voorhees.rb
# 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
You can’t perform that action at this time.