Skip to content

Instantly share code, notes, and snippets.

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

saasfreelancer saas786

🏠
Working from home
View GitHub Profile
@saas786
saas786 / headsortails.rb
Created April 28, 2012 07:56 — forked from Denommus/headsortails.rb
Heads or tails
# Shows all the possibilities of a set of coins throwing
# You could as well change "heads" and "tails" for true and false.
def possibilities(a)
results = []
if(a==1)
results << ["heads"]
results << ["tails"]
else
@saas786
saas786 / Ability.java
Created April 28, 2012 08:08 — forked from grignaak/Ability.java
Online ranking algorithm in java
package gaming.online.java;
public class Ability {
private final double mean;
private final double variance;
private Ability(final double mean, final double variance) {
this.mean = mean;
this.variance = variance;
}
@saas786
saas786 / gist:2517043
Created April 28, 2012 08:09 — forked from allex/gist:2515452
getElementsByTagName
/* vim: set ft=javascript: */
// http://dean.edwards.name/weblog/2009/12/getelementsbytagname/
function getElementsByTagName(node, tagName) {
var elements = [], i = 0, anyTag = tagName === "*", next = node.firstChild;
while ((node = next)) {
if (anyTag ? node.nodeType === 1 : node.nodeName === tagName) elements[i++] = node;
next = node.firstChild || node.nextSibling;
while (!next && (node = node.parentNode)) next = node.nextSibling;
}
return elements;
@saas786
saas786 / subclass.py
Created April 28, 2012 08:10
Subclass Example
class Person:
def work(self):
print "i am working"
def eat(self):
print "i am eating"
def sleep(self):
print "i am sleeping"
@saas786
saas786 / gist:2517049
Created April 28, 2012 08:10 — forked from jineeshjohn/gist:2515389
JavaScript Shuffle with for loop
function Shuffle(arr){
var len = arr.length;
for(var i = 0;i<len;i++){
var rand = Math.floor(Math.random()*len);
var randVal = arr[rand];
var temp = arr[i];
arr[i] = randVal;
arr[rand] = temp;
}
return arr;
@saas786
saas786 / gist:2517050
Created April 28, 2012 08:10
Javascript: track jQuery AJAX Requests in Google Analytics
if (typeof _gaq !== "undefined" && _gaq !== null) {
$(document).ajaxSend(function(event, xhr, settings){
_gaq.push(['_trackPageview', settings.url]);
});
}
@saas786
saas786 / gist:2517068
Created April 28, 2012 08:15 — forked from yoren/gist:2514914
Minimize WordPress default query.
function alter_the_query( $request ) {
$dummy_query = new WP_Query(); // the query isn't run if we don't pass any query vars
$dummy_query->parse_query( $request );
// @TODO sometimes this will help reduce queries, but sometimes won't
$args = array(
'showposts' => 1,
'update_post_term_cache' => 0,
'update_post_meta_cache' => 0,
'no_found_rows' => 1 // if showposts = -1, useless
@saas786
saas786 / index.html
Created April 28, 2012 08:15 — forked from tcomaj/index.html
HTML: Boilerplate <head> Section
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<!-- Make a DNS handshake with a foreign domain, so the connection goes faster when the user eventually needs to access it. This works well for loading in assets (like images) from another domain, or a JavaScript library from a CDN. -->
<link rel="dns-prefetch" href="//ajax.googleapis.com" />
<link rel="dns-prefetch" href="//s3.amazonaws.com" />
<!-- Make sure the latest version of IE is used -->
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
@saas786
saas786 / gist:2517088
Created April 28, 2012 08:19 — forked from luetkemj/wp-query-ref.php
WP: Query $args
<?php
/**
* WordPress Query Comprehensive Reference
* Compiled by luetkemj - luetkemj.com
*
* CODEX: http://codex.wordpress.org/Class_Reference/WP_Query
* Source: http://core.trac.wordpress.org/browser/tags/3.3.1/wp-includes/query.php
*/
$args = array(
@saas786
saas786 / tribe-common-libraries.class.php
Created April 28, 2012 08:54 — forked from peterchester/tribe-common-libraries.class.php
Wordpress: -> Class: library management
<?php
/**
* Class for managing overlapping helper plugins. This ensures that we use the latest versions of common code.
*
* Usage: include this file on any plugin that may have shared code BEFORE the 'plugins_loaded' action is completed.
* After including this file, register the helper files using the TribeCommonLibraries::register() instead of including the files directly.
*
* @author Peter Chester
* @version 1.0
*/