Skip to content

Instantly share code, notes, and snippets.

@3emad
3emad / Prototype.js
Last active August 29, 2015 14:13
A small experiment of prototypes
var a = function a(){
this.x = 1;
return this;
}
var l = {
x:1
};
a.prototype.inc = function(){ return this.x+1; }
l.inc = function(){ return this.x+1; }
@3emad
3emad / client.js
Created November 10, 2013 04:10 — forked from epadillas/client.js
// Send cookies for the socket.io handshake (sails.js)
// Based on https://gist.github.com/jfromaniello/4087861
// Socket.io open ticket (started by jfromaniello):
// https://github.com/LearnBoost/socket.io-client/pull/512
var io = require('socket.io-client');
var request = require('request');
var xhr = require('socket.io-client/node_modules/xmlhttprequest');
var xhrOriginal = require('xmlhttprequest');
@3emad
3emad / grep_quries_from_files.php
Created July 12, 2013 18:48
A Regex in php that grabs all the quries that are defined.
chdir('/var/www/website');
$matchingTable = 'sometable';
$regex = 'SELECT(\n|\s|\w|.)*?(?='.$matchingTable.')(\n|\s|\w|.)*?(?=(\'|");)'; // could change to update or delete
$filepaths = glob('*.*');
foreach($filepaths as $filepath){
if(!file_exists(realpath($filepath))){
echo $filepath.PHP_EOL;
continue;
}
@3emad
3emad / summary.markdown
Last active December 15, 2015 17:19
AngularJS Practice Guide Summary

AngularJS Practice Guide Summary

  • Define and group Angular things (dependency injection stuff) in modules.
  • Share data and wrap web server interaction in services.
  • Extend HTML and do DOM manipulation in directives.
  • make Controllers as "thin" as possible.

Using Controllers Correctly

// Source: https://groups.google.com/forum/#!topic/angular/hVrkvaHGOfc
// jsFiddle: http://jsfiddle.net/pkozlowski_opensource/PxdSP/14/
// author: Pawel Kozlowski
var myApp = angular.module('myApp', []);
//service style, probably the simplest one
myApp.service('helloWorldFromService', function() {
this.sayHello = function() {
return "Hello, World!"
var app;
app = (function(){
var myPrivateVariable = "my private content";
var application = {
init: function(){
console.log(myPrivateVariable);
},
@3emad
3emad / class.ux.js
Created August 22, 2012 01:05
UX indicator class for child of form
// UX indicator Main class
var UX = function (wrapperId){
this.wrapperId = wrapperId;
this.type = form;
this.type.parent = this;
this.indicator = '<div class="progress progress-striped active"><div class="bar" style="width: 100%;"></div></div>';
this.errorWrapper = '<div class="alert alert-error" />';
}
UX.prototype.initInidcator = function(id){
@3emad
3emad / gist:2286247
Created April 2, 2012 18:46
Sort select:option list with a callback function
/**
credits to: http://stackoverflow.com/questions/1134976/how-may-i-sort-a-list-alphabetically-using-jquery
: http://stackoverflow.com/questions/278089/javascript-to-sort-contents-of-select-element
and a little hacks there by 3emad
**/
function sortUnorderedOption(select,callback_fun) {
selElem = document.getElementById(select);
var tmpAry = new Array();
for (var i=0;i<selElem.options.length;i++) {
@3emad
3emad / gist:2286103
Created April 2, 2012 18:29
Chrome developer tool bug[network tab]: Double ajax post previewed is repeated
/*
* showed in chrome network posted the same value and returned the same response
* the following code will call action "getBar" twice
* $.post("example.com",{action:'getFoo'},function(data){},"json");
* $.post("example.com",{action:'getBar'},function(data){},"json");
*
* in google chrome network tab, it will show that getFoo is ignored and getBar was called twice, though
* the object response are correct on the javascript end.
*
* work around to this bug:
@3emad
3emad / gist:2285936
Created April 2, 2012 18:12
Changing options position pitfall
/*
* // the following example failed to keep the last index.
*
* temp = selElem.options[0];
* selElem.options[0] = selElem.options[1];
* selElem.options[1] = temp
* return;
*/
var dash = selElem.options[0];
var all = selElem.options[1];