Skip to content

Instantly share code, notes, and snippets.

@adam-lynch
adam-lynch / Rakefile
Created April 5, 2013 21:45
Rakefile to start the Jekyll server on Windows without CP850 string / character encoding errors. Just call: rake jekyll
task :jekyll do
puts '* Changing the codepage'
`chcp 65001`
puts '* Running Jekyll server'
`jekyll --server`
end
@adam-lynch
adam-lynch / iterateOverFilenamesInDirectoryRecursivelyBasedOnRegex.php
Last active December 16, 2015 07:18
Iterators on iterators. Get all filenames in a directory (recursively) which matches a given regular expression. Iterators: RegexIterator, RegexIteratorIterator, RegexDirectoryIterator, RecursiveRegexIterator.
$iterator = new \RegexIterator(
new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator($path, \FilesystemIterator::SKIP_DOTS),
\RecursiveIteratorIterator::LEAVES_ONLY
),
'%^.*?(([^\\\]+?)\.png)$%',
\RecursiveRegexIterator::GET_MATCH
);
foreach ($iterator as $file) {
@adam-lynch
adam-lynch / filterByDataAttribute.jquery.js
Last active December 16, 2015 21:40
A jQuery function which returns a subset of the given element(s) (jQuery object), where each element returned has the data attribute specified and thatdata attribute's value is equal to that of the second parameter (if one was given)
/**
* @param dataAttributeName string
* @param desiredDataAttributeValue string (optional)
* (desiredDataAttributeValue must be a string, strict comparison is done with data attribute value)
*
* @author: adam-lynch
*/
$.fn.filterByDataAttribute = function(dataAttributeName, desiredDataAttributeValue){
return $(this).filter(function() {
return desiredDataAttributeValue && $(this).data(dataAttributeName) === desiredDataAttributeValue
@adam-lynch
adam-lynch / delegateOnlyTo.jquery.js
Created May 12, 2013 22:11
Overriding of jQuery's .on() for specific event delegation; so that it can be called with ':only' at the end of the selector and the event will only be attached to that exact element (well, selector) only, i.e. excluding its descendants (well, technically it will be but the descendants will ignore the event and also prevent it from bubbling up i…
(function($){
var _oldOn = $.fn.on;
$.fn.on = function( types, selector, data, fn, one ){
var selectorSegments = selector.match(/^(.+?)(:only)?$/);
if ( selectorSegments[2] ) {
@adam-lynch
adam-lynch / convertHyphenatedToCamelCase.js
Last active December 17, 2015 12:29
Converts hypenated strings to camelCase. E.g. "hello-world" -> "helloWorld", "this-is-a-gist" -> "thisIsAGist", etc
/**
* @param str string
*
* @return string
*
* @author adam-lynch
*/
var convertHyphenatedToCamelCase = function( str ){
return str.replace( /-([a-z])/g, function( matches ){
return matches[1].toUpperCase();
@adam-lynch
adam-lynch / _GET.js
Last active December 17, 2015 12:48
Gets the value of a GET argument (URL parameter). Returns undefined if the argument doesn't exist. Like the $_GET superglobal array in PHP.
/**
* Gets the value of a GET argument (URL parameter). Returns undefined if the argument doesn't exist
*
* @param name string
* @returns string|undefined
*
* @author adam-lynch
*/
function _GET( name ){
var regexS = "[\\?&]" + name.replace( /[\[]/, "\\\[" ).replace( /[\]]/, "\\\]" ) + "=([^&#]*)",
@adam-lynch
adam-lynch / find-multi-byte-characters.sql
Created June 3, 2013 18:40
This returns all tuples which contain multi-byte characters. This came in handy when I was dealing with a MySQL database that was polluted with gibberish due to character encoding problems.
SELECT *
FROM table_name
WHERE LENGTH(column_name) != CHAR_LENGTH(column_name);
@adam-lynch
adam-lynch / rappingwrappers.js
Created July 26, 2013 15:08
Rapping Wrappers. Paste this in your browser's console
var e=document.querySelectorAll("*[id*=wrapper], *[class*=wrapper]"),r=["http://www.richincomeways.com/wp-content/uploads/2013/06/tupac.jpg","http://www.2freshbeats.com/wp-content/uploads/2012/05/snoop.jpg","http://cdn.hiphopwired.com/wp-content/uploads/2012/07/10428_The-Notorious-B_I_G_1.jpg"],rl=r.length;for(var i=0;i<e.length;i++){e[i].style.background="transparent url("+r[i%rl]+") center center repeat"};console.log( e.length);
@adam-lynch
adam-lynch / printObject.js
Created October 3, 2013 11:15
Pretty prints an object. Useful for IE8- which doesn't support console.debug
alert(JSON.stringify(YOUR_OBJECT_HERE, null, 4));//from: http://stackoverflow.com/a/8611131/727074
@adam-lynch
adam-lynch / speedingUpTheGoogleAndroidEmulator.md
Created October 31, 2013 11:11
Speeding up the Google Android emulator (for Titanium)

Speeding up the Google Android emulator (for Titanium)

Using Android 4.2.2 as an example.


1. Get the x86 Image

  1. Run the Android SDK Manager.
    • Windows: /SDK Manager.exe