Skip to content

Instantly share code, notes, and snippets.

@ijy
ijy / cartesian-product.js
Last active April 23, 2022 15:54
Underscore.js implementation of Cartesian Product (without any mutable variable). @see: http://stackoverflow.com/questions/12303989/cartesian-product-of-multiple-arrays-in-javascript
function cartesianProductOf() {
return _.reduce(arguments, function(a, b) {
return _.flatten(_.map(a, function(x) {
return _.map(b, function(y) {
return x.concat([y]);
});
}), true);
}, [ [] ]);
};
@ijy
ijy / xhtml-to-markdown.xsl
Created July 21, 2013 14:29
XHTML to Markdown converter.
<?xml version='1.0' encoding='iso-8859-1'?>
<!-- XHTML-to-Markdown converter by Andrew Green, Article Seven, http://www.article7.co.uk/ -->
<!-- This work is licensed under the Creative Commons Attribution-ShareAlike License. To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/2.0/ or send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA. -->
<xsl:stylesheet version='1.0' xmlns:h="http://www.w3.org/1999/xhtml" xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
<xsl:output method='text' encoding='utf-8'/>
@ijy
ijy / jquery-validate-match.js
Created July 17, 2013 11:29
Match two fields with the jQuery Validate plugin and the equalTo method.
$('#myform').validate({
rules: {
email: 'required',
emailConfirm: {
equalTo: '#email'
}
}
});
@ijy
ijy / ssl-setup.sh
Created July 16, 2013 08:00 — forked from leevigraham/ssl-setup.sh
A shell script to setup SSL on your localhost.
mkdir ~/Desktop/ssl
cd ~/Desktop/ssl
openssl genrsa -des3 -out server.key 1024
openssl req -new -key server.key -out server.csr
cp server.key server.key.org
openssl rsa -in server.key.org -out server.key
openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
sudo cp server.crt /private/etc/apache2/server.crt
sudo cp server.key /private/etc/apache2/server.key
@ijy
ijy / jquery-pubsub.js
Created June 28, 2013 14:19
jQuery PubSub in three lines. This will work in IE9+, so it's a perfect choice for jQuery 2.0 projects.
var o = $({});
$.subscribe = o.on.bind(o);
$.publish = o.trigger.bind(o);
@ijy
ijy / simple-server.txt
Last active December 19, 2015 02:39 — forked from JeffreyWay/gist:1525217
Instant Server for Current Directory.
alias server='open http://localhost:8000 && python -m SimpleHTTPServer'
@ijy
ijy / chromeframe.html
Created June 28, 2013 14:05
Add Chrome Frame prompt for IE6+7.
<!-- Prompt IE6 users to install Chrome Frame -->
<!--[if lt IE 8 ]>
<script src="//ajax.googleapis.com/ajax/libs/chrome-frame/1.0.3/CFInstall.min.js"></script>
<script>window.attachEvent('onload',function(){CFInstall.check({mode:'overlay'})})</script>
<![endif]-->
@ijy
ijy / querystring-params.php
Created June 28, 2013 14:04
Convert query string params into an arrary
$querystring = 'a=foo&b=bar';
parse_str($querystring, $params);
// Test it
echo "<pre>";
print_r($params);
echo "</pre>";
@ijy
ijy / Laravel: Blade: Limit foreach loop.php
Created June 22, 2013 23:15
A quick and easy way to limit a foreach loop in Laravel Blade.
@foreach (array_slice($posts->toArray(), 0, 5) as $post)
<h1>{{ $post['title'] }}</h1>
@endforeach
@ijy
ijy / Symphony 2.3 Custom Data Source.php
Last active December 18, 2015 20:49
Symphony 2.3 custom Data Source shell.
<?php
require_once(TOOLKIT . '/class.datasource.php');
Class datasourcetour_l_current_presentation_images extends SectionDatasource{
public $dsParamROOTELEMENT = 'tour-l-current-presentation-images';
public $dsParamORDER = 'asc';
public $dsParamPAGINATERESULTS = 'yes';
public $dsParamLIMIT = '1';