Skip to content

Instantly share code, notes, and snippets.

View adeolaawoyemi's full-sized avatar
🏠
Working from home

Adeola Awoyemi adeolaawoyemi

🏠
Working from home
  • Yahoo
  • San Jose, CA
View GitHub Profile
@adeolaawoyemi
adeolaawoyemi / switch_protocol.js
Created November 7, 2012 10:50
Javascript protocol (SSL) resource switch
script.src = ('https:' == document.location.protocol ? 'https' : 'http') + '://my.url.com/file.ext';
@adeolaawoyemi
adeolaawoyemi / gist:3859479
Created October 9, 2012 15:21
parse JSON object in AS3
private function parseJSON(o:*, spaces:int = 1):String {
var str:String = "";
if(getTypeof(o) == "object") {
str += "{\n";
for(var i:* in o) {
str += getSpaces(spaces) + i + "=";
if(getTypeof(o[i]) == "object" || getTypeof(o[i]) == "array") {
str += parseJSON(o[i], spaces + 1) + "\n";
} else {
var type:String = getTypeof(o[i]);
@adeolaawoyemi
adeolaawoyemi / gist:3040782
Created July 3, 2012 16:18
Batch-import databases
for d in *.sql; do echo "Database ${d/.sql/} will be created" && mysql -uroot -e "create database ${d/.sql/};" && mysql -uroot ${d/.sql/} < $d && echo "Done creating and populating ${d/.sql/}"; done
@adeolaawoyemi
adeolaawoyemi / gist:3016923
Created June 29, 2012 09:35
parse list of videoIDs (and sanitise)
var playlist = "-123 ,456-, x789";
var videos = playlist.split(',');
var videos_count = videos.length;
for( var i = 0; i < videos_count; i++ ) {
// sanitise and remove non-numeric characters
var video_id = Number(videos[i].replace(/\D/g, ''));
// test
trace('videoID: [' + video_id + ']');
}
@adeolaawoyemi
adeolaawoyemi / gist:3014238
Created June 28, 2012 21:58
iPhone Mobile Safari HTML5 Video access log
192.168.0.105 - - [28/Jun/2012:22:48:07 +0100] "GET /html5video HTTP/1.1" 301 323
192.168.0.105 - - [28/Jun/2012:22:48:07 +0100] "GET /html5video/ HTTP/1.1" 200 1100
192.168.0.105 - - [28/Jun/2012:22:48:08 +0100] "GET /html5video/chrome_japan.mp4 HTTP/1.1" 206 2
192.168.0.105 - - [28/Jun/2012:22:48:08 +0100] "GET /html5video/chrome_japan.mp4 HTTP/1.1" 200 9407755
192.168.0.105 - - [28/Jun/2012:22:48:09 +0100] "GET /html5video/chrome_japan.mp4 HTTP/1.1" 304 -
192.168.0.105 - - [28/Jun/2012:22:48:17 +0100] "GET /html5video/chrome_japan.mp4 HTTP/1.1" 206 2
192.168.0.105 - - [28/Jun/2012:22:48:17 +0100] "GET /html5video/chrome_japan.mp4 HTTP/1.1" 200 9407755
192.168.0.105 - - [28/Jun/2012:22:48:18 +0100] "GET /html5video/chrome_japan.mp4 HTTP/1.1" 206 65536
192.168.0.105 - - [28/Jun/2012:22:48:19 +0100] "GET /html5video/chrome_japan.mp4 HTTP/1.1" 206 65536
192.168.0.105 - - [28/Jun/2012:22:48:17 +0100] "GET /html5video/chrome_japan.mp4 HTTP/1.1" 206 9325219
@adeolaawoyemi
adeolaawoyemi / gist:2955101
Created June 19, 2012 16:26
Force IE9 to use IE9 Standard mode, ALWAYS
X-UA-Compatible: IE=edge,chrome=1
@adeolaawoyemi
adeolaawoyemi / gist:2955082
Created June 19, 2012 16:23
add header to apache response (enable CORS)
# Enable CORS
Header append Access-Control-Allow-Origin *
@adeolaawoyemi
adeolaawoyemi / gist:2954331
Created June 19, 2012 13:50
Automatically select all text in a TextField when user clicks inside it
my_tf.addEventListener(FocusEvent.FOCUS_IN, onFocusIn);
my_tf.addEventListener(FocusEvent.FOCUS_OUT, onFocusOut);
function onFocusIn(event:FocusEvent):void {
setTimeout(event.target.setSelection, 50, 0, event.target.text.length);
}
function onFocusOut(event:FocusEvent):void {
event.target.setSelection(0,0);
}
@adeolaawoyemi
adeolaawoyemi / gist:2933733
Created June 15, 2012 00:02
Simulate keypress usnig javascript (doesn't work in Safari or Chrome)
var elem = (document.getElementsByClassName('mentionsTextarea'))[0];
elem.value = 'www.youtube.com';
elem.blur();
elem.value += ' ';
var evt = document.createEvent('KeyboardEvent');
evt.initKeyEvent(
'keypress',
true, // key down events bubble
true, // and they can be cancelled
null, // Use the default view
@adeolaawoyemi
adeolaawoyemi / gist:2143454
Created March 21, 2012 01:32
jQuery latest
http://code.jquery.com/jquery-latest.js