Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / iterateOverFilenamesInDirectoryRecursivelyBasedOnRegex.php
Last active October 23, 2024 17:06
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 / 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