Skip to content

Instantly share code, notes, and snippets.

View Overbryd's full-sized avatar

Lukas Rieder Overbryd

View GitHub Profile
# Create Partition Table
echo "Create Partition Table"
gpart create -s gpt mfid0
gpart create -s gpt mfid1
# Create Boot Partition
echo "Create Boot Partition"
gpart add -a 4k -s 64k -t freebsd-boot mfid0
gpart add -a 4k -s 64k -t freebsd-boot mfid1
require "benchmark"
require "bigdecimal"
require "bigdecimal/util"
Benchmark.bm do |x|
class Foo
VALUE = BigDecimal("1.2")
def to_d
VALUE
@Overbryd
Overbryd / json_store.rb
Last active August 29, 2015 14:05
JSON PStore support
require "pstore"
require "json"
class JSON::Store < PStore
def dump(table)
# use JSON.pretty_generate(table) to make it even more human readable
JSON.generate(table)
end
@Overbryd
Overbryd / result_macmini6,2_i7_2,6GHz.txt
Last active August 29, 2015 14:07
Cost of having timezone related code
Calculating -------------------------------------
rails 688 i/100ms
rails_default 1496 i/100ms
manual 1875 i/100ms
-------------------------------------------------
rails 7165.7 (±1.0%) i/s - 72240 in 10.082247s
rails_default 16039.7 (±1.0%) i/s - 161568 in 10.074064s
manual 20281.0 (±1.7%) i/s - 204375 in 10.080226s
Comparison:

Offers for Android

Receive an offer tailored for the user from the backend.

POST http://backend_url/android_offers/generate
{ user_id: 2112 }

200 OK
{

Select query problem

CREATE TABLE `testA` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `fbuserid` bigint(20) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `fbuserid_idx` (`fbuserid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

SELECT * FROM testA WHERE fbuserid = '123';

POST /events

  • responds with all active and open events
  • active events have a remaining key with the remaining time in seconds
  • open events have no remaining
POST /events
user_id=2112
@Overbryd
Overbryd / ruby.md
Last active August 29, 2015 14:20
Code styleguide

Code Styleguide

In order to make pairing very efficient I always found a code styleguide very helpful to minimize discussions around code style.

The goal is to keep code highly readable under any circumstances. Contributing and adhering to this styleguide will help improve overall code readability.

A good reference to set discussions around unwritten rules: https://github.com/bbatsov/ruby-style-guide

Source files, Intendation

Order Request:

POST /orders HTTP/1.1
Host: api.point101.com 
Content-Type: application/json
X-App-ID: simplybuy.it
X-App-Token: deadbeef123
X-HMAC: abc1234567890
@Overbryd
Overbryd / pathToNode.js
Created May 26, 2015 16:33
pretty awesome function to get a path to any given element
// pretty awesome function to get a path to any given element
function pathToNode(node) {
if (node.id.length > 0) { return "#" + node.id; }
var path = [];
var parents = $(node).parents().toArray().reverse();
var deferred = $.Deferred();
var self = this;
function qualifiers(node) {
if (node.id.length > 0) {
return "#" + node.id;