Skip to content

Instantly share code, notes, and snippets.

@luutruong
luutruong / Common-Currency.json
Created May 9, 2022 09:35 — forked from ksafranski/Common-Currency.json
Common Currency Codes in JSON
{
"USD": {
"symbol": "$",
"name": "US Dollar",
"symbol_native": "$",
"decimal_digits": 2,
"rounding": 0,
"code": "USD",
"name_plural": "US dollars"
},
import CryptoJS from 'crypto-js'
export function AES_encrypt(message: string, key: string): string {
const salt = CryptoJS.lib.WordArray.random(256)
const iv = CryptoJS.lib.WordArray.random(16)
const keyHash = CryptoJS.PBKDF2(key, salt, {
hasher: CryptoJS.algo.SHA512,
keySize: 64 / 8,
iterations: 999,
@luutruong
luutruong / youtube_2_mp3.sh
Created July 17, 2021 09:02
Loop to convert Youtube video to Mp3 format using youtube-dl
#!/bin/bash
while [[ true ]]; do
video_url=""
audio_format=""
audio_quality=""
read -p "Enter youtube video URL: " video_url
if [[ -z "${video_url}" ]]; then
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'your_api_url');
// custom HTTP method: GET, POST, PUT, DELETE
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, [

Direct copy of pre-encoded file:

$ ffmpeg -i filename.mp4 -codec: copy -start_number 0 -hls_time 10 -hls_list_size 0 -f hls filename.m3u8

<xf:js>
$(document).ready(function() {
$('.calvingDateBtn').on('click', function(e) {
e.preventDefault();
var $input = $('#calvingDateInput'),
$result = $('#calvingDateDue');
if ($(e.currentTarget).data('reset')) {
$input.val('');
$result.text('');
<?php
class Encrypter
{
const METHOD = 'AES-256-CBC';
public static function encrypt(array $payload, $key)
{
$key = md5($key, true);
@luutruong
luutruong / openssl_encrypt_decrypt.php
Created October 27, 2019 05:33 — forked from joashp/openssl_encrypt_decrypt.php
Simple PHP encrypt and decrypt using OpenSSL
<?php
/**
* simple method to encrypt or decrypt a plain text string
* initialization vector(IV) has to be the same when encrypting and decrypting
*
* @param string $action: can be 'encrypt' or 'decrypt'
* @param string $string: string to encrypt or decrypt
*
* @return string
*/
@luutruong
luutruong / README.md
Created December 2, 2018 15:11 — forked from magnetikonline/README.md
An example of recursion with Promises - reading recursive directories.

An example of recursion with Promises

A pattern for recursion with Promises - in this example, walking a directory structure.

Function flow

  • readDirRecursive() is called with a starting directory and will itself return a Promise.
  • Internally readDir() is called and passed starting directory.
  • A list of directory items is returned by getItemList() as a Promise, which in turn is chained to getItemListStat() to stat each item to determine if file or directory.
  • Finalised list then passed to processItemList():
    • Files are added to accumulating fileList array.
    • Directories are added to readDirQueue.
<?php
abstract class BaseDoc {
/**
* @param SomeObject1 $argument1
* @param SomeObject2 $argument2
*/
public function exampleFunc($argument1, $argument2) {
}