Skip to content

Instantly share code, notes, and snippets.

View amirkhiz's full-sized avatar

Siavash Habil amirkhiz

  • Sony
  • Turkey
View GitHub Profile
@amirkhiz
amirkhiz / unique-generator.php
Last active November 21, 2019 12:48
Generate unique Alphanumeric code PHP
<?php
// Reference https://codebriefly.com/unique-alphanumeric-string-php/
function unique_code($limit)
{
return substr(base_convert(sha1(uniqid(mt_rand())), 16, 36), 0, $limit);
}
echo unique_code(8);
@phpenterprise
phpenterprise / string-similarity-mysql.sql
Created June 25, 2019 15:21
String Similarity with MySQL
DELIMITER $$
CREATE DEFINER=`root`@`localhost` FUNCTION `COMPARE_STRING`( s1 text, s2 text) RETURNS int(11)
DETERMINISTIC
BEGIN
DECLARE s1_len, s2_len, i, j, c, c_temp, cost INT;
DECLARE s1_char CHAR;
DECLARE cv0, cv1 text;
SET s1_len = CHAR_LENGTH(s1), s2_len = CHAR_LENGTH(s2), cv1 = 0x00, j = 1, i = 1, c = 0;
IF s1 = s2 THEN
RETURN 0;
@amirkhiz
amirkhiz / E.164
Created May 23, 2019 15:00
E.164
Billy Chia Billy Chia
E.164 is the international telephone numbering plan that ensures each device on the PSTN has globally unique number.
This is what allows phone calls and text messages can be correctly routed to individual phones in different countries.
E.164 numbers are formatted [+] [country code] [subscriber number including area code] and can have a maximum of fifteen digits.
Examples of E.164 Numbers
E.164 Format Country Code Country Subscriber Number
+14155552671 1 US 4155552671
+442071838750 44 GB 2071838750
@amirkhiz
amirkhiz / IyzicoPayment.php
Last active January 5, 2019 17:18
Iyzico wrapper class with example payment and callback page. Iyzico library used v2.0.43 version from this repository https://github.com/iyzico/iyzipay-php
<?php
namespace App\Classes\Iyzico;
use Iyzipay;
use Iyzipay\Model;
use Iyzipay\Options;
use Iyzipay\Request;
/**
@WietseWind
WietseWind / rippled-proxy.js
Created March 8, 2018 00:30
Rippled Websocket proxy to test reconnecting & health checking for https://www.npmjs.com/package/rippled-ws-client
const WebSocket = require('ws')
const ws = new WebSocket('wss://s1.ripple.com')
const wss = new WebSocket.Server({ port: 8011 })
wss.on('connection', function connection(c) {
let sendmessages = true
setTimeout(function () {
sendmessages = false
@umidjons
umidjons / youtube-dl-download-audio-only-on-best-quality.md
Last active March 9, 2024 07:54
Download Audio from YouTube with youtube-dl

Download Audio from YouTube

-i - ignore errors

-c - continue

-t - use video title as file name

--extract-audio - extract audio track

@mihow
mihow / load_dotenv.sh
Last active July 25, 2024 04:35
Load environment variables from dotenv / .env file in Bash
# The initial version
if [ ! -f .env ]
then
export $(cat .env | xargs)
fi
# My favorite from the comments. Thanks @richarddewit & others!
set -a && source .env && set +a
@DomenicF
DomenicF / get_current_post_type.php
Last active December 5, 2022 07:11 — forked from bradvin/get_current_post_type.php
Get the current post_type context in the WordPress admin.
<?php
/**
* gets the current post type in the WordPress Admin
*/
function get_current_post_type() {
global $post, $typenow, $current_screen;
//we have a post so we can just get the post type from that
if ( $post && $post->post_type ) {
return $post->post_type;
<?php
/**
* Reference/source: http://stackoverflow.com/a/1464155/933782
*
* I want a short alphanumeric hash that’s unique and who’s sequence is difficult to deduce.
* I could run it out to md5 and trim the first n chars but that’s not going to be very unique.
* Storing a truncated checksum in a unique field means that the frequency of collisions will increase
* geometrically as the number of unique keys for a base 62 encoded integer approaches 62^n.
* I’d rather do it right than code myself a timebomb. So I came up with this.
*
@raineorshine
raineorshine / _chrome-ext-auth-identity.md
Last active November 10, 2023 23:57
How to set up user authentication for a Chrome Extension using the Chrome Identity API

How to set up user authentication for a Chrome Extension using the Chrome Identity API

  1. Create a private key file, from which you can create the manifest key and Application ID, as detailed here: https://stackoverflow.com/questions/23873623/obtaining-chrome-extension-id-for-development
  2. Add the manifest key to "key" in manifest.json
  3. Create a new project in Google Developer Console https://console.developers.google.com/project
  4. Go to "APIs & auth > Credentials" and create new client id for a Chrome Application using the Application ID generated in step 3.
  5. Copy the Client ID to oauth2.client_id in the manifest.json

Deprecated?