Skip to content

Instantly share code, notes, and snippets.

@NatasaPeic
NatasaPeic / regex.txt
Created July 5, 2017 02:04 — 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})*$/'
@NatasaPeic
NatasaPeic / regex.txt
Created July 5, 2017 02:04 — 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})*$/'
@NatasaPeic
NatasaPeic / bfs.html
Created July 6, 2017 18:04 — forked from kevinfjbecker/bfs.html
Breadth-first Graph Traversal in JavaScript
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>A Graph</title>
<!--[if IE]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<style>
article, aside, figure, footer, header, hgroup,
@NatasaPeic
NatasaPeic / d3.html
Created July 14, 2017 19:49 — forked from LevelbossMike/d3.html
creating table from array of json with d3
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
</head>
<body>
<table id="split">
<thead></thead>
<tbody></tbody>
@NatasaPeic
NatasaPeic / index.html
Created August 16, 2017 12:53 — forked from enjalot/index.html
Simple Pie Chart example with D3.js
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>Testing Pie Chart</title>
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.js?2.1.3"></script>
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.geom.js?2.1.3"></script>
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.layout.js?2.1.3"></script>
<style type="text/css">
@NatasaPeic
NatasaPeic / app.js
Created September 18, 2017 22:38 — forked from clarle/app.js
Short tutorial on how to use Express and node-mysql
// Module dependencies
var express = require('express'),
mysql = require('mysql');
// Application initialization
var connection = mysql.createConnection({
host : 'localhost',
user : 'root',
var util = require('util'),
http = require('http'),
httpProxy = require('http-proxy');
function request_handler(proxy, req, res) {
// http(s) requests.
proxy.web(req, res, function (err) {
console.log(err.stack);
res.writeHead(502);
res.end("There was an error. Please try again");
@NatasaPeic
NatasaPeic / index.html
Created March 13, 2018 14:45 — forked from pmanijak/index.html
Service example with AngularJS for sharing scope data between controllers
<!doctype html>
<html ng-app="project">
<head>
<title>Angular: Service example</title>
<script src="http://code.angularjs.org/angular-1.0.1.js"></script>
<script>
var projectModule = angular.module('project',[]);
projectModule.factory('theService', function() {
return {
@NatasaPeic
NatasaPeic / toblob.js
Created May 10, 2018 16:37
Canvas toBlob() polyfill
(function(global) {
if (!('HTMLCanvasElement' in global)) return;
if (!('toDataURL' in global.HTMLCanvasElement.prototype)) return;
if ('toBlob' in global.HTMLCanvasElement.prototype) return;
Object.defineProperty(global.HTMLCanvasElement.prototype, 'toBlob', {
value: function(callback/*, type, encoderOptions*/) {
var url = this.toDataURL.apply(this, [].slice.call(arguments, 1));
var m = /^data:(.*?);base64,(.*)$/.exec(url), type = m[1], b64 = m[2];
setTimeout(function() {
callback(new Blob([
@NatasaPeic
NatasaPeic / README.md
Created May 14, 2018 13:37 — forked from markmarkoh/README.md
US Zip Codes

This is a d3.js visualization of US zip codes.

Original zip code dataset from Geocommons.

5MB shapefile with properties such as zipcode, state, name, population, area, more.

http://geocommons.com/overlays/54893 (Thank you Bill Greer)

This converts it nicely: