Skip to content

Instantly share code, notes, and snippets.

View sameerkat's full-sized avatar

Sameer sameerkat

View GitHub Profile
@sameerkat
sameerkat / regex.txt
Created December 23, 2015 09:13 — forked from nerdsrescueme/regex.txt
Common Regex
Perl and PHP Regular Expressions
PHP regexes are based on the PCRE (Perl-Compatible Regular Expressions), so any regexp that works for one should be compatible with the other or any other language that makes use of the PCRE format. Here are some commonly needed regular expressions for both PHP and Perl. Each regex will be in string format and will include delimiters.
All Major Credit Cards
This regular expression will validate all major credit cards: American Express (Amex), Discover, Mastercard, and Visa.
//All major credit cards regex
'/^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|6011[0-9]{12}|622((12[6-9]|1[3-9][0-9])|([2-8][0-9][0-9])|(9(([0-1][0-9])|(2[0-5]))))[0-9]{10}|64[4-9][0-9]{13}|65[0-9]{14}|3(?:0[0-5]|[68][0-9])[0-9]{11}|3[47][0-9]{13})*$/'
@sameerkat
sameerkat / konami.js
Created May 16, 2015 01:08 — forked from BastienClement/gist:1286687
Konami Code in Javascript
function konami(cb) {
var code = [38, 38, 40, 40, 37, 39, 37, 39, 66, 65];
var pos = 0;
document.onkeydown = function(e) {
if(code[pos] === e.which) {
if(++pos >= code.length) {
if(typeof cb == String.fromCharCode(102,117,110,99,116,105,111,110))
cb();
pos = 0;
@sameerkat
sameerkat / pubsub.js
Last active August 29, 2015 14:19 — forked from patrickrbc/pubsub.js
;(function (root) {
'use strict';
function PubSub () {
this.topics = {};
}
PubSub.prototype.subscribe = function (name, fn) {
this.topics[name] = this.topics[name] || [];
this.topics[name].push(fn);
@sameerkat
sameerkat / pr.sh
Created December 16, 2014 23:33
Quickly create a Pull Request for your current branch
pr() {
local repo=`git remote -v | grep -m 1 "(push)" | sed -e "s/.*github.com[:/]\(.*\)\.git.*/\1/"`
local branch=`git name-rev --name-only HEAD`
echo "... creating pull request for branch \"$branch\" in \"$repo\""
open https://github.com/$repo/pull/new/$branch
}
alias pr=pr
@sameerkat
sameerkat / update-date.sh
Last active August 29, 2015 14:09
Update date/time to lastest
boot2docker ssh
sudo ntpclient -s -h pool.ntp.org