Skip to content

Instantly share code, notes, and snippets.

@jrom
jrom / datamodel.rake
Created Nov 23, 2016
Data model for Rails app using rails_erd
View datamodel.rake
namespace :datamodel do
desc 'Generates data model in erd.pdf'
task :generate do
#say 'Loading application environment...'
Rake::Task[:environment].invoke
require 'rails_erd/diagram/graphviz'
#say 'Loading all models...'
Rails.application.eager_load!
::Rails::Engine.subclasses.map(&:instance).map {|e| e.class.eager_load!}
View redbooth-api3.js
var local_hash = window.location.hash.substr(1),
hash_value = local_hash.substr(local_hash.indexOf(key + '=')).split('&')[0].split('=')[1],
Data = {};
// Once OAuth handshake is done, we'll be redirected with a hash string in the location that we'll use to extract the token
if (hash_value) {
Data.access_token = hash_value;
call_api("organizations", {}, function (data) {
console.log(data); // Here you have your organizations
@jrom
jrom / status.sh
Created Mar 14, 2013
Find status aggregated count for nginx logs
View status.sh
sudo cat /var/log/nginx/access.log | cut -f 9 -d" " | sort | uniq -c
@jrom
jrom / sshd_config
Created Jan 21, 2013
SSHD Config to avoid frozen capistrano deploys
View sshd_config
# /etc/ssh/sshd_config
TCPKeepAlive yes
ClientAliveInterval 15
ClientAliveCountMax 5
@jrom
jrom / screen.sh
Created Dec 6, 2012
How to use screen
View screen.sh
screen # Starts a screen session
<C-a d> # Detaches from the screen session
screen -r # Reattaches to a detached session
screen -S paco # Starts a screen session called "paco"
screen -r paco # Reattaches to a detached session called "paco"
@jrom
jrom / creditcard.coffee
Created May 11, 2012
Credit Card number validation in Coffee Script
View creditcard.coffee
# Ported from https://github.com/jzaefferer/jquery-validation/blob/master/jquery.validate.js
creditcard = (value) ->
# accept only spaces, digits and dashes
if /[^0-9 \-]+/.test(value)
return false
nCheck = 0
nDigit = 0
bEven = false
@jrom
jrom / remove_jobs.rb
Created Mar 15, 2012
Remove resque jobs if match a condition
View remove_jobs.rb
def remove_failed_jobs_if(&block)
i = 0
while i < Resque::Failure.count
job = Resque::Failure.all(i)
if yield job
Resque::Failure.remove(i)
else
i += 1
end
end
@jrom
jrom / emoji-plugin.js
Created Mar 7, 2012
Emoji plugin for Talker
View emoji-plugin.js
plugin.onMessageInsertion = function (event) {
var content;
content = Talker.getLastInsertion().replace(/:[\w_+]+:/g, function (match) {
var emoji = match,
filename = (emoji == ':+1:' ? ':plus1:' : emoji).replace(/:/g, '');
return "<img class=\"emoji\" title=\"" + emoji + "\" alt=\"" + emoji + "\" height=\"20\" width=\"20\" align=\"absmiddle\" src=\"https://teambox.com/assets/emojis/" + filename + ".png\">"
});
return content;
};
@jrom
jrom / nginx.conf
Created Feb 7, 2012
nginx hack for multiple conditions
View nginx.conf
if ($request_uri = /) {
set $test A;
}
if ($host ~* teambox.com) {
set $test "${test}B";
}
if ($http_cookie !~* "auth_token") {
set $test "${test}C";
You can’t perform that action at this time.