Skip to content

Instantly share code, notes, and snippets.

View mohsen1's full-sized avatar

Mohsen Azimi mohsen1

View GitHub Profile
@mohsen1
mohsen1 / domenic.js
Last active August 29, 2015 14:20
Promises and callback
function add (arg1, arg2, cb) {
return (new Promise(reject, resolve) {
if (typeof arg1 !== 'number') {
reject(new TypeError('arg1 should be a number'));
}
if (typeof arg2 !== 'number') {
reject(new TypeError('arg2 should be a number'));
@mohsen1
mohsen1 / 1.json
Last active August 29, 2015 14:16
{
"apiVersion": "1.0.0",
"swaggerVersion": "1.2",
"basePath": "http://swagger.io",
"resourcePath": "/people/@me",
"produces": [
"application/xml",
"application/json"
],
"consumes": [
@mohsen1
mohsen1 / _
Last active August 29, 2015 14:15
Proof of concept using lodash for Backbone by cherry-picking all _.{method}s that Backbone uses from Lodash
keys
uniqueId
isEmpty
bind
once
each
extend
defaults
result
clone
@mohsen1
mohsen1 / download.js
Last active March 30, 2019 05:13
Download Chromecast backgrounds
var https = require('https');
var fs = require('fs');
var url = 'https://raw.githubusercontent.com/dconnolly/chromecast-backgrounds/master/backgrounds.json';
Array.prototype.getLast = function() {
return this[this.length - 1];
};
function logFail(err){
console.log('Failed!');
@mohsen1
mohsen1 / consolidated.json
Created May 21, 2014 18:01
Consolidated JSON Spec
{
"opts": {
"properties": {
"modelPackage": "com.reverb.models",
"apiPackage": "com.reverb.apis",
"groupId": "com.reverb.swagger",
"artifactId": "swagger-client",
"artifactVersion": "1.0.0"
},
"uri": "http://petstore.swagger.wordnik.com/api/api-docs"
@mohsen1
mohsen1 / words.js
Last active December 31, 2015 11:49
1000 most frequently used words
names = [
"A",
"ABLE",
"ABOUT",
"ABOVE",
"ACCORDING",
"ACCOUNT",
"ACROSS",
"ACT",
"ACTION",
@mohsen1
mohsen1 / style.css
Last active December 18, 2015 10:19
Github dark theme This theme uses webkit filters to achive a consistent dark theme across all Github pages.
/* Invert all the things! */
html
{
-webkit-filter: invert(1) grayscale(0.6);
}
/* Execpt these guys... */
img,
.minibutton,
.state-indicator,
@mohsen1
mohsen1 / fs.js
Created May 29, 2013 14:51
Wrong node
var fs = require('fs');
var random = (~~(Math.random() * 1e9)).toString(2);
fs.writeFile('./random.txt', random, function(err){
if(err) console.error(err);
else console.log('file has been written');
});
@mohsen1
mohsen1 / reactor.js
Last active January 15, 2022 21:57
Reactor Pattern in JavaScript
function Event(name){
this.name = name;
this.callbacks = [];
}
Event.prototype.registerCallback = function(callback){
this.callbacks.push(callback);
}
function Reactor(){
this.events = {};
@mohsen1
mohsen1 / classical.md
Last active December 14, 2015 15:09
Classical Inheritance in JavaScript which never uses prototype object. This is bad code. It's here to demonstrate how bad Classical Inheritance is!

Let me introduce you to Classical Inheritance that never uses prototype. This is a bad coding exercise but will teach you the real Classical Inheritance which always compared to prototypal inheritance:

Make a custructor:

function Person(name, age){
  this.name = name;
  this.age = age;
  this.sayHello = function(){return "Hello! this is " + this.name;}
}