Skip to content

Instantly share code, notes, and snippets.

@3dd13
3dd13 / Gemfile
Created Nov 27, 2012
Runing single ruby file on heroku
View Gemfile
source 'https://rubygems.org'
@kenzie
kenzie / _error_messages.html.erb
Created Sep 13, 2011
Rails 3 form error partial
View _error_messages.html.erb
<% if target.errors.any? %>
<div class="error_explanation">
<h2><%= pluralize(target.errors.count, "error") %> prevented this record from being saved:</h2>
<ul>
<% target.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
@pch
pch / watermark.rb
Created Jan 18, 2011
Paperclip Watermark processor
View watermark.rb
class User
has_attached_file :photo,
:processors => [:watermark],
:styles => {
:medium => {
:geometry => "300x300>",
:watermark_path => "#{Rails.root}/public/images/watermark.png"
},
:thumb => "100x100>",
}
View lock-unlock-scroll.js
function lock_scroll(){
// lock scroll position, but retain settings for later
var scrollPosition = [
self.pageXOffset || document.documentElement.scrollLeft || document.body.scrollLeft,
self.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop
];
var html = jQuery('html'); // it would make more sense to apply this to body, but IE7 won't have that
html.data('scroll-position', scrollPosition);
html.data('previous-overflow', html.css('overflow'));
html.css('overflow', 'hidden');
View gist:20ac531649f76f123ca6
//Object Literal
var app = app || {};
//object literal
app = {
init: function(){
this.cache();
this.bind();
},
@etiennetalbot
etiennetalbot / App.Module.js
Last active Aug 31, 2016
Javascript Module
View App.Module.js
/*jslint nomen: true */
window.App = window.App || {};
window.App.ModuleName = (function (document, $) {
'use strict'; //OPTIONAL if you don't want your code to be strict
var _vars, _els, _privateMethod, init;
@mopsled
mopsled / color.rb
Last active Dec 23, 2016
Simple Sinatra/ActiveRecord RESTful API
View color.rb
require 'active_record'
class Color < ActiveRecord::Base
end
@mpmckenna8
mpmckenna8 / brazilWor.json
Last active Aug 11, 2017
d3 data() to load brazil w/ cities map
View brazilWor.json
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@Kikobeats
Kikobeats / index.js
Last active Sep 6, 2017
ES6 Pure & self documented Functions.
View index.js
/**
* ES6 Pure & self documented Functions.
*
* Why Pure?
*
* A pure function is a function where the return value is only determined
* by its input values, without observable side effects.
*
* Why Self-documented?
*
@james2doyle
james2doyle / keyup-debouce-timeout.js
Created Oct 5, 2016
A debounce timeout trigger for typing in an input. The example is in jQuery, but this works with any event/listener.
View keyup-debouce-timeout.js
$('#input').on('keyup', function() {
// do an ajax save when this input is changed
var val = this.value;
// clear the timeout so we dont fire in succession
clearTimeout(this.delayer);
this.delayer = setTimeout(function () {
console.log(val);
}, 500);
});