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 / commands.sh
Last active May 23, 2018 11:41
Web Server Performance Comparison #sysbench #benchmark
# Ref: http://wiki.mikejung.biz/Sysbench
# CPU
sysbench --test=cpu --cpu-max-prime=20000 run
sysbench --test=cpu --cpu-max-prime=20000 run --num-threads=4
#FILE IO
sysbench --test=fileio --file-total-size=4G prepare
sysbench --test=fileio --file-total-size=4G --file-test-mode=rndrw --max-time=300 --max-requests=0 --file-extra-flags=direct run
sysbench --test=fileio --file-total-size=4G cleanup
@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 / async-readable-stream.js
Last active November 10, 2020 15:26
Node.js Asynchronous Readable Stream
/*
Creating Asynchronous Readable Stream in NodeJS
--------------------------------------------------------
When data is pushed asynchronously to internal buffer, you'll get an asynchronous
behaviour of the stream.
See Synchronous Version: https://gist.github.com/hassansin/7f3250d79a386007ce45
*/
var Readable = require("stream").Readable;
@hassansin
hassansin / sync-readable-stream.js
Last active December 25, 2019 02:08
Node.js Synchronous Readable Stream
/*
Creating Synchronous Readable Stream in NodeJS
--------------------------------------------------
When data is pushed synchronously to internal buffer, you'll get the synchronous
behaviour of the stream. This would block the rest of the code from being executed in
the next event loop iteration.
In the example setImmediate should be called immediatley in next event loop iteration.
But since the stream is synchronously reading data, it can't execute other callbacks.
@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 / 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();
/*Use Fiddler Proxy*/
curl_setopt($ch, CURLOPT_PROXY, '127.0.0.1:8888');
/*Use Proxy*/
curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1);
curl_setopt($ch, CURLOPT_PROXY, "IP:PORT");
curl_setopt($ch, CURLOPT_PROXYUSERPWD, "username:password");
@hassansin
hassansin / eloquent-cheatsheet.php
Last active May 5, 2024 05:53
Laravel 5 Eloquent CheatSheet #laravel #eloquent
Model::
/*Select*/
select('col1','col2')
->select(array('col1','col2'))
->select(DB::raw('businesses.*, COUNT(reviews.id) as no_of_ratings, IFNULL(sum(reviews.score),0) as rating'))
->addSelect('col3','col4')
->distinct() // distinct select
/*From*/
@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 / ab.sh
Created May 26, 2015 12:55
Apache Bench Ajax POST
ab \
-n 1000 \
-c 20 \
-s 30 \
-p post-data.txt \
-T 'application/x-www-form-urlencoded; charset=UTF-8' \
-v 3 \
-H "X-Requested-With: XMLHttpRequest" \
-H "X-Ajax-Referer: http://example.com" \
-H "Accept-Encoding: gzip, deflate" \