Neonsunburst Content Class

package com.neonsunburst {
	
	import flash.display.MovieClip;
	import flash.events.*;
	import com.gskinner.motion.GTween;
	import com.gskinner.motion.easing.*;
	
	public class Content extends MovieClip{
		
		var model:Model;
		
		public function Content (aModel:Model)
		{
			model = aModel;
			model.addEventListener(Event.CHANGE, update);
		}
		public function update(event:Event) : void {
			trace (this + " model updated");
			new GTween(this.slides.getChildAt(model.getCurrentPage() - 1), .5, {alpha:1}, {ease:Sine.easeIn});
			new GTween(this.slides.getChildAt(model.getPreviousPage() -1), .5, {alpha:0}, {ease:Sine.easeIn});
		}
		public function engage() : void {
			new GTween(this.hifiA, .5, {alpha:0}, {ease:Sine.easeIn});
		}
		public function unEngage() : void {
			new GTween(this.hifiA, .5, {alpha:1}, {ease:Sine.easeIn});
		}
	}
}

source

rand64

#include "stdlib.h"
#include "stdint.h"

uint64_t rand64()
{
	// Combin 4 parts of low 16-bit of each rand()
	uint64_t R0 = (uint64_t)random() << 48;
	uint64_t R1 = (uint64_t)random() << 48 >> 16;
	uint64_t R2 = (uint64_t)random() << 48 >> 32;
	uint64_t R3 = (uint64_t)random() << 48 >> 48;
	return R0 | R1 | R2 | R3;
}

#define SEGS 100
#define TIMES 50000

// Show segments
int main (int argc, char const *argv[])
{
	const uint64_t SEG = UINT64_MAX / SEGS;
	int f[SEGS] = { 0 };
	for(int i = 0; i < TIMES; ++i)
	{
		uint64_t r = rand64();
		f[r / SEG]++;
	}
	for (int i = 0; i < SEGS; ++i)
	{
		printf("#%2d: (%20llu ~ %20llu) %dn", i, i * SEG, (i + 1) * SEG - 1, f[i]);
	}
	return 0;
}

source

Remove Encoded Spans From SlideDeck Title

jQuery(document).ready(function(){
    jQuery('.slidedeck dt').each(function(){
        this.innerHTML = this.innerHTML.replace(/&lt;(.*)&gt;(.*)&lt;(.*)&gt;/,'$2');
    });
});

source

Meta Tags – config your Web for iPhone

<!--Change the Appearance of the iPhone's Status Bar-->
<meta name="apple-mobile-web-app-status-bar-style" content="default" />
<!--The values that you can change for content are default (white), black and black-translucent.-->

<!--Prevent Users From Scaling (Pinching)-->
<meta name="viewport" content="user-scalable=no, width=device-width" />

<!--Icon for Bookmarked Website - 57 x 57 pixel .png file-->
<link rel="apple-touch-icon" href="bookmark-icon.png" />

<!--Create a Splash Screen for iPhone Website - 320x460 .png file-->
<link rel="apple-touch-startup-image" href="splash_screen.png" />

source

Base 58 encode (used for flic.kr short urls)

/*
 Function used to return flickr short url from a photo id.
 example of usage
 var shortFlickrURL:String = 'www.flic.kr/p/' + Base58Encoder.encode(Number('4725679319') );
/// returns <a href="http://www.flic.kr/p/8cAkPD">www.flic.kr/p/8cAkPD</a>
/// short url for this full url <a href="http://www.flickr.com/photos/ninjaparade/4725679319/" >http://www.flickr.com/photos/ninjaparade/4725679319/</a>


*/

package {

	/**
	 * @author ninjaparade
	 */
	public class Base58Encoder {

		
		public static function encode( num : Number ) : String
		{
		var alphabet : String = '123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ' ;
			var base_count : int = alphabet.length;
			var encode : String = "";
			while(num >= base_count) {
				var div : int = num / base_count;
				var mod : int = (num - base_count * Math.round(div) );
				encode = alphabet.charAt(mod) + encode;
				num = Math.round(div);
			}

			if(num) 
			{
				encode = alphabet.charAt(num) + encode;
			}
			return encode;
		}
	}
}

