Skip to content

Instantly share code, notes, and snippets.

View dreamyguy's full-sized avatar
👨‍💻 Code-bending

Wallace Sidhrée dreamyguy

👨‍💻 Code-bending
View GitHub Profile
@dreamyguy
dreamyguy / modernizr.ios.js
Last active April 9, 2018 11:30
Modernizr tests to detect iOS devices.
// iOS Detection
// Clumsy but handy way to detect iOS devices and refer to them when needed.
Modernizr.addTest('ipad', function () {
return !!navigator.userAgent.match(/iPad/i);
});
Modernizr.addTest('iphone', function () {
return !!navigator.userAgent.match(/iPhone/i);
});
@dreamyguy
dreamyguy / iTerm tricks
Created December 8, 2013 08:58
iTerm tricks!
::Turn off system bell on iTerm::
iTerm1
Bookmarks > Manage Profiles > Terminal Profiles > Default > Silence Terminal Bell
iTerm2
Preferences > Profiles > Tab:Terminal > Notifications > Silence Bell
@dreamyguy
dreamyguy / gimme-some-love.js
Created March 27, 2014 15:28
javascript - gimme some love!
var gimme = (function(){
return {
some : function() {
return window.parent.document.createElement('love');
}
};
})();
gimme.some();
@dreamyguy
dreamyguy / ezinst
Last active September 14, 2015 08:50
ezinst - install perl dependencies easily (as long as one trusts the source)
#!/bin/sh
echo aptitude install "cpan-lib`echo $1|sed -e 's/\\(::\\|\/\\)/-/g'|tr 'A-Z' 'a-z'`-perl"
sudo aptitude install --allow-untrusted --assume-yes cpan-lib`echo $1|sed -e 's/\\(::\\|\/\\)/-/g'|tr 'A-Z' 'a-z'`-perl ||
echo aptitude install "lib`echo $1|sed -e 's/\\(::\\|\/\\)/-/g'|tr 'A-Z' 'a-z'`-perl"
sudo aptitude install --allow-untrusted --assume-yes lib`echo $1|sed -e 's/\\(::\\|\/\\)/-/g'|tr 'A-Z' 'a-z'`-perl
# use example: ezinst Catalyst::View::TT
@dreamyguy
dreamyguy / check-if-function-exists.js
Last active August 29, 2015 14:01
Check if function exists, through the console.
// a loose check, to see if object exists
if (something) {
console.log('%c something() is present! ', 'background: #bada55; color: black');
} else {
console.log('%c something() is NOT present! ', 'background: #de1e7e; color: white');
}
// a strict check, object must be a function
if (typeof(something) === 'function') {
console.log('%c something() is present! ', 'background: #bada55; color: black');
@dreamyguy
dreamyguy / tt-using-dumper-to-find-data-structure.md
Last active April 19, 2017 08:46
How to find data structure on Template Toolkit with Dumper
@dreamyguy
dreamyguy / logMessage1-import.js
Last active January 24, 2018 13:58
A way to see console.log() messages without breaking old browsers AND only on dev servers
import {ENV} from '../../env'; // (ENV = 'dev' || 'prod')
export default function logMessage(message, styles) {
// 'ENV' will establish if this should be rendered or not.
// Since it's set to 'dev' by default, 'console.log' messages
// will not output in production.
if (ENV === 'dev' && typeof parent.window.console === 'object') {
parent.window.console.log(message, styles);
}
}
@dreamyguy
dreamyguy / inject-script.js
Created September 11, 2014 10:02
Inject script tag into body, with callback
// this takes into consideration IE7+
// http://msdn.microsoft.com/en-us/library/hh180173%28v=vs.85%29.aspx
function injectjs(url) {
injs = document.createElement('script');
injs.src = url;
injs.type = 'text/javascript';
injs.async = true;
if(injs.addEventListener) {
injs.addEventListener('load', callback, false);
}
@dreamyguy
dreamyguy / cookie-management.js
Created September 11, 2014 10:30
Create, read and erase cookies
@dreamyguy
dreamyguy / randomly-load-functions.html
Last active August 29, 2015 14:07
Load 1 out of N number of javascript functions randomly
<!DOCTYPE html>
<html>
<head>
<title>Random Functions</title>
<meta name="viewport" content="width=device-width, minimum-scale=1, maximum-scale=1">
</head>
<body>
<div id="top" style="height: 400px"></div>
<div id="bottom" style="height: 400px"></div>
<script type="text/javascript">