Skip to content

Instantly share code, notes, and snippets.

View kbrock's full-sized avatar

Keenan Brock kbrock

View GitHub Profile
@pixeltrix
pixeltrix / time_vs_datatime.md
Last active February 18, 2024 19:20
When should you use DateTime and when should you use Time?

When should you use DateTime and when should you use Time?

It's a common misconception that [William Shakespeare][1] and [Miguel de Cervantes][2] died on the same day in history - so much so that UNESCO named April 23 as [World Book Day because of this fact][3]. However because England hadn't yet adopted [Gregorian Calendar Reform][4] (and wouldn't until [1752][5]) their deaths are actually 10 days apart. Since Ruby's Time class implements a [proleptic Gregorian calendar][6] and has no concept of calendar reform then there's no way to express this. This is where DateTime steps in:

>> shakespeare = DateTime.iso8601('1616-04-23', Date::ENGLAND)
=> Tue, 23 Apr 1616 00:00:00 +0000
>> cervantes = DateTime.iso8601('1616-04-23', Date::ITALY)
=> Sat, 23 Apr 1616 00:00:00 +0000
@jrafanie
jrafanie / a_summary.md
Last active August 29, 2015 14:20
Require timing logging with virtual memory logging

We were seeing 500+ MB of increased virtual memory usage compared to older versions of ManageIQ per process.

Using ManageIQ and require logging, we can measure how long and how much memory EACH require takes:

REQUIRE_LOG=true bin/rails r ""

This writes a log file in vmdb/log/require_DATEXYZ.log.

Note, require_with_logging is required in the preinitializer.rb

@havenwood
havenwood / hello.cr
Created April 17, 2015 00:09
"Hello, world!" from MRuby embedded in Crystal
@[Link("mruby")]
lib MRuby
type MRubyState = Void*
fun open = mrb_open : MRubyState
fun load_string = mrb_load_string(mrb : MRubyState, code : Pointer(UInt8))
fun close = mrb_close(mrb : MRubyState)
end
CODE = <<-RUBY_CODE
@mig-hub
mig-hub / chat.rb
Last active March 28, 2020 16:56 — forked from rkh/chat.rb
# coding: utf-8
require 'sinatra'
set server: 'thin', connections: []
get '/' do
halt erb(:login) unless params[:user]
erb :chat, locals: { user: params[:user].gsub(/\W/, '') }
end
get '/stream', provides: 'text/event-stream' do
@piscisaureus
piscisaureus / pr.md
Created August 13, 2012 16:12
Checkout github pull requests locally

Locate the section for your github remote in the .git/config file. It looks like this:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = git@github.com:joyent/node.git

Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to this section. Obviously, change the github url to match your project's URL. It ends up looking like this:

@evilpie
evilpie / disassembler.js
Created April 4, 2012 11:51
Disassembler for Notch's 'DCPU-16'
/* See: http://0x10c.com/doc/dcpu-16.txt */
function hex(n) {
return '0x' + n.toString(16);
}
function disassemble (code) {
var PC = 0;
var operand = function (bits) {
@krainboltgreene
krainboltgreene / forth.rb
Created January 15, 2012 18:45 — forked from perimosocordiae/forth.rb
A pure Ruby interpreter for Forth
#!/usr/bin/env ruby
# Return and remove the last value of the stack array
def pop
$stack.pop || raise(StackUnderflow)
end
# Add a expression to the stack
def push(expression)
$stack << expression
@fogus
fogus / forth.rb
Created August 30, 2011 18:40 — forked from perimosocordiae/forth.rb
A pure Ruby interpreter for Forth rr
#!/usr/bin/env ruby
# the stack
$stack = []
def pop() $stack.pop || ufe end
def push(f) $stack<<f end
# poor man's Exception class
def ufe() raise("Stack underflow") end
# lambda constructor helpers
@perimosocordiae
perimosocordiae / forth.rb
Created February 10, 2010 18:58
A pure Ruby interpreter for Forth
#!/usr/bin/env ruby
# the stack
$stack = []
def pop() $stack.pop || ufe end
def push(f) $stack<<f end
# poor man's Exception class
def ufe() raise("Stack underflow") end
# lambda constructor helpers