Skip to content

Instantly share code, notes, and snippets.

@gitawego
gitawego / Event.php
Last active February 20, 2020 11:29
Event(NodeJs style) class for PHP
/**
* Created by IntelliJ IDEA.
* User: hongbo
* Date: 4/26/12
* Time: 9:59 AM
*/
class Event
{
@gitawego
gitawego / injector.js
Created December 6, 2012 11:02 — forked from skrat/injector.js
Injector.js - Dependency Injection
/**
* @constructor
*/
function Injector() {
/**
* @type {!Object.<string, function(Injector=): !Object>}
*/
this.factories = {};
/**
* @type {!Object.<string, !Object>}
@gitawego
gitawego / declare.js
Created December 6, 2012 15:35
a simple method for class declaration
function declare(Parent, props) {
"use strict";
var Factory, Super, i
, __construct = props.__construct || function () {
}
, toArr = function (args) {
var a = [];
for (var i = 0, l = args.length; i < l; i++) {
a[i] = args[i];
}
@gitawego
gitawego / serverReachable.js
Created December 10, 2012 14:00
a simple way to detect if server is reachable
//event naviagor.onLine isn't fiable.
function serverReachable() {
// IE vs. standard XHR creation
var x = new ( window.ActiveXObject || XMLHttpRequest )( "Microsoft.XMLHTTP" ),
s;
x.open(
// requesting the headers is faster, and just enough
"HEAD",
// append a random string to the current hostname,
// to make sure we're not hitting the cache
@gitawego
gitawego / Injector.js
Created December 10, 2012 17:02
improved version of Injector.js
/**
* @constructor
*/
function Injector() {
/**
* @type {!Object.<string, function(Injector=): !Object>}
*/
this.factories = {};
/**
* @type {!Object.<string, !Object>}
/* best breakpoints */
@media (min-width:320px) { /* smartphones, portrait iPhone, portrait 480x320 phones (Android) */ }
@media (min-width:480px) { /* smartphones, Android phones, landscape iPhone */ }
@media (min-width:600px) { /* portrait tablets, portrait iPad, e-readers (Nook/Kindle), landscape 800x480 phones (Android) */ }
@media (min-width:801px) { /* tablet, landscape iPad, lo-res laptops ands desktops */ }
@media (min-width:1025px) { /* big landscape tablets, laptops, and desktops */ }
@media (min-width:1281px) { /* hi-res laptops and desktops */ }
/* to work better with 960 grids: */
@media (min-width:320px) { /* smartphones, iPhone, portrait 480x320 phones */ }
@media (min-width:481px) { /* portrait e-readers (Nook/Kindle), smaller tablets @ 600 or @ 640 wide. */ }
@gitawego
gitawego / newton.js
Last active December 26, 2015 05:28
Newton's Method to get square root
function sqrt_iter(g, y) {
if (Math.abs(g*g - y) < 0.000000000000001) {
return g;
} else {
return sqrt_iter( (g + y / g)/2, y );
}
}
function sqrt(y) {
return sqrt_iter(1.0, y);
}
function fact1(x) {
if(x<=1) return 1;
else return x*fact(x-1);
}
function fact2(x){
var res=x;
while(--x){
res *= x;
#!/bin/bash
echo "Stopping Qmail - Japan it UP!"
/etc/init.d/qmail stop
echo "Clearing the Mail Queue"
cd /var/qmail/queue/info
define(function(){
var supportsCSSText = getComputedStyle(document.body).cssText !== "";
return {
/**
* @method domToImage
* @param {HTMLElement} origElem
* @param {function(Error,Image)} callback
* @param {Object|String} style
* @param {String} style.href
* @param {Number} style.width