Skip to content

Instantly share code, notes, and snippets.

@Joseph-N
Joseph-N / example.js
Last active August 29, 2015 13:57
With this jquery snippet you will be able to animate to an anchor from a url. If for example you follow a link from page A (e.g http://mywebsite.com/products/1#tomato) it will scroll smoothly to the element with id of tomato in page B
// animate scroll put this on (PAGE B)
var elementClick = window.location.hash
var destination = $(elementClick).offset().top;
$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination}, 1100, function() {
window.location.hash = elementClick
});
@Joseph-N
Joseph-N / example.html
Last active August 29, 2015 13:58
Code snippets on how to load Github embedded gists with turbolinks - Tutorial link http://josephndungu.com/tutorials/using-github-embedded-gists-with-turbolinks
<!-- before -->
<script src="https://gist.github.com/username/gist_id.js"></script>
<script src="https://gist.github.com/username/gist_id.js?file=file_name"></script>
<!-- after -->
<div class="gist" data-src="https://gist.github.com/username/gist_id.json"></div>
<div class="gist" data-src="https://gist.github.com/username/gist_id.json" data-file="file_name"></div>
@Joseph-N
Joseph-N / Gemfile
Last active August 29, 2015 13:58
How to implement revision control in rails app using paperclip and vestal versions - Tutorial link:- http://josephndungu.com/tutorials/revision-control-with-paperclip-rails
# add paperclip
gem 'paperclip', '~>3.4.2'
# add vestal versions
gem 'vestal_versions', :git => 'git://github.com/laserlemon/vestal_versions'
@Joseph-N
Joseph-N / modems.conf
Last active August 29, 2015 14:01
code snippets for sms messages with rails
# Modems configuration
#
# Example and default values
#
# group = modems
# id = "my-id"
# name = "my-name"
# detect-string = "MODEM"
# detect-string2 = "" [Default]
# init-string = "AT+CNMI=1,2,0,0,0" [Default]
gem 'faker', github: 'stympy/faker'
gem 'rack-contrib'
gem 'soulmate', :require => 'soulmate/server'
<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 / Gemfile_0
Last active August 29, 2015 14:18
Gists for tutorial
gem 'bootstrap-sass'
gem 'devise'
gem 'mailboxer'
@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 / 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 / addthis.js
Last active April 25, 2018 07:03
How to configure AddThis to work with Turbolinks - Rails 4
// 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];
}
}