Skip to content

Instantly share code, notes, and snippets.

View getify's full-sized avatar
💭
Just coding

Kyle Simpson getify

💭
Just coding
View GitHub Profile
// 1: how could you rewrite the following to make it shorter?
if (foo) {
bar.doSomething(el);
} else {
bar.doSomethingElse(el);
}
// ------------------------------------
$("#foo").click(function(e){
if (e.clientX) {
// native mouse click
}
else {
// triggered mouse click
}
});
for (var i = 0, j = foo.length; i < j; i++) {
// do stuff
}
for (var i = foo.length; i;) {
// first usage in loop: blah[--i]
// do stuff slightly faster in reverse order
}
// HOWTO: load LABjs itself dynamically!
// inline this code in your page to load LABjs itself dynamically, if you're so inclined.
(function (global, oDOC, handler) {
var head = oDOC.head || oDOC.getElementsByTagName("head");
function LABjsLoaded() {
// do cool stuff with $LAB here
}
char* executeProcess(char** args) {
int p[2], p2[2], pid, output_length = 100, current_size = 0, num_args = 3, i, child_stat;
bool error = false;
char cread;
char* output = NULL;
char** cmd_args;
std::string cmd(args[1]);
// take off args[0], since will be sent into stdin of process
std::string input_data(args[0]);
I noticed you are hotlinking to http://labjs.com/js/LAB.js.
While I'm thrilled that you've found a use for LABjs, my
server is not a CDN and is not set up to handle the bandwidth
load your high traffic site is sending at it. I've added a
note to the file to help explain that to your users. Please
stop hotlinking.
@getify
getify / gist:670840
Created November 10, 2010 13:22
using LABjs to load from a CDN, with simple error detection (& timeout), and a local load fallback
function test_jQuery() { jQuery(""); }
function success_jQuery() { alert("jQuery is loaded!");
var successfully_loaded = false;
function loadOrFallback(scripts,idx) {
function testAndFallback() {
clearTimeout(fallback_timeout);
if (successfully_loaded) return; // already loaded successfully, so just bail
try {
scripts[idx].test();
@getify
getify / gist:671048
Created November 10, 2010 16:12
using join() and regex to count occurrences of some string in an array
function count_str_occurrences(str,arr) {
var arr_str = arr.join(","),
regex = new RegExp("(?:^|,)"+str+"(?:,|$)","g"),
tmp;
if (tmp = arr_str.match(regex)) {
return tmp.length;
}
return 0;
}
@getify
getify / gist:675496
Created November 13, 2010 17:18
detecting if flash plugin is installed
var _flash_installed = ((typeof navigator.plugins != "undefined" && typeof navigator.plugins["Shockwave Flash"] == "object") || (window.ActiveXObject && (new ActiveXObject("ShockwaveFlash.ShockwaveFlash")) != false));
@getify
getify / gist:701970
Created November 16, 2010 15:59
how to use jQuery.noConflict() to manage multiple versions of jQuery on same page
<html>
<head>
<script src="jquery-1.3.3"></script>
<script>var $jq133 = jQuery.noConflict(true);</script>
<!-- other stuff -->
<script src="jquery-1.4"></script>
<script>var $jq14 = jQuery.noConflict(true);</script>