Skip to content

Instantly share code, notes, and snippets.

rubiii rubiii

Block or report user

Report or block rubiii

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@rubiii
rubiii / application_controller.rb
Last active Apr 11, 2018
Rails: Redirect users to the last page they were trying to access after login
View application_controller.rb
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 Apr 11, 2018
Rails validator for Postgres decimal type with custom precision and scale
View decimal_validator.rb
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
View twitter_screenshot.js
// 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 Jul 3, 2014
heredoc example. for the next time i forget the syntax.
View heredoc.rb
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 Jun 13, 2014
keybase proof
View keybase.md

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 Feb 5, 2014
tells you the latest version number of a gem
View latest
#!/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 Aug 29, 2015
check whether a certain project name is available as a gem or npm package
View chk
#!/usr/bin/env ruby
require 'httpclient'
require 'json'
class Chk
RUBYGEMS_URL = 'http://rubygems.org/gems/%s'
NPM_URL = 'https://npmjs.org/package/%s'
View rsync-wtf.md

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 Dec 17, 2015
Savon 3.0 TL;DR
View tldr.md

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 Dec 17, 2015
Wasabi 4.0 TL;DR
View tldr.md

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.
You can’t perform that action at this time.