Skip to content

Instantly share code, notes, and snippets.

find . -name \* -print0 | perl -MFile::Basename -0nle 'rename $_, dirname($_)."/prefix_".basename($_)'
@adam-lynch
adam-lynch / existsInAny.js
Last active August 29, 2015 13:57
A (probably inefficient) functional approach to determine if any object contains a specific value for a property in an array of objects. Very Haskelly.
var existsInAny = function(needle, propertyName, haystack){
return haystack.map(function(el){return el[propertyName] === needle;}).reduce(function(a,b){return a||b;});
}
/*
# CoffeeScript version
existsInAny = (needle, propertyName, haystack) ->
haystack.map((el)-> el[propertyName] is needle).reduce((a,b)-> a||b)
*/
# thing - {mixed}. Anything you want to get the type of.
getType: do =>
unless @classToType?
@classToType = {}
for type in ['Boolean', 'Number', 'String', 'Function', 'Array', 'Date', 'RegExp', 'Undefined', 'Null']
@classToType["[object #{type}]"] = type
return (thing) =>
className = Object::toString.call thing
return if @classToType[className]? then @classToType[className].toLowerCase() else 'object'
@adam-lynch
adam-lynch / Viewport and scale meta tag.html
Created January 27, 2014 11:01
Viewport and scale meta tag
<meta name="viewport" content="width=device-width, initial-scale=1.0">
/(<a[^>]*?>.*?)?(?!<[^>]*?)([a-zA-Z0-9.!\#$%&'*+\/=?^_`{|}~-])+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*(?![^<]*?>)/gi
@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
@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 / 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 / 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 / _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( /[\]]/, "\\\]" ) + "=([^&#]*)",