Skip to content

Instantly share code, notes, and snippets.

View whitehorse0's full-sized avatar
🤓
trying to make the world better with software

eka-putra whitehorse0

🤓
trying to make the world better with software
  • @bibit.id
  • Jakarta, Indonesia
View GitHub Profile
@tj
tj / app.js
Created August 31, 2012 05:33
users online with redis
var express = require('express');
var redis = require('redis');
var db = redis.createClient();
var app = express();
// track users online (replace UA string with user id)
app.use(function(req, res, next){
var ua = req.headers['user-agent'];
@ianwremmel
ianwremmel / queue.js
Created September 19, 2012 23:17
Some things in nodejs need to be done synchronously (or, at least, shouldn't be enqueued at the rate a foreach loop will do so). Once I wrote this function three or four times, I decided it was time to put it somewhere easily accessible.
/**
* @file queue.js
* This is an asynchronous queue for nodejs. Initialize it with a callback to
* execute against each item in the queue and (optionally) a queue of items
* against which to operate. Then, execute emitter.emit('next') at the end of
* your callback to trigger each subsequent run. Queue.exec() returns the
* emitter you'll need. Once exec has been called, each time push() is called,
* the pushed item will be execuated against at the end of the queue (if the
* queue is empty, it will be executed imediately).
*/
@mobilemind
mobilemind / git-tag-delete-local-and-remote.sh
Last active May 16, 2025 16:05
how to delete a git tag locally and remote
# delete local tag '12345'
git tag -d 12345
# delete remote tag '12345' (eg, GitHub version too)
git push origin :refs/tags/12345
# alternative approach
git push --delete origin tagName
git tag -d tagName
@krzysztofantczak
krzysztofantczak / index.js
Created April 19, 2014 06:35
requirebin sketch
// !! Open devtools console and click 'run' button.
//
// line 24 is responsible for reemiting received events to 'piped' emitters
// but it fails when em1 --pipes--> em2 and em2 --pipes--> em1
// when line 42 is uncommented
var events = require('events');
var wrap = function ( emitter )
{
emitter.pipe = function ( targetEmitter )
@turret-io
turret-io / aes_enc_dec.php
Last active March 26, 2025 08:04
AES encryption/decryption in PHP
<?php
// DEFINE our cipher
define('AES_256_CBC', 'aes-256-cbc');
// Generate a 256-bit encryption key
// This should be stored somewhere instead of recreating it each time
$encryption_key = openssl_random_pseudo_bytes(32);
// Generate an initialization vector
// This *MUST* be available for decryption as well
@kottenator
kottenator / simple-pagination.js
Created July 13, 2015 20:44
Simple pagination algorithm
// Implementation in ES6
function pagination(c, m) {
var current = c,
last = m,
delta = 2,
left = current - delta,
right = current + delta + 1,
range = [],
rangeWithDots = [],
l;
@subfuzion
subfuzion / curl.md
Last active May 13, 2025 18:51
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.

@jherax
jherax / arrayFilterFactory.1.ts
Last active February 20, 2025 05:05
Filters an array of objects with multiple match-criteria.
type FilterOperator = 'AND' | 'OR';
type FiltersBy<T> = {
[K in keyof T]?: (value: T[K]) => boolean;
};
/**
* Factory function that creates a specialized function to filter
* arrays, by validating all filters (AND operator),
* or validating just one of the filters (OR operator).
* @param operator Method to validate all filters: AND, OR
@therightstuff
therightstuff / _end-to-end-enc.js.md
Last active December 19, 2023 02:17
Javascript / Node.js end-to-end encryption
@simonhamp
simonhamp / AppServiceProvider.php
Last active May 2, 2025 14:33
A pageable Collection implementation for Laravel
<?php
namespace App\Providers;
use Illuminate\Support\Collection;
use Illuminate\Pagination\LengthAwarePaginator;
class AppServiceProvider extends ServiceProvider
{
public function boot()