Skip to content

Instantly share code, notes, and snippets.

😍
Back in OSS business

Mohsen Azimi mohsen1

😍
Back in OSS business
Block or report user

Report or block mohsen1

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@mohsen1
mohsen1 / domenic.js
Last active Aug 29, 2015
Promises and callback
View domenic.js
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'));
View 1.json
{
"apiVersion": "1.0.0",
"swaggerVersion": "1.2",
"basePath": "http://swagger.io",
"resourcePath": "/people/@me",
"produces": [
"application/xml",
"application/json"
],
"consumes": [
@mohsen1
mohsen1 / _
Last active Aug 29, 2015
Proof of concept using lodash for Backbone by cherry-picking all _.{method}s that Backbone uses from Lodash
View _
keys
uniqueId
isEmpty
bind
once
each
extend
defaults
result
clone
@mohsen1
mohsen1 / download.js
Last active Mar 30, 2019
Download Chromecast backgrounds
View download.js
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
Consolidated JSON Spec
View consolidated.json
{
"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 Dec 31, 2015
1000 most frequently used words
View words.js
names = [
"A",
"ABLE",
"ABOUT",
"ABOVE",
"ACCORDING",
"ACCOUNT",
"ACROSS",
"ACT",
"ACTION",
@mohsen1
mohsen1 / style.css
Last active Dec 18, 2015
Github dark theme This theme uses webkit filters to achive a consistent dark theme across all Github pages.
View style.css
/* Invert all the things! */
html
{
-webkit-filter: invert(1) grayscale(0.6);
}
/* Execpt these guys... */
img,
.minibutton,
.state-indicator,
View fs.js
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 Apr 22, 2020
Reactor Pattern in JavaScript
View reactor.js
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 Dec 14, 2015
Classical Inheritance in JavaScript which never uses prototype object. This is bad code. It's here to demonstrate how bad Classical Inheritance is!
View classical.md

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;}
}
You can’t perform that action at this time.