Skip to content

Instantly share code, notes, and snippets.

class Hash
def to_proc
method(:[]).to_proc
end
def dig(*keys)
result = fetch(keys.shift, nil)
if result.is_a?(Hash) && keys.any?
result.dig *keys
@glucero
glucero / array.rb
Created March 4, 2015 13:53
Array#^
class Array
def ^(operand)
(self | operand) - (self & operand)
end
end
diff --git a/server.c b/server.c
index db172e3..a16e2eb 100644
--- a/server.c
+++ b/server.c
@@ -4,6 +4,7 @@
#include <string.h>
#include <syslog.h>
#include <sys/time.h>
+#include <time.h>
#include <unistd.h>
@glucero
glucero / process_status.bat
Last active August 29, 2015 14:05
monitor process status with command output template
@ECHO OFF
SETLOCAL EnableExtensions
SET PROCESS=%~nx1
SET NAME=%~n1
FOR /F %%x IN ('tasklist /NH /FI "IMAGENAME eq %PROCESS%"') DO IF %%x == %PROCESS% GOTO FOUND
ECHO OS^|Windows^|Process^|%NAME%^|Status 0 2 %NAME% (%PROCESS%) is not running.
GOTO EOF
:FOUND
ECHO OS^|Windows^|Process^|%NAME%^|Status 1 0 %NAME% (%PROCESS%) is running.
:EOF
require 'optparse'
user_input = {}
OptionParser.new do |opts|
opts.banner = "RFE #{RFE::VERSION}"
opts.separator ""
opts.separator "Available Options:"
opts.on("-h", "--help", "help") do |some_option|
puts opts
end
@glucero
glucero / field.rb
Last active August 29, 2015 13:56
a helper class for experimenting with bit fields
class Field
Bit = Struct.new(:to_s, :to_i, :to_bool, :regex) do
alias to_str to_s
def ===(other) entries.any? { |entry| entry === other } end
end
False = Bit.new(?0, 0, false, /^[0nf]/i)
True = Bit.new(?1, 1, true, /^[1yt]/i)
@glucero
glucero / disapproval.js
Created October 30, 2013 04:52
javascript of disapproval
String.fromCharCode(this._=Math.pow(!0x0+!0<<0|0>>0,this._0=-~-~-~-~-~-0)*((+!0+'00')-~0),+!0+'00'-_0,_);
@glucero
glucero / srzf.rb
Last active December 23, 2015 15:39
where's the '>>>' operator, matz?!
class ShiftRightZeroFill
def >(operand)
(@value & 0xFFFFFFFF) >> operand
end
def initialize(value)
@value = value
end
end
@glucero
glucero / ruby_archive.rb
Last active December 20, 2015 17:09
self extracting ruby archiver
#!/usr/bin/env ruby
class RubyArchive
require 'rubygems/package'
require 'zlib'
attr_reader :path
class Archive
@glucero
glucero / chutes_and_ladders.rb
Last active December 20, 2015 05:59
chutes and ladders turn count analysis
module ChutesAndLadders
class Game
# chutes ladders
Board = {16 => 6, 1 => 23,
48 => 26, 4 => 14,
49 => 11, 9 => 31,
56 => 53, 21 => 42,
62 => 19, 28 => 84,