Skip to content

Instantly share code, notes, and snippets.

View hassansin's full-sized avatar
👋
Working from home

Hassansin hassansin

👋
Working from home
View GitHub Profile
@hassansin
hassansin / module.js
Created December 20, 2014 11:23
node.js - require module multiple times results in same object
//has to return object
module.exports = {
key: 'Hello'
}
@hassansin
hassansin / deploy.sh
Created May 18, 2015 08:41
Deploy Node app with bash
#!/bin/env sh
USER=ubuntu
SERVER=example.com
DESTINATION=/var/www/ics-feed
git archive -o latest.zip HEAD
scp latest.zip $USER@$SERVER:$DESTINATION
ssh $USER@$SERVER " \
mkdir -vp $DESTINATION && cd $DESTINATION \
@hassansin
hassansin / mongoose-examples.js
Last active August 29, 2015 14:25
Mongoose by Examples
/*
Stream / QueryStreams
----------------------------
Ref: http://mongoosejs.com/docs/api.html#querystream_QueryStream
one chunk == one document
*/
readable = Model.where('created').gte(twoWeeksAgo).stream();
@hassansin
hassansin / casper-js-on-comple-error.js
Created July 31, 2015 13:51
CasperJS onComplete called infinitely when exitOnError is false.
var casper = require('casper').create({
viewportSize: {
width: 1024,
height: 768
},
pageSettings: {
webSecurityEnabled: false
},
exitOnError: false,
waitTimeout: 70000
@hassansin
hassansin / apiary.apib
Created December 24, 2015 03:55
Blueprint Circular Reference Error
FORMAT: 1A
HOST: https://api-sandbox.foxycart.com
# FoxyCart
# FoxyCart API Root [/]
## API starting point [GET]
+ Request
@hassansin
hassansin / .block
Last active March 9, 2016 23:32
D3 Chronograph Stopwatch
license: gpl-3.0
height: 300
border: no
@hassansin
hassansin / send.js
Created September 26, 2016 00:49
Send Joke with AWS SNS
#!/usr/bin/env node
/**
* Send a Joke to your mobile using AWS SNS service
* Usage:
* ./send.js phoneNumber [firstName] [lastName]
*
*/
const http = require('http');
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<script src="https://cdn.jsdelivr.net/lodash/4/lodash.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/benchmark/2.1.3/benchmark.min.js"></script>
</head>
<body>
@hassansin
hassansin / laravel-debugging.md
Last active July 2, 2017 22:00
Laravel Debugging #laravel #debugging
Get Query Logs
DB::enableQueryLog();
dd(DB::getQueryLog()); #output last executed queries
DB::table('users')->toSql() #show the generated sql statement 
DB::table('users')->getQuery()->wheres #show wheres conditions
Debug Messages with DebugBar
@hassansin
hassansin / send-to-kindle.js
Created September 22, 2017 09:52
Webtask to send any Webpage to Kindle as PDF
'use latest';
import nodemailer from 'nodemailer@2.5.0';
import request from 'request@2.81.0';
module.exports = function(context, cb) {
const url = context.query.url;
const kindleAddress = context.query.address || context.secrets.KINDLE_ADDRESS;
if (!url) {
return cb(null, "missing url parameter");