Skip to content

Instantly share code, notes, and snippets.

#!/bin/bash
redis_version=2.6.7
# from here: http://www.codingsteps.com/install-redis-2-6-on-amazon-ec2-linux-ami-or-centos/
# and here: https://raw.github.com/gist/257849/9f1e627e0b7dbe68882fa2b7bdb1b2b263522004/redis-server
###############################################
# To use:
# wget https://gist.github.com/raw/4497007/866287a130a5a4ca12a132fd52e391cde39f4f3f/install-redis.sh
# chmod +x install-redis.sh
# ./install-redis.sh
@mlconnor
mlconnor / aws_sdk_s3.php
Created January 15, 2013 18:33
Amazon AWS PHP 2 SDK S3 Example
<?php
// http://www.leofs.org/docs/s3_client.html
// i used composer with the following composer.json file and then called composer install
// {"require":{"aws/aws-sdk-php": "2.*"}}
require "vendor/autoload.php";
use Aws\Common\Enum\Region;
use Aws\S3\S3Client;
@mlconnor
mlconnor / javascript_notes.js
Created February 1, 2013 14:56
Javascript Notes
// ==== DOING CLASSES IN JS ============================================/
// constructor function
function MyClass () {
var privateVariable; // private member only available within the constructor fn
this.privilegedMethod = function () { // it can access private members
//..
};
}
@mlconnor
mlconnor / csv_to_json.php
Last active December 13, 2015 17:09
This awesome function will return an array of rows with the key values of each row matching the column header which should be provided in the first row.
<?php
$array = csv_to_array(file_get_contents('some_file.csv'));
$json = json_encode($array);
echo $json;
/**
* This awesome function will return an
* array of rows with the key values of
* each row matching the column header
@mlconnor
mlconnor / gist:4955479
Created February 14, 2013 19:18
JavaScript to parse a CSV string and create JSON objects based on the column headers
function csvToJson(str) {
var data = [], i = 0, k = 0, header = [];
var csvLines = CSVToArray(str);
for ( i = 0; i < csvLines.length; i++ ) {
var line = csvLines[i];
if ( i == 0 ) {
header = csvLines[i];
} else {
@mlconnor
mlconnor / git_cheats.sh
Last active December 14, 2015 08:38
My git cheat sheet
# create a repo
# 1. In your user bar at the top right of any page, click the "Create a New Repo" button
# 2. Dashboard context switcherSelect the account you wish to create the repository on
# 3. Create repository fieldEnter a name, select to make the repository either public or private and click "Create repository"
git clone https://github.com/mlconnor/[new-project-name]
# add your files
git add index.js
# commit that stuff back to github
@mlconnor
mlconnor / tlds.php
Last active August 2, 2023 12:49
PHP list of top level domains and a TLD domain checker for URL parsing
/**
* Returns true or false
* indicating whether or not the URL
* passes a TLD check.
*/
function check_tld($url) {
$parsed_url = parse_url($url);
if ( $parsed_url === FALSE ) return false;
return preg_match('/\.(aero|asia|biz|cat|com|coop|info|int|jobs|mobi|museum|name|net|org|post|pro|tel|travel|mlcee|xxx|ac|ad|ae|af|ag|ai|al|am|an|ao|aq|ar|as|at|au|aw|ax|az|ba|bb|bd|be|bf|bg|bh|bi|bj|bl|bm|bn|bo|bq|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|cr|cu|cv|cw|cx|cy|cz|de|dj|dk|dm|do|dz|ec|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gg|gh|gi|gl|gm|gn|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|im|in|io|iq|ir|is|it|je|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|me|mf|mg|mh|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|mv|mw|mx|my|mz|na|nc|ne|nf|ng|ni|nl|no|np|nr|nu|nz|om|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|ps|pt|pw|py|qa|re|ro|rs|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sx|sy|sz|tc|td|tf|tg|th|tj|tk|tl|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|
@mlconnor
mlconnor / yyyymmdd.js
Last active December 16, 2015 09:49
Regex to validate yyyymmdd with all leaps since 1582. This is bad ass. The final regex is... var regex = new RegExp("^(?:(?:(?:(?:[13579][26]|[2468][048])00)|(?:[0-9]{2}(?:(?:[13579][26])|(?:[2468][048]|0[48]))))(?:(?:(?:09|04|06|11)(?:0[1-9]|1[0-9]|2[0-9]|30))|(?:(?:01|03|05|07|08|10|12)(?:0[1-9]|1[0-9]|2[0-9]|3[01]))|(?:02(?:0[1-9]|1[0-9]|2[0-…
var regex = /^(?:\d{4})(?:(?:(09|04|06|11)(?:01|02|03|04|05|06|07|08|09|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30))|(?:(?:01|03|05|07|08|10|12)(?:01|02|03|04|05|06|07|08|09|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31))|(?:02(?:01|02|03|04|05|06|07|08|09|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29)))$/;
var m30 = "(?:(?:09|04|06|11)(?:0[1-9]|1[0-9]|2[0-9]|30))";
var m31 = "(?:(?:01|03|05|07|08|10|12)(?:0[1-9]|1[0-9]|2[0-9]|3[01]))";
var fLeap = "(?:02(?:0[1-9]|1[0-9]|2[0-9]))";
var fNonLeap = "(?:02(?:[01][0-9]|2[0-8]))";
var nonLeapMonths = "(?:" + m30 + "|" + m31 + "|" + fNonLeap + ")";
var leapMonths = "(?:" + m30 + "|" + m31 + "|" + fLeap + ")";
@mlconnor
mlconnor / oembed_endpoints.js
Created April 24, 2013 12:45
List of oEmbed endpoints found here http://api.embed.ly/1/services
[{"regex": ["http://*youtube.com/watch*", "http://*.youtube.com/v/*", "https://*youtube.com/watch*", "https://*.youtube.com/v/*", "http://youtu.be/*", "http://*.youtube.com/user/*", "http://*.youtube.com/*#*/*", "http://m.youtube.com/watch*", "http://m.youtube.com/index*", "http://*.youtube.com/profile*", "http://*.youtube.com/view_play_list*", "http://*.youtube.com/playlist*"], "about": "YouTube is the world's most popular online video community, allowing millions of people to discover, watch and share originally-created videos. YouTube provides a forum for people to connect, inform, and inspire others across the globe and acts as a distribution platform for original content creators and advertisers large and small.", "displayname": "YouTube", "name": "youtube", "domain": "youtube.com", "subdomains": ["m.youtube.com"], "favicon": "http://c2548752.cdn.cloudfiles.rackspacecloud.com/youtube.ico", "type": "video"}, {"regex": ["http://*twitch.tv/*", "http://*justin.tv/*/b/*", "http://*justin.tv/*/w/*"], "about":
@mlconnor
mlconnor / json_generics.js
Created May 1, 2013 20:15
Jison Gist for processing Java Generics like strings
var Parser = require("jison").Parser;
var grammar = {
"lex": {
"rules": [
["\\s+", "/* skip whitespace */"],
[",", "return ','"],
["<", "return '<'"],
[">", "return '>'"],