Skip to content

Instantly share code, notes, and snippets.

View jpsirois's full-sized avatar
🤙

Jean-Philippe Sirois jpsirois

🤙
View GitHub Profile
//
// Regular Expression for URL validation
//
// Author: Diego Perini
// Created: 2010/12/05
// Updated: 2018/09/12
// License: MIT
//
// Copyright (c) 2010-2018 Diego Perini (http://www.iport.it)
//
@plbabin
plbabin / gist:908413
Created April 7, 2011 18:47
Small custom jQuery selector that validate if an element has a data attach to himself
$.extend($.expr[':'], {
hasData: function (obj, intStackIndex, arrProperties) {
var arguments = arrProperties[ 3 ];
var $this = $(obj);
var isValid = false;
if(arguments.indexOf('=') > -1){
arguments = arguments.split('=')
if($this.data(arguments[0]) == arguments[1]){
isValid = true;
@madrobby
madrobby / README.md
Created May 17, 2011 16:34 — forked from 140bytes/LICENSE.txt
Luhn10 algorithm

Implementation of the Luhn 10 algorithm to check validity of credit card numbers. See http://en.wikipedia.org/wiki/Luhn_algorithm for details on the algorithm.

var validCreditCard = function(a,b,c,d,e){for(d=+a[b=a.length-1],e=0;b--;)c=+a[b],d+=++e%2?2*c%10+(c>4):c;return!(d%10)};

validCreditCard('378282246310005'); //=> true
validCreditCard('378282246310006'); //=> false

// some numbers to test with
// 378282246310005 371449635398431 378734493671000
@necolas
necolas / snippet.js
Created June 14, 2011 20:36
Optimised async loading of cross-domain scripts
/*
* Updated to use the function-based method described in http://www.phpied.com/social-button-bffs/
* Better handling of scripts without supplied ids.
*
* N.B. Be sure to include Google Analytics's _gaq and Facebook's fbAsyncInit prior to this function.
*/
(function(doc, script) {
var js,
fjs = doc.getElementsByTagName(script)[0],
@lucasfais
lucasfais / gist:1207002
Created September 9, 2011 18:46
Sublime Text 2 - Useful Shortcuts

Sublime Text 2 – Useful Shortcuts (Mac OS X)

General

⌘T go to file
⌘⌃P go to project
⌘R go to methods
⌃G go to line
⌘KB toggle side bar
⌘⇧P command prompt
@danbeam
danbeam / update-nodejs.bash
Created November 30, 2011 18:52
Keep up to date with the latest version of node.js
#!/bin/bash
sudo apt-get -qq install build-essential g++ apache2-utils libssl-dev curl
latest_dir="http://nodejs.org/dist/latest/";
latest_version=$(curl -s "$latest_dir" | grep "tar\.gz" | sed -re 's/.*?href="node-(v[0-9\.]+)\.tar\.gz".*/\1/');
cleanup() {
rm -rf "$temp";
}
#!/usr/bin/env ruby
require 'csv'
require 'json'
if ARGV.size != 2
puts 'Usage: csv_to_json input_file.csv output_file.json'
puts 'This script uses the first line of the csv file as the keys for the JSON properties of the objects'
exit(1)
end
@rafbm
rafbm / config.ru
Created January 28, 2012 23:29
Example Sinatra app using the Namespace extension from Sinatra::Contrib
require 'sinatra/base'
require 'sinatra/namespace'
class MyApp < Sinatra::Base
register Sinatra::Namespace
get '/' do
'Home'
end
@mikejolley
mikejolley / gist:1965933
Created March 3, 2012 12:50
WooCommerce payment gateway plugin base
<?php
/*
Plugin Name: WooCommerce <enter name> Gateway
Plugin URI: http://woothemes.com/woocommerce
Description: Extends WooCommerce with an <enter name> gateway.
Version: 1.0
Author: WooThemes
Author URI: http://woothemes.com/
Copyright: © 2009-2011 WooThemes.