Skip to content

Instantly share code, notes, and snippets.

View espen's full-sized avatar

Espen Antonsen espen

View GitHub Profile
@mikz
mikz / gist:574015
Created September 10, 2010 17:14
def quoted_date(value)
if value.acts_like?(:time) && value.respond_to?(:usec)
begin
"#{value.getutc.to_s(:db)}.#{sprintf("%06d", value.usec)} #{value.formatted_offset}"
rescue
"#{super}.#{sprintf("%06d", value.usec)}"
end
else
super
@rkh
rkh / gist:4644647
Last active December 11, 2015 18:49

The Hunt for the right HTTP library

Use case: Travis CLI. One command invokes one or more sequential HTTP requests.

Note that startup time and the first request are very significant for a command line tool like this.

Clone the repo if you want to follow along.

Note: numbers might be due to how libraries are used (via faraday)

@larsw
larsw / lamkarri.md
Last active December 12, 2015 02:58
Wasims #lamkarri

Wasims (@WasimZahid) #lamkarri

Jeg skal nå dele verdens enkleste måte å lage en nydelig pakistansk lammegryte på, helt fra scratch.

  1. Ha 1kg lammekjøtt i biter (gjerne rett fra fryseren) i en middels stor gryte.

  2. Skjær en løk, litt fersk ingefær og hvitløk i fine biter.

@robmiller
robmiller / strtotime.rb
Last active December 24, 2015 21:49
Sometimes I want to do natural language datetime calculations from the commandline, just to work out things like "what date will it be in 60 days" or "when was 30 days ago". This helps.
#!/usr/bin/env ruby
# Requirements: Ruby and the Chronic gem
#
# Install Chronic with: `gem install chronic`
#
# Examples:
#
# $ strtotime 'in 60 days'
# 6 Dec 2013 14:55:44
@benhoskings
benhoskings / ruby-2-cert-issue-fix.sh
Last active March 21, 2016 18:30
Ruby 2.0 CA cert issue fix
# If you're having cert issues on ruby 2.0.0-p0, the issue is most likely that ruby can't
# find the required intermediate certificates. If you built it via rbenv/ruby-build, then
# the certs are already on your system, just not where ruby expects them to be.
# When ruby-build installs openssl, it installs the CA certs here:
~/.rbenv/versions/2.0.0-p0/openssl/ssl/cacert.pem
# Ruby is expecting them here:
$(ruby -ropenssl -e 'puts OpenSSL::X509::DEFAULT_CERT_FILE')
# Which for me, is this path:
@alloy
alloy / Rakefile
Last active March 23, 2016 10:36
A Rakefile that standardises program env installation and guides the user, as opposed to crashing with Ruby exceptions such as `LoadError`. The only case where this will *never* work reliably is if you use the `rubygems-bundler` (NOEXEC) plugin, which introduces chicken-and-egg problems.
# Do *not* load any libs here that are *not* part of Ruby’s standard-lib. Ever.
desc "Install all dependencies"
task :bootstrap do
if system('which bundle')
sh "bundle install"
sh "git submodule update --init"
# etc
else
$stderr.puts "\033[0;31m[!] Please install the bundler gem manually: $ [sudo] gem install bundler\e[0m"

Proposal for a date system overhaul

The Problem

FullCalendar was initially designed without much notion of timezones. By default, it ignores timezone offsets in the dates it receives.

The original assumption was that if you received a date from Brussels, say "2013-09-01T12:00:00+02:00", which is noon, it would display as noon in every timezone.

However, FullCalendar shoehorns this value into a local date. With the same example, if you were in San Francisco, it internally stores the date as "2013-09-01T12:00:00-08:00". This is bad for two reasons:

@aslakhellesoy
aslakhellesoy / gfm.sh
Last active November 23, 2016 09:57
Compile and show GFM docs in your browser.https://help.github.com/articles/github-flavored-markdown
#!/bin/sh
# Compile and show [GFM](https://help.github.com/articles/github-flavored-markdown) docs in your browser.
# Before this works you need to `gem install bcat`
#
# Usage: gfm.sh FILE.md
#
curl --silent --data-binary @- https://api.github.com/markdown/raw -H "Content-Type: text/plain" | bcat
@vagmi
vagmi / pg_application_name_patch.rb
Created May 11, 2012 06:13
Set the application name for a postgres connection in Rails 3
module ActiveRecord
module ApplicationName
def self.included(base)
unless base.respond_to? :establish_connection_with_application_name
base.extend ClassMethods
base.class_eval do
class << self
alias_method_chain :establish_connection, :application_name
end
end
@madwork
madwork / decode_session_cookie.rb
Last active October 22, 2020 18:13 — forked from profh/decode_session_cookie.rb
Rails 4.1+ Decode Session