Skip to content

Instantly share code, notes, and snippets.

Avatar
👋
Working from home

Hassansin hassansin

👋
Working from home
View GitHub Profile
@hassansin
hassansin / request-response.go
Last active March 22, 2023 08:08
Request-response pattern over asynchronous protocol using Go channel
View request-response.go
package main
import (
"errors"
"fmt"
"math/rand"
"net/http"
"sync"
"time"
@hassansin
hassansin / prepare-commit-msg.sh
Last active March 2, 2023 01:06
Clubhouse - Git Hooks
View prepare-commit-msg.sh
#!/bin/sh
# If commit message does not refer to any CH story number,
# this hook will parse the CH story from the current branch and
# append it to the commit message
#
# Example:
# Branch: hassansin/ch1643/custom-subdomains
# commit message: add support for EU base urls
# appended commit message: Add support for EU base urls [ch1643]
@hassansin
hassansin / eloquent-cheatsheet.php
Last active February 28, 2023 13:03
Laravel 5 Eloquent CheatSheet #laravel #eloquent
View eloquent-cheatsheet.php
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 / README.md
Last active January 22, 2023 21:17
Remote Debugging with XDebug 2.1
View README.md

XDebug

A PHP extension that allows you to:

  1. walk through your code by Remote Debugging
  2. find bottlenecks in your application by Profiling
  3. find Code Coverage in a single request
  4. trace your application by logging all function calls
@hassansin
hassansin / ab.sh
Created May 26, 2015 12:55
Apache Bench Ajax POST
View ab.sh
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" \
@hassansin
hassansin / README.md
Last active November 17, 2021 17:15
Working with MongoDB TTL (Time-To-Live) Index
@hassansin
hassansin / async-readable-stream.js
Last active November 10, 2020 15:26
Node.js Asynchronous Readable Stream
View async-readable-stream.js
/*
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 / commands.js
Last active September 3, 2020 16:35
MongoDB commands
View commands.js
db.collection.createIndex( { orderDate: 1, zipcode: -1 }, {background: true} )
db.events.ensureIndex( { "timestampISO": 1 }, { expireAfterSeconds: 120*24*60*60 } ) // <3.0, TTL index, 120day retention period
db.collection.getIndexes() //get all indexes
db.collection.dropIndex("name"); //drop single index
db.collection.dropIndexes(); //drop all indexes
db.collection.find({ email: 'test@sendgrid.com' }).explain("executionStats") // <3.0 : https://docs.mongodb.org/manual/reference/method/cursor.explain/#cursor.explain
//https://docs.mongodb.org/manual/tutorial/measure-index-use/
db.collection.explain("executionStats").find({ email: 'test@sendgrid.com' }) // 3.0 +
db.events.totalIndexSize() // in bytes, should not exceed RAM
@hassansin
hassansin / sync-readable-stream.js
Last active December 25, 2019 02:08
Node.js Synchronous Readable Stream
View sync-readable-stream.js
/*
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 / .bashrc
Last active August 18, 2019 08:09
dotfiles
View .bashrc
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples
# If not running interactively, don't do anything
case $- in
*i*) ;;
*) return;;
esac