Skip to content

Instantly share code, notes, and snippets.

View sufian07's full-sized avatar
🎉
Focusing

Mohammad Abu Sufian sufian07

🎉
Focusing
View GitHub Profile
@sufian07
sufian07 / index.js
Last active June 28, 2016 06:30
Flatten the array
/**
* This function get a nested array and return flatten format of that array
*/
function flatten(array) {
var flat = [];
for(var i = 0; i < array.length; i++) {
if(Array.isArray(array[i])) {
flat = flat.concat(flatten(array[i]));
} else {
flat.push(array[i]);
@sufian07
sufian07 / simple-json-api.php
Created August 1, 2016 12:13 — forked from daggerhart/simple-json-api.php
Simple Read-Only JSON API example for WordPress
<?php
/**
* Class Simple_Json_Api
*/
class Simple_Json_Api {
/**
* The top level argument for the endpoint.
* ex http://example.com/myjson/post/1
@sufian07
sufian07 / curl.md
Created August 24, 2017 02:12 — forked from subfuzion/curl.md
curl POST examples

Common Options

-#, --progress-bar Make curl display a simple progress bar instead of the more informational standard meter.

-b, --cookie <name=data> Supply cookie with request. If no =, then specifies the cookie file to use (see -c).

-c, --cookie-jar <file name> File to save response cookies to.

@sufian07
sufian07 / 1-add-middleware.php
Created February 16, 2018 13:41 — forked from adamwathan/1-add-macros.php
Multiformat Endpoints in Laravel
<?php
namespace App\Http\Middleware;
class CaptureRequestExtension
{
public function handle($request, $next)
{
if ($request->route()->parameter('_extension') !== null) {
$request->attributes->set('_extension', substr($request->route()->parameter('_extension'), 1));
@sufian07
sufian07 / fewer_properties_subset_of_object_es6.js
Last active July 18, 2018 11:02
To get subset of an object in es6 syntax
const a = {
name: "Sufian",
age:34,
prof:"SE"
}
console.log(...a)
//Option 1
let {name,age} = a
const b = {name,age}
@sufian07
sufian07 / FlattenedPromiseChain.md
Created July 20, 2018 10:32 — forked from geowulf/FlattenedPromiseChain.md
Promises: Flattened Promise Chain

Credit: Thomas Burleson

Since promise handlers can return Promises, let’s use that technique to refactor an implementation:

var Dashboard = function( $scope, user, ServiceOne, ServiceTwo )
    {
        Service-1
            .getAddressInfo( user )                                              // Request #1
<?php
sprintf(
'SELECT * FROM (%s)',
implode(
' INNER JOIN ',
array_map(
function($s,$i){
return sprintf(
"(%s) as temp%d %s",
$s,
<?php
$selects[] = rtrim( join( array_map(
function ($custom_field)
{
$alias = 'custom' . $custom_field;
return "(SELECT wcf.value FROM workorder_custom_fields as wcf"
." WHERE wcf.workorder_id=w.workorder_id"
." AND wcf.custom_label_id='". dbsafe($custom_field). "') as `$alias`, ";
},
$customFields
@sufian07
sufian07 / memoize.js
Created August 25, 2018 12:13 — forked from jherax/memoize.generic.ts
High-order function that memoizes a function
/**
* @summary
* High-order function that memoizes a function, by creating a scope
* to store the result of each function call, returning the cached
* result when the same inputs is given.
*
* @description
* Memoization is an optimization technique used primarily to speed up
* functions by storing the results of expensive function calls, and returning
* the cached result when the same inputs occur again.
@sufian07
sufian07 / stream.js
Created October 10, 2021 09:37
Creating some example for creating stream in node js
const fs = require('fs');
const path = require('path');
const express = require('express');
const app = express()
const port = 5000
const Stream = require('stream')
app.get('/', (req, res) => {