Skip to content

Instantly share code, notes, and snippets.

View darkterminal's full-sized avatar

Imam Ali Mustofa darkterminal

View GitHub Profile
@darkterminal
darkterminal / debounce-throttle.md
Created October 2, 2022 12:56 — forked from ionurboz/debounce-throttle.md
Simple JavaScript debounce and throttle (Pure, Vanilla, Plain JS)

If you've written any kind of validation on user input, like onkeypress then you'll know that sometimes you want to throttle the amount of times your function runs. A good example of this is Ajax based username validation - you don't want to hit the server on every key press, because most users will be able to write their name in around 1/10th of a second, so you should throttle the ajax request until the input is dormant for 100ms.

So with a bit of magic JavaScript making use of the ever useful closure JavaScript offers, we can create a simple method to handle this for us:

function debounce(fn, delay) {
  var timer = null;
  return function () {
    var context = this, args = arguments;
    clearTimeout(timer);
 timer = setTimeout(function () {
@darkterminal
darkterminal / strong-passwords.php
Created September 24, 2022 07:33 — forked from compermisos/strong-passwords.php
A user friendly, strong password generator PHP function.
#!/usr/bin/php
<?PHP
// Generates a strong password of N length containing at least one lower case letter,
// one uppercase letter, one digit, and one special character. The remaining characters
// in the password are chosen at random from those four sets.
//
// The available characters in each set are user friendly - there are no ambiguous
// characters such as i, l, 1, o, 0, etc. This, coupled with the $add_dashes option,
// makes it much easier for users to manually type or speak their passwords.
//
Error:
$ adb devices
List of devices attached
52003c2b58b445db no permissions (user in plugdev group; are your udev rules wrong?); see [http://developer.android.com/tools/device.html]
Fix:
1> sudo usermod -aG plugdev $LOGNAME (https://developer.android.com/studio/run/device)
2> lsusb
3> sudo vi /etc/udev/rules.d/51-android.rules
@darkterminal
darkterminal / docker-compose.yml
Created July 17, 2022 16:41 — forked from bschaatsbergen/docker-compose.yml
multi-node elasticsearch cluster
version: '2.2'
services:
es01:
image: docker.elastic.co/elasticsearch/elasticsearch:7.12.0
container_name: es01
environment:
- node.name=es01
- cluster.name=es-docker-cluster
- discovery.seed_hosts=es02,es03
- cluster.initial_master_nodes=es01,es02,es03
@darkterminal
darkterminal / git_cleanup_non_remote_branches.sh
Created July 14, 2022 02:37 — forked from leandrocrs/git_cleanup_non_remote_branches.sh
command to cleanup all local branch without remote
git fetch --prune | git branch -r | awk '{print $1}' | egrep -v -f /dev/fd/0 <(git branch -vv | grep origin) | awk '{print $1}' | xargs git branch -D
@darkterminal
darkterminal / gitlab-release.js
Last active July 1, 2022 13:48
Gitlab Release JS
const _importDynamic = new Function('modulePath', 'return import(modulePath)');
const fetch = async function (...args) {
const { default: fetch } = await _importDynamic('node-fetch');
return fetch(...args);
}
const pkg = require('./package.json')
const PROPERTIES = {
@darkterminal
darkterminal / bearer-token.php
Created May 17, 2022 07:38 — forked from wildiney/bearer-token.php
PHP - How to get and set Bearer Token
<?php
/**
* Get hearder Authorization
* */
function getAuthorizationHeader(){
$headers = null;
if (isset($_SERVER['Authorization'])) {
$headers = trim($_SERVER["Authorization"]);
}
else if (isset($_SERVER['HTTP_AUTHORIZATION'])) { //Nginx or fast CGI
@darkterminal
darkterminal / skeleton.css
Created May 6, 2022 08:09
Skeleton Loader CSS
/* The loading Class */
.loading {
position: relative;
background-color: #e2e2e2;
}
/* The moving element */
.loading::after {
display: block;
content: "";
@darkterminal
darkterminal / normalizeWhitespaceCharacters.php
Last active February 18, 2022 19:15
Normalize Whitespace Characters using PHP
<?php
//grepper php normalize whitespace characters
function normalizeWhitespaceCharacters( $string )
{
$stepOne = htmlentities($string);
$stepTwo = trim(preg_replace('/(&nbsp;)+|\s\K\s+/','', $stepOne));
$final = html_entity_decode($stepTwo);
return $final;
}
@darkterminal
darkterminal / example.php
Created January 27, 2022 09:13 — forked from rohit00082002/example.php
Markdown Limited - a small, fast, safe markdown function in PHP
<?php
require('markdown_limited.php');
//header('Content-Type: text/plain; charset=UTF-8');
$text = file_get_contents('sample.txt');
print markdown_limited($text);
?>
<style type="text/css">
/* Don't judge me */