Skip to content

Instantly share code, notes, and snippets.

View magdmartin's full-sized avatar

Martin Magdinier magdmartin

  • Toronto (Canada)
View GitHub Profile
@nerdsrescueme
nerdsrescueme / regex.txt
Created September 23, 2011 16:08
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})*$/'
@eliotk
eliotk / gist:7744806
Last active October 6, 2020 13:00
A ruby script to parse My Tracks kml files and aggregate the summary data into one CSV file to chart changes in time series (or otherwise)
require 'nokogiri'
require 'csv'
kml_path = '/path/to/Google Drive/My Tracks/'
def kml_file_paths path
Dir.glob(path + "*.kml")
end
csv = CSV.open('mytracks.csv', "wb")
@ettorerizza
ettorerizza / refinetranslator.py
Last active April 28, 2018 00:04
a mini Python3 script that transforms a list of operations performed in Open Refine into a text file easier to read. To use it, paste your Open Refine "undo/redo" history in a file named, for example, "operations.json", place this file in the same folder as the Python script, and run this command : python refinetranslator.py operations.json
#!/usr/bin/python3
import json
import sys
with open(sys.argv[1], "r") as infile:
data = json.load(infile)
outfile = open(sys.argv[1]+".txt", 'w')
count = 1