Skip to content

Instantly share code, notes, and snippets.

@zdennis
zdennis / keybase.md
Created July 11, 2014 20:22
keybase.md

Keybase proof

I hereby claim:

  • I am zdennis on github.
  • I am zdennis (https://keybase.io/zdennis) on keybase.
  • I have a public key whose fingerprint is DF8D 39D9 9993 DFFD 7801 5D9D 3F59 51D7 5DAE D169

To claim this, I am signing this object:

1) Grape::DSL::Validations.reset_validations! resets validations
Failure/Error: expect(subject.settings.peek[:validations]).to be_empty
expected to respond to `empty?`
# ./spec/grape/dsl/validations_spec.rb:30:in `block (3 levels) in <module:DSL>'
2) Grape::Validations::PresenceValidator with a required non-empty string requires when missing
Failure/Error: expect(last_response.body).to eq('{"error":"email is missing, email is invalid"}')
expected: "{\"error\":\"email is missing, email is invalid\"}"
got: "{\"error\":\"email is missing\"}"
@zdennis
zdennis / hal-snippet.js
Last active August 29, 2015 14:06
HAL curies for docs, separating curie URL templates from link relation descriptions. The differences below are due to the way that WebLinking RFC 5988 has specified that non-registered relations must be URLs
"_links": {
"curies": [
{
"name": "doc",
"href": "http://haltalk.herokuapp.com/docs/{rel}",
"templated": true
}
],
// this is the "latest-posts" link relation. The base documentation URL can change
@zdennis
zdennis / gitconfig.sh
Last active August 29, 2015 14:07
gitconfig aliases
# +cbranch+ returns the current branch you are on
cbranch = !"git branch | grep '*' | cut -f2 -d' '"
# +open-url+ opens the home page for this repository
open-url = !"open `git remote show origin | grep 'Fetch URL' | ruby -e \"puts 'http://' + STDIN.read.scan(/Fetch URL: git@(.*)/).join.sub(':', '/').sub('.git','')\"`"
# +open-branch+ opens the current branch in your default browser
open-branch = !"open `git remote show origin | grep 'Fetch URL' | ruby -e \"puts 'http://' + STDIN.read.scan(/Fetch URL: git@(.*)/).join.sub(':', '/').sub('.git','') + \\\\\"/tree/#{%x|git cbranch|}\\\\\"\"`"
# +open-sha+ opens the current SHA in your default browser
# simple character binding
#"z":"echo hello world"
# controler character binding
#"\C-g":"echo goodbye world"
# function key binding
# "\033OP":"echo f1"
# "\eOQ":"echo f2"
@zdennis
zdennis / example.rb
Created February 14, 2015 18:08
Ruby Process.spawn with pipes
100.times do
r,w = IO.pipe
pid1 = Process.spawn(Hash.new, "echo", "foo\nbar\nbaz\nfood", out: w)
pid2 = Process.spawn(Hash.new, "grep", "foo", in: r)
foo = Process.waitpid2(pid1)
# don't forget to close the write pipe, otherwise this will hang on the second process indefinitely
w.close
bar = Process.waitpid2(pid2)
class Surveys::ReportController < ApplicationController
def show
Survey.find()
end
end
@zdennis
zdennis / readme.md
Last active August 29, 2015 14:16
Annoying REPL SIGSTOP Issue
  • Make sure you are running the bash shell.
  • Run repl.rb which will echo what you print unless you enter "irb".
  • Type "irb" to launch a new irb process.
  • Hit Ctrl-Z to send SIGTSTP to stop the irb process.
  • You'll be brought back to the main repl.
  • Type "foo", hit enter. You'll be echoed "oo".
  • Type "foo" again, hit enter. You'll see "foo".
  • Now hit Ctrl-C to interrupt the process, it will die and the missing "f" will show up.

This seems to not be a problem with irb, but any child process that calls "gets". If you launch "irb" from bash though and do the same steps, bash doesn't exhibit this issue, just a ruby REPL.

@zdennis
zdennis / problem-86.rb
Created February 27, 2015 15:03
Project Euler problem #86 (First Attempt, Naive I know :)
=begin
Cuboid room:
* consider all integer up to cuboids: M x M x M
* where M = 100
* a^2 + b^2 = c^2
* c = sqrt(a^2 + b^2)
* shortest path thru cuboid: Math.sqrt( l**2 + (w + h)**2 )
=end
#!/usr/bin/ruby
require 'chronic'
require 'term/ansicolor'
#
# Configuring your prompt. This can be set to a static value or to a
# Proc like object that responds to #call. If it responds to call it will
# be used every time the prompt is to be re-drawn
#