Skip to content

Instantly share code, notes, and snippets.

View kschiess's full-sized avatar
💭
see .plan

Kaspar Schiess kschiess

💭
see .plan
View GitHub Profile
#![deny(warnings)]
extern crate futures;
extern crate hyper;
extern crate pretty_env_logger;
extern crate serde_json;
use futures::{future, Future};
use hyper::{Body, Client, Request, Response, Server};
use hyper::client::HttpConnector;
@kschiess
kschiess / keybase.md
Created September 23, 2014 07:17
Keybase authentication.

Keybase proof

I hereby claim:

  • I am kschiess on github.
  • I am kschiess (https://keybase.io/kschiess) on keybase.
  • I have a public key whose fingerprint is 410C D966 C2FE D140 1ADA 77E9 8C67 10A3 D7A0 791E

To claim this, I am signing this object:

$:.unshift 'PATHTOINTERNALSCODE'
require 'string_internals.bundle'
def scan_for title, s, indent=0
GC.start
times = 0
content = ''
ObjectSpace.each_object(String) do |str|
if str == s
times += 1
@kschiess
kschiess / gist:6218466
Last active December 21, 2015 00:09
Non-obvious string interpolation tidbit.
class Foo
def to_s
1
end
# Just to make sure ;)
def inspect
'a foo'
end
end
@kschiess
kschiess / transactions_spec.rb
Last active December 18, 2015 23:59
Taking the transaction behaviour discussion into code. Use 'rspec transactions_spec.rb'
require 'rspec'
require 'dm-transactions'
RSpec.configure do |rspec|
rspec.mock_with :flexmock
end
describe 'transaction block behaviour' do
let(:t) { DataMapper::Transaction.new() }
diff --git a/lib/rip/compiler/parser.rb b/lib/rip/compiler/parser.rb
index eb60b43..2416e3d 100644
--- a/lib/rip/compiler/parser.rb
+++ b/lib/rip/compiler/parser.rb
@@ -261,11 +261,13 @@ module Rip::Compiler
rule(:heredoc_start) { angled_open.repeat(2, 2) >> heredoc_label >> line_break }
rule(:heredoc_label) { match['A-Z_'].repeat(1).capture(:heredoc_label) }
- rule(:heredoc_content) { (heredoc_end.absent? >> heredoc_content_any >> (line_break.absent? >> heredoc_content_any).repeat >> heredoc_content_any).repeat(1) }
+ # rule(:heredoc_content) { (heredoc_end.absent? >> heredoc_content_any >> (line_break.absent? >> heredoc_content_any).repeat >> heredoc_content_any).repeat(1) }
require 'strscan'
# Inspired by
# http://eli.thegreenplace.net/2012/08/02/parsing-expressions-by-precedence-climbing/
# A succinct implementation of precedence climbing in Ruby
operations = {}
%w(+ -).each { |c| operations[c] = [:left, 1] }
@kschiess
kschiess / respond_to_missing?
Created November 27, 2012 10:29
Exploring the meaning of Ruby 1.9 respond_to_missing?
class Foo
def respond_to?(sym)
if sym == :foo
return true
else
super
end
end
end
class Bar
# Encoding: UTF-8
require 'fiber'
HEADER = 0x61
FOOTER = 0x62
DLE = 0xAB
def after_dle(x)
x
@kschiess
kschiess / element_parser.rb
Created May 29, 2012 05:34
Parses a tokenized stream of elements.
require 'parslet'
include Parslet
input = %w(a aa b)
class El < Parslet::Atoms::Base
def initialize(pattern)
@pattern = pattern
super()
end