Skip to content

Instantly share code, notes, and snippets.

Joseph Ndungu Joseph-N

Block or report user

Report or block Joseph-N

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
@Joseph-N
Joseph-N / base64encode.js
Last active Jun 21, 2018
How to download a file using Capybara and Poltergeist in Ruby. Tutorial Link https://goo.gl/CvzTG9
View base64encode.js
var base64EncodeChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
function base64encode(str) {
var out, i, len;
var c1, c2, c3;
len = str.length;
i = 0;
out = "";
while(i < len) {
@Joseph-N
Joseph-N / rspec_model_testing_template.rb
Created Jul 28, 2016 — forked from kyletcarlson/rspec_model_testing_template.rb
Rails Rspec model testing skeleton & cheat sheet using rspec-rails, shoulda-matchers, shoulda-callbacks, and factory_girl_rails. Pretty much a brain dump of examples of what you can (should?) test in a model. Pick & choose what you like, and please let me know if there are any errors or new/changed features out there. Reddit comment thread: http…
View rspec_model_testing_template.rb
# This is a skeleton for testing models including examples of validations, callbacks,
# scopes, instance & class methods, associations, and more.
# Pick and choose what you want, as all models don't NEED to be tested at this depth.
#
# I'm always eager to hear new tips & suggestions as I'm still new to testing,
# so if you have any, please share!
#
# @kyletcarlson
#
# This skeleton also assumes you're using the following gems:
@Joseph-N
Joseph-N / longest_common_substring_ruby.rb
Created Apr 23, 2016
Longest common substring ruby
View longest_common_substring_ruby.rb
def find_longest_common_substring(s1, s2)
if (s1 == "" || s2 == "")
return ""
end
m = Array.new(s1.length){ [0] * s2.length }
longest_length, longest_end_pos = 0,0
(0 .. s1.length - 1).each do |x|
(0 .. s2.length - 1).each do |y|
if s1[x] == s2[y]
m[x][y] = 1
@Joseph-N
Joseph-N / Gemfile_0
Last active Aug 29, 2015
Gists for tutorial
View Gemfile_0
gem 'bootstrap-sass'
gem 'devise'
gem 'mailboxer'
View _task.html.erb
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title"><%= task.title %></h3>
</div>
<div class="panel-body">
<%= truncate task.description, length: 50 %>
</div>
</div>
@Joseph-N
Joseph-N / application.rb
Last active Feb 26, 2019
Example YML file
View application.rb
require File.expand_path('../boot', __FILE__)
require 'rails/all'
# configurations
# preload tokens in application.yml to local ENV
config = YAML.load(File.read(File.expand_path('../application.yml', __FILE__)))
config.merge! config.fetch(Rails.env, {})
config.each do |key, value|
@Joseph-N
Joseph-N / _message.html.erb
Last active Mar 7, 2019
Tutorial code snippets for chat application in rails. Tutorial link http://goo.gl/l3e8zN
View _message.html.erb
<li class="<%= self_or_other(message) %>">
<div class="avatar">
<img src="http://placehold.it/50x50" />
</div>
<div class="chatboxmessagecontent">
<p><%= message.body %></p>
<time datetime="<%= message.created_at %>" title="<%= message.created_at.strftime("%d %b %Y at %I:%M%p") %>">
<%= message_interlocutor(message).name %><%= message.created_at.strftime("%H:%M %p") %>
</time>
</div>
@Joseph-N
Joseph-N / status_codes.txt
Created Jul 18, 2014
Rails status codes and their symbols
View status_codes.txt
100 = :continue
101 = :switching_protocols
102 = :processing
200 = :ok
201 = :created
202 = :accepted
203 = :non_authoritative_information
204 = :no_content
205 = :reset_content
206 = :partial_content
View gemfile
gem 'faker', github: 'stympy/faker'
gem 'rack-contrib'
gem 'soulmate', :require => 'soulmate/server'
@Joseph-N
Joseph-N / addthis.js
Last active Apr 25, 2018
How to configure AddThis to work with Turbolinks - Rails 4
View addthis.js
// turbolinks addthis
var initAdthis;
initAdthis = function(){
// Remove all global properties set by addthis, otherwise it won't reinitialize
for (var i in window) {
if (/^addthis/.test(i) || /^_at/.test(i)) {
delete window[i];
}
}
You can’t perform that action at this time.