Skip to content

Instantly share code, notes, and snippets.

Avatar

Joseph Ndungu Joseph-N

View GitHub Profile
@Joseph-N
Joseph-N / heroku-remote.md
Created Sep 17, 2020 — forked from randallreedjr/heroku-remote.md
Add a Heroku remote to an existing git repo
View heroku-remote.md

Working with git remotes on Heroku

Generally, you will add a git remote for your Heroku app during the Heroku app creation process, i.e. heroku create. However, if you are working on an existing app and want to add git remotes to enable manual deploys, the following commands may be useful.

Adding a new remote

Add a remote for your Staging app and deploy

Note that on Heroku, you must always use master as the destination branch on the remote. If you want to deploy a different branch, you can use the syntax local_branch:destination_branch seen below (in this example, we push the local staging branch to the master branch on heroku.

$ git remote add staging https://git.heroku.com/staging-app.git
@Joseph-N
Joseph-N / sidekiq.monit
Created Aug 25, 2020
Sidekiq sidekiq.service Fedora + RVM
View sidekiq.monit
check process sidekiq
matching "sidekiq"
start program = "/bin/systemctl start sidekiq.service"
stop program = "/bin/systemctl stop sidekiq.service"
if totalmem > 3000 MB for 5 cycles then alert
if totalmem > 5000 MB for 5 cycles then restart
@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
You can’t perform that action at this time.