Skip to content

Instantly share code, notes, and snippets.

View egm0121's full-sized avatar
⚛️
https://www.generationatomic.org/why-nuclear/

Giulio Dellorbo egm0121

⚛️
https://www.generationatomic.org/why-nuclear/
View GitHub Profile
@egm0121
egm0121 / gist:4491817
Created January 9, 2013 09:24
jsonP Twitter Search Example
(function (q) {
window.a = function (d) {
while (d.results.length) document.body.innerHTML += '<li>' + d.results.pop().text;
};
var js = document.createElement('script'),
first = document.getElementsByTagName('script')[0];
js.src = 'http://search.twitter.com/search.json?q=' + q + '&callback=a';
first.parentNode.insertBefore(js, first);
})('upcloo');
@egm0121
egm0121 / CometServer.php
Last active December 11, 2015 12:48
http streaming tracker
<?php
//no limite di tempo
set_time_limit(0);
//error_reporting(E_RECOVERABLE_ERROR);
//include 'ACometResponse.php';
class CometServer {
@egm0121
egm0121 / snippet.js
Last active December 11, 2015 12:49
snippet
(function me(){
$.ajax( "http://127.0.0.1:8080/channel1/?token="+parseInt(Math.random()*10e2)+"&else=boo" )
.done(me)
.fail(me)
})()
<script src="socket.io/socket.io.js"></script>
<script>
var socket = io.connect('http://localhost');
socket.on('news', function (data) {
console.log(data);
});
socket.emit('my other event', { my: 'data' });
</script>
Ciao, sono un piccolo socket.io
@egm0121
egm0121 / index.html
Created January 31, 2013 13:48
real time user tracking socket.io + Redis
<script src="socket.io/socket.io.js"></script>
<script>
var socket = io.connect('http://localhost');
socket.on('news', function (data) {
console.log(data);
});
socket.emit('setinfo',{'bella merda':navigator.userAgent})
</script>
@egm0121
egm0121 / myCtrl.js
Last active December 19, 2015 23:59
Angular Controller Constructor + proto methods
.controller('myCtrl', function(){
var Controller = function($scope) {
var that = this;
this.$scope = $scope;
this.init.apply(this,[].slice.call(arguments,0));
};
@egm0121
egm0121 / helperEs5Keys.js
Created July 23, 2013 13:46
ng-repeat of props in {} keep no default sorting
$scope.objKeys= function(o){
return angular.isObject(o) ? Object.keys(o) : [];
};
@egm0121
egm0121 / gist:d8a48d137b215b11b74f
Created May 7, 2014 08:28
hide console.log in prod
!function(a,b){var c,d={},e=function(){},f=function(){d.history=d.history||[],d.history.push(arguments),this.console&&original.log(Array.prototype.slice.call(arguments))},g=["assert","clear","count","debug","dir","dirxml","error","exception","group","groupCollapsed","groupEnd","info","log","markTimeline","profile","profileEnd","table","time","timeEnd","timeStamp","trace","warn"],h=g.length,i=window.console=window.console||{};try{for(;h--;)c=g[h],i[c]="log"==c?f:e}catch(j){}b._unlockConsole=function(){i.log=a,d.history.map(function(a){i.log.apply(i,Array.prototype.slice.call(a))})}}(null!=console&&"object"==typeof console&&"log"in console?console.log:function(){},this);
@egm0121
egm0121 / style.less
Created January 12, 2016 14:52
atom custom styles
/*
* Your Stylesheet
*
* This stylesheet is loaded when Atom starts up and is reloaded automatically
* when it is changed.
*
* If you are unfamiliar with LESS, you can read more about it here:
* http://www.lesscss.org
*/
@egm0121
egm0121 / getWatchers.js
Created March 10, 2017 13:14
angular.js Dom based active watchers counter
function getWatchers(root) {
root = angular.element(root || document.documentElement);
var watcherCount = 0;
var scopeArr = [];
function getElemWatchers(element) {
var isolateWatchers = getWatchersFromScope(element.data().$isolateScope);
var scopeWatchers = getWatchersFromScope(element.data().$scope);
var watchers = scopeWatchers.concat(isolateWatchers);
angular.forEach(element.children(), function (childElement) {
watchers = watchers.concat(getElemWatchers(angular.element(childElement)));