Skip to content

Instantly share code, notes, and snippets.

View richardsondx's full-sized avatar

Richardson Dackam richardsondx

View GitHub Profile

Keybase proof

I hereby claim:

  • I am richardsondx on github.
  • I am richardsondx (https://keybase.io/richardsondx) on keybase.
  • I have a public key ASAbWDn-nbRVwC_v7ul--0bEjDuiQ6JqT-lW8XPJXXineQo

To claim this, I am signing this object:

@richardsondx
richardsondx / inflections.rb
Last active March 18, 2020 06:36
Humanize Method
class String
# ..... some code
#
# See ActiveSupport::Inflector.humanize.
def humanize(capitalize: true, keep_id_suffix: false)
ActiveSupport::Inflector.humanize(self, capitalize: capitalize, keep_id_suffix: keep_id_suffix)
end
# .... more codee
end
@richardsondx
richardsondx / README.md
Last active January 8, 2020 18:42
Util to Flatten an array of arbitrarily nested arrays of integers into a flat array of integers. e.g. [[1,2,[3]],4] -> [1,2,3,4]

ArrayUtil

I wrote a class with a custom :flatten method in Ruby similar to [1,2,3].flatten This method recursively flatten an Array

Prerequisite

You'll need:

  • ruby
  • minitest
@richardsondx
richardsondx / README.md
Created January 8, 2020 18:39
Util to Flatten an array of arbitrarily nested arrays of integers into a flat array of integers. e.g. [[1,2,[3]],4] -> [1,2,3,4]

ArrayUtil

I wrote a class with a custom :flatten method in Ruby similar to [1,2,3].flatten This method recursively flatten an Array

Prerequisite

You'll need:

  • ruby
  • minitest
@richardsondx
richardsondx / Retweet Migration
Created April 25, 2012 02:07
Retweet functionality App
class CreateRetweets < ActiveRecord::Migration
def change
create_table :retweets do |t|
t.string :content
t.integer :user_id
t.integer :micropost_id
t.timestamps
end
add_index :retweet, [:micropost_id, :created_at]
@richardsondx
richardsondx / convert.rb
Created October 9, 2012 01:42
Convert html tag img to image_tag
# This project is a fork from https://gist.github.com/1254319 that I updated
# ~ (http://richardsondx.github.com)
#!/usr/bin/env ruby -Ku
require "nokogiri"
require "iconv"
# opens every file in the given dir tree and converts any html img tags to rails image_tag calls
@richardsondx
richardsondx / error.txt
Last active June 13, 2018 03:16
undefined class/module Rack::Handler::Servlet::DefaultEnv
# jruby 9.0.5.0 (2.2.3) 2016-01-26 7bee00d Java HotSpot(TM) 64-Bit Server VM 25.72-b15 on 1.8.0_72-b15 +jit [darwin-x86_64]
# Rails 3.2.13
cache error: undefined class/module Rack::Handler::Servlet::DefaultEnv
org/jruby/RubyMarshal.java:145:in `load'
/Users/richardson/.rvm/gems/jruby-9.0.5.0/gems/actionpack-3.2.13/lib/action_dispatch/http/rack_cache.rb:18:in `read'
/Users/richardson/.rvm/gems/jruby-9.0.5.0/gems/rack-cache-1.6.1/lib/rack/cache/meta_store.rb:30:in `lookup'
/Users/richardson/.rvm/gems/jruby-9.0.5.0/gems/rack-cache-1.6.1/lib/rack/cache/context.rb:173:in `lookup'
/Users/richardson/.rvm/gems/jruby-9.0.5.0/gems/rack-cache-1.6.1/lib/rack/cache/context.rb:66:in `call!'
/Users/richardson/.rvm/gems/jruby-9.0.5.0/gems/rack-cache-1.6.1/lib/rack/cache/context.rb:51:in `call'
@richardsondx
richardsondx / Gemfile_code_smell.rb
Last active May 19, 2017 20:33
Performance Gemfile & Best Practises Gems
# Code smell
gem 'rubocop'
gem "rubycritic", require: false
gem 'reek'
gem 'simplecov', require: false
gem 'gemsurance'
# Better error page for Rack apps
gem "better_errors"
gem "binding_of_calle"
@richardsondx
richardsondx / gzip.rb
Last active April 4, 2017 07:49
Monkey patch to fix Authentication failure! invalid_credentials: OAuth2::Error jruby 8 , rails 3.2.13 devise 3.2.4 | Force faraday to 'uncompressed' gzip
# In Rails, add this to your Initializer/ folder
#
# Fix by @richardsondx - Richardson Dackam
#
# Thi monkey patch is not actually forcing farady to uncompress the response but it's telling it not to compress
# So it forces Faraday to avoid compressing the response.
# The gresponse from google had the header 'accept-encoding': 'gzip'
# unlike http.net, http.request doesn't automatically uncompress gzip request
# more info about http.request at https://github.com/ruby/ruby/blob/ruby_2_2/lib/net/http.rb
@richardsondx
richardsondx / gmail.js
Created April 1, 2016 16:13
My app is a chrome extension. (chrome browser). I'm trying to trigger a `SAVE` on the draft in gmail
// compose is the compose window element
// Here I'm clicking the x button on the compose window. But it Doesn't seem to work or trigger a save.
$(compose).find('[aria-label="Save & Close"]').trigger('click');
// select subject to trigger a Save, not sure if that works.
$(compose).find('input[name=subjectbox]').trigger('select');
// Reload Page
$.ajax({
url: window.location.href,