Skip to content

Instantly share code, notes, and snippets.

View ziad-saab's full-sized avatar
🔥

Ziad Saab ziad-saab

🔥
View GitHub Profile
@ziad-saab
ziad-saab / reddit.js
Created July 26, 2016 19:15
Reddit MySQL API
var bcrypt = require('bcrypt');
var HASH_ROUNDS = 10;
module.exports = function RedditAPI(conn) {
return {
createUser: function createUser(user, callback) {
// first we have to hash the password...
bcrypt.hash(user.password, HASH_ROUNDS, function(err, hashedPassword) {
if (err) {
@ziad-saab
ziad-saab / iss-promise.js
Created September 25, 2015 19:27
Promises Exercise 3 Possible Solution
var request = require('request');
var prompt = require('prompt');
var Promise = require('bluebird');
var promptPromisified = Promise.promisifyAll(prompt);
var requestPromisified = Promise.promisify(request);
//necessary function for distanceTo
Number.prototype.toRadians = function() {
return this * Math.PI / 180;
}
@ziad-saab
ziad-saab / index.html
Last active August 29, 2015 14:20 — forked from d3noob/.block
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Collapsible Tree Example</title>
<style>
.node circle {
@ziad-saab
ziad-saab / get-roles.js
Last active October 4, 2021 15:52
Get a list of a user's roles from Parse, including child roles, up to a certain depth
// Maximum depth is 3, after that we get a "" error from Parse
function getUserRoles(user) {
var queries = [
new Parse.Query('_Role').equalTo('users', user)
];
for (var i = 0; i < 2; i++) {
queries.push(new Parse.Query('_Role').matchesQuery('roles', queries[i]));
}
return user.rolesPromise = Parse.Query.or.apply(Parse.Query, queries).find().then(
@ziad-saab
ziad-saab / gist:917bdc18252c18d6be7a
Created July 8, 2014 19:55
Convert a number to a short version with K, M, B
// Taken from https://github.com/broofa/jslitmus and prettified
function numberToShortLabel(n) {
if (n == Infinity) {
return 'Infinity';
}
else if (n > 1e9) {
n = Math.round(n/1e8);
return n/10 + 'B';
}
else if (n > 1e6) {
@ziad-saab
ziad-saab / model_Base.js
Created June 20, 2014 21:45
Parse.com and ExtJS 5 base model
Ext.define('MyApp.model.Base', {
extend: 'Ext.data.Model',
fields: [
{
name: 'objectId',
type: 'string'
}
],
@import "compass/css3/shared";
// NOTE:
// All mixins for the 2009 spec have been written assuming they'll be fed property values that
// correspond to the standard spec. Some mixins can be fed values from the 2009 spec, but don't
// rely on it. The `legacy-order` mixin will increment the value fed to it because the 2009
// `box-ordinal-group` property begins indexing at 1, while the modern `order` property begins
// indexing at 0.
// if `true`, the 2009 properties will be emitted as part of the normal mixin call
@ziad-saab
ziad-saab / parse-to-jquery-promise.js
Created July 2, 2013 16:46
Create a jQuery Promise from a Parse promise
Parse.Promise.prototype.toJqueryPromise = function() {
var def = jQuery.Deferred();
this.then(
def.resolve.bind(def),
def.reject.bind(def)
);
return def.promise();
}