Skip to content

Instantly share code, notes, and snippets.

View amirkhiz's full-sized avatar

Siavash Habil amirkhiz

  • Sony
  • Turkey
View GitHub Profile
<?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.
*
@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);
@amirkhiz
amirkhiz / getPotentialDomains.php
Last active October 25, 2019 08:43
Get potential domain from array of strings
<?php
function getPotentialDomains( $lines ) {
$re = '~((https|http){1}://(www|ww2|web)?(\.)?(([a-z0-9\-])+\.)+([a-z]{2,}){1})~ui';
$domains = [];
foreach ( $lines as $line ) {
preg_match_all( $re, $line, $matches, PREG_SET_ORDER, 0 );
$domains = array_merge( $domains, $matches );
@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

Keybase proof

I hereby claim:

  • I am amirkhiz on github.
  • I am habil (https://keybase.io/habil) on keybase.
  • I have a public key ASDT1ZcD9RZiUQOcrqb1jQ2fewEmmYkquGViyofv9xRJ9Ao

To claim this, I am signing this object:

@amirkhiz
amirkhiz / permission.sh
Created January 6, 2019 15:05
Set Files & Directories permission command
find * -type d -print0 | xargs -0 chmod 0755 # for directories
find . -type f -print0 | xargs -0 chmod 0644 # for files
stat -c "%a %n" * # Check permissions
@amirkhiz
amirkhiz / readme.md
Created January 6, 2019 14:55
Use Google Analytics Api in PHP
  1. Goto Google Developer Console
  2. Make New Project
  3. Enable Analytics API
  4. In Credentials Menu item create new Service Account with P12 option
  5. Download P12 file and copy Email Address that Service Account give you
  6. Goto Google Analytics Account
  7. Create New property for your site
  8. In Analytics panel in ACCOUNT Column Click User Management Paste Email Address that Service Account get us and click add
  9. Copy 9 last digit of url in Analytics page of project and we will use it in Google Api Library
@amirkhiz
amirkhiz / Controller.php
Last active January 6, 2019 14:52
General Search in all tables of site
class Controller {
public function search()
{
$kelime = $_POST['query'];
$result = $this->site_model->search($keyword);
foreach ($result as $item) {
switch ($item->type) {
case 'products':
@amirkhiz
amirkhiz / send-request.js
Created January 6, 2019 14:46
Send file with ajax request in form data
$('#frm-human-res').submit(function (e) {
e.preventDefault();
var form_data = new FormData(),
cv_file = document.getElementById("upload-btn").files[0];
var other_data = $(this).serializeArray();
$.each(other_data, function (key, input) {
form_data.append(input.name, input.value);
});
@amirkhiz
amirkhiz / generate_unique_id.php
Created January 6, 2019 14:45
Generate Unique ID
function generateUniqueId()
{
mt_srand();
$order_no = substr(md5(uniqid(mt_rand())), 0, 8);
return $order_no;
}