source

get IP

function getip()
{
    return (isset($_SERVER['HTTP_X_REAL_IP'])) ? $_SERVER['HTTP_X_REAL_IP'] : $_SERVER['REMOTE_ADDR'] ;
}

source

Return Array of Overridden Methods in Ruby Subclasses

# thanks to the answer here:
# <a href="http://stackoverflow.com/questions/3488203/how-do-i-see-where-in-the-class-hierarchy-a-method-was-defined-and-overridden-in" >http://stackoverflow.com/questions/3488203/how-do-i-see-where-in-the-class-hierarchy-a-method-was-defined-and-overridden-in</a>
class Object
  def self.overridden_methods(parent_class = Object, within_tree = true)
    if within_tree
      defined_methods = ancestors[0..ancestors.index(parent_class) - 1].map { |object| object.instance_methods(false) }.flatten.uniq
      parent_methods = superclass.instance_methods
    else
      defined_methods = instance_methods(false)
      parent_methods = parent_class.instance_methods
    end
    defined_methods & parent_methods
  end
  
  def overridden_methods(parent_class = Object, within_tree = true)
    self.class.overridden_methods(parent_class, within_tree)
  end
  
  def self.overrides?(method, parent_class = Object, within_tree = true)
    overridden_methods(parent_class, within_tree).include?(method.to_s)
  end
  
  def overrides?(method, parent_class = Object, within_tree = true)
    self.class.overrides?(method, parent_class, within_tree)
  end
end

class ParentModel < Object
  def save; end
end

class ChildModel < ParentModel
  def save; end
  def create; end
  def to_s; end
end

class AnotherChildModel < ParentModel
  def save; end
end

class GrandChildModel < ChildModel
  def create; end
end

# what have you overridden from the base `Object` class
p ParentModel.overridden_methods(Object)
#=> []
p ParentModel.overridden_methods(Object, false)
#=> []
p ChildModel.overridden_methods(Object)
#=> ["to_s", "save"]
p ChildModel.overridden_methods(Object, false)
#=> ["to_s"]
p ChildModel.overridden_methods(ParentModel)
#=> ["to_s", "save"]
p ChildModel.overridden_methods(ParentModel, false)
#=> ["to_s", "save"]
p AnotherChildModel.overridden_methods(Object)
#=> ["save"]
p AnotherChildModel.overridden_methods(Object, false)
#=> []
p AnotherChildModel.overridden_methods(ParentModel)
#=> ["save"]
p AnotherChildModel.overridden_methods(ParentModel, false)
#=> ["save"]
p GrandChildModel.overridden_methods(Object)
#=> ["create", "to_s", "save"]
p GrandChildModel.overridden_methods(Object, false)
#=> []
p GrandChildModel.overridden_methods(ParentModel)
#=> ["create", "to_s", "save"]
p GrandChildModel.overridden_methods(ParentModel, false)
#=> []
p GrandChildModel.overridden_methods(ChildModel)
#=> ["create"]
p GrandChildModel.overridden_methods(ChildModel, false)
#=> ["create"]

# note, this probably won't work with modules overriding methods, it just needs to be tweaked a little more

source

Remove Encoded Spans From SlideDeck Title

jQuery('.slidedeck dt').each(function(){
	this.innerHTML = this.innerHTML.replace(/&lt;(.*)&gt;(.*)&lt;(.*)&gt;/,'$2'); 
});

source

redirect index.htm and index.html to root

RewriteEngine On
RewriteBase /
RewriteRule ^index.html?$ / [NC,R,L]

source

Find total size for some files

find . -type f -mtime -30 -exec ls -l {} ; | awk '{ s+=$5 } END { print s }'

source