Skip to content

Instantly share code, notes, and snippets.

View Lazhari's full-sized avatar
:octocat:
Working from home

Lazhari Lazhari

:octocat:
Working from home
View GitHub Profile
@Lazhari
Lazhari / mongoose-promise.js
Last active February 11, 2016 11:58
ECMAScript 6 Promise for Node.js
const Article = require('./models/article');
function getArticles(callback) {
callback = callback || function () {};
return new Promise((resolve, reject) => {
Article.find({}, (err, articles) => {
if(err) {
reject(err);
return callback(err);
}
@Lazhari
Lazhari / readme.md
Created December 31, 2015 11:57
JSLint: Using a function before it's defined error
/*jslint latedef:false*/
@Lazhari
Lazhari / generate-ssl-openssl.md
Created December 14, 2015 14:47
Generate SSL certification using openssl
openssl genrsa -out server-key.pem 1024
openssl req -new -key server-key.pem -out server-csr.pem
openssl x509 -req -in server-csr.pem -signkey server-key.pem -out server-cert.pem
@Lazhari
Lazhari / readme.md
Created November 18, 2015 12:02
Use Bitbucket repo with openshift
  1. Clone your repository
$ git clone <bitbucket-repo-url>
  1. Add the remote origin for openshift

Your local clone has then your other repo (bitbucket etc.) as remote repo. Your remote repo is stored with the alias "origin" (the default alias used by git if you clone). You then add the openshift repo as remote to your clone. You do that while explicitly using an alias for the remote repo you add - I'm using "openshift" as alias here:

@Lazhari
Lazhari / test.js
Created November 12, 2015 16:57
Remove element from an array using underscore
var array3 = _.without(array3, _.findWhere(array3, {_id: push._id}));
@Lazhari
Lazhari / Error-mount-partition.md
Created October 11, 2015 21:15
wrong fs type, bad option, bad superblock on /dev/sdaX

Error

wrong fs type, bad option, bad superblock on /dev/sdaX,
missing codepage or helper program, or other error
In some cases useful info is found in syslog - try
dmesg | tail  or so

Solution

@Lazhari
Lazhari / vegenere.class.js
Created September 26, 2015 20:32
Example Node.js 4.0.0/ES6 : Vigenère cipher Class
'use strict';
class VigenereCipher {
constructor(key) {
this.key = key;
}
crypt(text) {
var cypher = '';
text = text.toUpperCase();
@Lazhari
Lazhari / install-scrapy.md
Last active September 26, 2015 04:39
If pip install scrapy don't work in ubuntu 15.04 try this command
$ sudo apt-get install python-dev libffi-dev libssl-dev libxml2-dev libxslt1-dev
$ pip install scrapy

@Lazhari
Lazhari / coupon.js
Created September 21, 2015 16:52
Running CRUD methods in a remote method for a loopback model
module.exports = function(Coupon) {
Coupon.status = function(cb) {
var currentDate = new Date();
Coupon.count({expiredDate: {gt : currentDate}}, function(err, nbCoupons) {
return cb(err, nbCoupons);
});
};
Coupon.expirationStatus = function(couponId, cb) {
var currentDate = new Date();
Coupon.findById(couponId, function(err, instance) {
@Lazhari
Lazhari / parse-csv.py
Created September 2, 2015 16:48
Parsing CSV file
def parse_file(datafile):
name = ""
data = []
with open(datafile,'rb') as f:
r = csv.reader(f)
name = r.next()[1]
header = r.next()
data = [row for row in r]
return (name, data)