Skip to content

Instantly share code, notes, and snippets.

@roidrage
roidrage / Ouch
Created October 5, 2008 13:44
Ouch
if @params[:highlighting]
hash[:hl] = true
hash["hl.fl"] = @params[:highlighting][:field_list].join(',') if @params[:highlighting][:field_list]
snippets = @params[:highlighting][:max_snippets]
if snippets
if snippets.kind_of? Hash
if snippets[:default]
hash["hl.snippets"] = snippets[:default]
end
~$ ARCHFLAGS='-arch i386 -arch x86_64'
~$ rvm install 1.8.7 --debug --reconfigure -C --enable-shared=yes
~$ wget http://sourceforge.net/projects/rubycocoa/files/RubyCocoa/1.0.0/RubyCocoa-1.0.0.tar.gz/download
~$ tar xzf RubyCocoa-1.0.0.tar.gz && rm RubyCocoa-1.0.0.tar.gz && cd RubyCocoa-1.0.0
~/RubyCocoa-1.0.0$ ruby install.rb config --build-universal=yes
~/RubyCocoa-1.0.0$ ruby install.rb setup
~/RubyCocoa-1.0.0$ sudo ruby install.rb install
@lmarburger
lmarburger / backup_pgdump.rake
Created December 13, 2010 21:54
Copy the latest Heroku pgdump to S3 and capture a new one
# pgbackups client from heroku gem
require 'pgbackups/client'
desc 'Backup database'
task(:backup_database => :environment) { backup_database }
desc 'cron'
task :cron => :backup_database
@spig
spig / validate_barcode.js
Last active May 10, 2024 15:10
Validate a barcode UPC-E, UPC-A, EAN, EAN-14, SSCC
// checksum calculation for GTIN-8, GTIN-12, GTIN-13, GTIN-14, and SSCC
// based on http://www.gs1.org/barcodes/support/check_digit_calculator
function isValidBarcode(barcode) {
// check length
if (barcode.length < 8 || barcode.length > 18 ||
(barcode.length != 8 && barcode.length != 12 &&
barcode.length != 13 && barcode.length != 14 &&
barcode.length != 18)) {
return false;
}
@kares
kares / sessions.rake
Created April 14, 2011 07:31 — forked from yaroslav/sessions.rake
rake task for cleaning up ActiveRecord session store table from expired sessions
namespace :db do
namespace :sessions do
desc "Clean up expired Active Record sessions (updated before ENV['UPDATED_AT'], defaults to 1 month ago)."
task :expire => :environment do
time = Time.parse( ENV['UPDATED_AT'] || 1.month.ago.to_s(:db) )
say "cleaning up expired sessions (older than #{time}) ..."
session = ActiveRecord::SessionStore::Session
rows = session.delete_all ["updated_at < ?", time]
say "deleted #{rows} session row(s) - there are #{session.count} session row(s) left"
end
@anunay
anunay / js-email-validator.js
Last active July 25, 2016 04:51
Javascript: Email Validator
/**
* function validateEmail(email){}
* @author Anunay Dahal
* @param String email [Email address as a parameter]
* @return Boolean [Returns TRUE if email address is valid else return FALSE]
*/
function validateEmail(email){
return /^([\w!.%+\-])+@([\w\-])+(?:\.[\w\-]+)+$/.test(email);
}
@mkxml
mkxml / checkDigitGS1.js
Last active January 25, 2020 07:43
Check Digit GS1
/*
Check digit GS1
Arguments:
- [String] GS1 code without check digit to generate
the check digit
Returns:
- [Number] Check digit for given code
Author: Matheus R. Kautzmann
*/
@jtribble
jtribble / valid-phone.js
Last active July 25, 2016 04:55
Is string a valid us phone number
/**
* Is string a valid phone number?
*
* @param {string} str
* @return {boolean}
*/
var isValidPhone = function (str) {
if (!str) return false;
var count = str.replace(/[^0-9]/g, '').length;
return count == 10 || count == 11;
@croxton
croxton / cloudinary_reponsive_background_cover_img
Last active November 1, 2019 10:36
Responsive background cover images with Cloudinary & jQuery, fetched on the fly
HTML:
<header id="js-cover" class="cover">
<!-- Optionally specify image width stoppoints to reduce the maximum possible no of transforms per image -->
<!-- The appropriate image resolution will automatically be loaded -->
<img
data-stoppoints="480,768,1200"
data-src="http://res.cloudinary.com/<your account name>/image/fetch/w_auto,dpr_auto/http://<your full img url>"
class="cld-responsive cover-img" id="js-cover-img">