Skip to content

Instantly share code, notes, and snippets.

@rubiii
rubiii / application_controller.rb
Last active April 11, 2018 17:26
Rails: Redirect users to the last page they were trying to access after login
class ApplicationController < ActionController::Base
before_action :set_return_to
def set_return_to
if !request.xhr? && request.format.html? && request.get?
session[:return_to] = request.url
end
end
end
@rubiii
rubiii / decimal_validator.rb
Last active April 11, 2018 17:29
Rails validator for Postgres decimal type with custom precision and scale
class DecimalValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
precision = options[:precision]
scale = options[:scale]
if !precision || !scale
raise ArgumentError, "#{self.class.name} expects :precision and :scale option"
end
// Takes a screenshot from a given Tweet.
// Usage: phantomjs twitter_screenshot.js https://twitter.com/Snowden/status/777557723118440448
var system = require("system"),
args = system.args;
var url = args[1];
if (!url) {
console.log("Please provide the URL to a Tweet.");
@rubiii
rubiii / heredoc.rb
Created July 3, 2014 21:51
heredoc example. for the next time i forget the syntax.
ERB.new(<<MSG).result(binding)
Blah
ID CODE
--------------------------------------------------------
<% @codes.each do |id, code| %>
<%= id.ljust(20) %> <%= code %>
<% end %>
Blah
MSG
@rubiii
rubiii / keybase.md
Created June 13, 2014 13:08
keybase proof

Keybase proof

I hereby claim:

  • I am rubiii on github.
  • I am rubiii (https://keybase.io/rubiii) on keybase.
  • I have a public key whose fingerprint is A16E 8BE9 0170 59BF FC7B 5041 33B6 0CF6 F240 DD49

To claim this, I am signing this object:

@rubiii
rubiii / latest
Created February 5, 2014 18:01
tells you the latest version number of a gem
#!/usr/bin/env ruby
require 'httpclient'
require 'json'
if ARGV.any?
gems = ARGV
else
puts 'feed me some gem name(s)!'
exit
@rubiii
rubiii / chk
Last active August 29, 2015 13:56
check whether a certain project name is available as a gem or npm package
#!/usr/bin/env ruby
require 'httpclient'
require 'json'
class Chk
RUBYGEMS_URL = 'http://rubygems.org/gems/%s'
NPM_URL = 'https://npmjs.org/package/%s'

sources

app-js/**/*.js.coffee -> public/javascripts/compiled/

rsync -a --filter=P spec --filter=P *.js.map --filter=P *.js --delete -v app-js/ public/javascripts/compiled/

specs

@rubiii
rubiii / tldr.md
Last active December 17, 2015 22:59
Savon 3.0 TL;DR

Savon 3.0 TL;DR

  • It requires Ruby 1.9 or higher.
  • It is based on the all-new Wasabi 4.0 which is the driving factor behind this version. This means, that we now require a WSDL! There's a TL;DR for Wasabi 4.0 as well and you should read it.
  • HTTP caused a lot of problems and questions which this project should not have to deal with at all, so I'm replacing HTTPI with a simple adapter you can overwrite for authentication, cookies, etc. Added benefit: you can also easily swap it out in your tests.
  • Thanks to the new parser, Savon can now create example requests and show you the types to use.
@rubiii
rubiii / tldr.md
Last active December 17, 2015 22:59
Wasabi 4.0 TL;DR

Wasabi 4.0 TL;DR

  • It requires Ruby 1.9 or higher.
  • It is based on specifications and validates against real world WSDL documents.
  • It is way faster than ever before, while now parsing all elements.
  • It properly separates operations by service and port.
  • It supports WSDL and XML Schema imports.
  • It knows the input, output and fault message types.
  • It knows about Arrays of elements.