Skip to content

Instantly share code, notes, and snippets.

@Joseph-N
Joseph-N / filtering.js
Last active November 14, 2020 15:59
Embedding the plagdetector smart widget
<script type="text/javascript">
window.onload = function(){
new PDWidget({user_id: '10' }).render("#plagdetector-container");
}
</script>
@Joseph-N
Joseph-N / heroku-remote.md
Created September 17, 2020 08:14 — forked from randallreedjr/heroku-remote.md
Add a Heroku remote to an existing git repo

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 August 25, 2020 18:16
Sidekiq sidekiq.service Fedora + RVM
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 June 21, 2018 08:34
How to download a file using Capybara and Poltergeist in Ruby. Tutorial Link https://goo.gl/CvzTG9
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 July 28, 2016 12:30 — forked from SabretWoW/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…
# 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 April 23, 2016 14:11
Longest common substring ruby
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 August 29, 2015 14:18
Gists for tutorial
gem 'bootstrap-sass'
gem 'devise'
gem 'mailboxer'
<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 December 8, 2020 16:31
Example YML file
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 April 15, 2021 11:09
Tutorial code snippets for chat application in rails. Tutorial link http://goo.gl/l3e8zN
<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>