Skip to content

Instantly share code, notes, and snippets.

View jboulhous's full-sized avatar

Jamal Boulhous jboulhous

  • Morocco, Africa
View GitHub Profile
@jboulhous
jboulhous / getGistFile.js
Created February 24, 2016 00:34
get gist file with $.ajax
function getGistFile (gist, filename, cb) {
$.ajax({
url: 'https://api.github.com/gists/' + gist,
type: 'GET',
dataType: 'jsonp'
}).success( function(gistdata) {
var content = gistdata.data.files[filename].content;
cb(null, JSON.parse(content))
}).error( function(e) {
cb(e)
[
{
"text": "Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.",
"author": "Martin Golding"
},
{
"text": "All computers wait at the same speed.",
"author": "Unknown"
},
{
var cb = _.compose(_.identity, console.log.bind(console));
asyncFunctionThatReturnsNullResult(cb);
// => null {result: [Results..]}
@jboulhous
jboulhous / isSunday.js
Created March 18, 2014 03:24
moment isSunday plugin
/*
License
do waht the fuck you want to public license
*/
(function () {
var moment;
moment = this.moment;
moment.fn.isSunday = function (start) {
return this.day() === 0
function logRenders () {
_.each(Template, function (template, name) {
var oldRender = template.rendered;
var counter = 0;
template.rendered = function () {
console.log(name, "render count: ", ++counter);
oldRender && oldRender.apply(this, arguments);
};
});
@jboulhous
jboulhous / sessionLog.js
Created September 13, 2013 21:29
log Session in the browser
sessionLog = (function(){
var loggers = {};
function sessionLog(key,stop){
if(key in loggers) loggers[key].stop();
if(stop) return;
else {
loggers[key] = Deps.autorun(function(){
console.log('Session.get("'+key+'") : ',Session.get(key));
});
@jboulhous
jboulhous / isValidURL.js
Created September 4, 2013 13:40
Valid Url
// http://stackoverflow.com/questions/1303872/trying-to-validate-url-using-javascript
window.isValidURL = (function() {// wrapped in self calling function to prevent global pollution
//URL pattern based on rfc1738 and rfc3986
var rg_pctEncoded = "%[0-9a-fA-F]{2}";
var rg_protocol = "(http|https):\\/\\/";
var rg_userinfo = "([a-zA-Z0-9$\\-_.+!*'(),;:&=]|" + rg_pctEncoded + ")+" + "@";
var rg_decOctet = "(25[0-5]|2[0-4][0-9]|[0-1][0-9][0-9]|[1-9][0-9]|[0-9])"; // 0-255
@jboulhous
jboulhous / url.js
Created September 2, 2013 13:55
Random urls using http://chancejs.com/
chance.url = function(){
return 'http://' + this.domain() + '/' + this.sentence().replace(/ /g,'_') + 'html';
};
@jboulhous
jboulhous / serach-facebook-pages.js
Created August 5, 2013 03:39
Seach for facebook pages
function getUrl(query,type,callback){
var access = Meteor.user().services.facebook.accessToken
var url = 'https://graph.facebook.com/search?'
url += $.param({
q:query,
type : type,
access_token : access
});
return $.get(url,callback);
}
define([
"underscore",
"backbone",
"marionette",
"vent"
],
/**
* Creates the primary `Marionette.Application` object that runs the admin framework. Provides a central point
* from which all other sub-applications are started, shown, hidden, and stopped.