Skip to content

Instantly share code, notes, and snippets.

View khanzadimahdi's full-sized avatar
🤔
Don't ration passion!

mahdikhanzadi khanzadimahdi

🤔
Don't ration passion!
View GitHub Profile
@taylorza
taylorza / GO-Fillslice.md
Last active August 8, 2024 04:04
Golang - Fill slice/array with a pattern

Filling an array or slice with a repeated pattern

Looking for an efficient pure GO approach to copy repeating patterns into a slice, for a toy project, I ran a few tests and discovered a neat approach to significantly improve performance. For the toy project, I am using this to fill a background buffer with a specific RGB color pattern, so improving this performance significantly improved my acheivable framerate.

All the test were run with a buffer of 73437 bytes, allocated as follows

var bigSlice = make([]byte, 73437, 73437)

Fill the slice with the value 65 by looping through each element and setting the value

@khanzadimahdi
khanzadimahdi / countries.php
Created March 9, 2020 06:10
All countries name, abbrev name, phone code and a pattern to match phone codes
<?php
$countryCodes = [
[
'abbr' => 'AD',
'name' => 'ANDORRA',
'code' => '376',
'pattern' => ''
],
[
@khanzadimahdi
khanzadimahdi / regex-match-utf8-hashtags.php
Created January 26, 2020 06:16
regex to match utf8 hashtags (similar to Instagram and Facebook)
/**
* @see https://regexr.com/4suqt
* @see https://regex101.com/r/4SAxik/1
* @see https://www.regexpal.com/?fam=113956
**/
$regex = "(?:#)([\p{L}\p{N}_](?:(?:[\p{L}\p{N}_]|(?:\.(?!\.))){0,28}(?:[\p{L}\p{N}_]))?)";
$text = "here is a #hashtag.tail and #another_hashtag #هشتگ #__hehe #123 this is a test.";
@AliN11
AliN11 / typescript-dependency-injection.ts
Created September 15, 2019 12:58
Typescript Dependency Injection
interface Wheel {}
interface Engine {}
class Car {
private wheel: Wheel;
private engine: Engine;
public constructor(wheel: Wheel, engine: Engine) {
this.wheel = wheel;
this.engine = engine;
@khanzadimahdi
khanzadimahdi / array_splice_assoc.php
Created August 25, 2019 07:31
php array_splice_assoc (array_splice associative)
<?php
/**
PHP array_splice doesn't use associative replacement keys, so i wrote the below method to do that.
*/
function array_splice_assoc(array &$original, int $offset, int $length = 0, $replacement = null) {
$slice = array_slice($original, 0, $offset, true);
if (!is_null($replacement)) {
// cast to array
@khanzadimahdi
khanzadimahdi / data-uri-regex-rfc2397.md
Last active December 1, 2024 19:17
regex pattern base64 data uri according to RFC 2397

pattern:

^data:((?:\w+\/(?:(?!;).)+)?)((?:;[\w\W]*?[^;])*),(.+)$

test this pattern on regexr: https://regexr.com/4inht

regex pattern to match RFC 2397 data URL

@khanzadimahdi
khanzadimahdi / string-limit.js
Created April 23, 2019 05:46
limit strings length in pure javascript
// add some prototypes
String.prototype.limit = function(length = 150, tail = '...') {
return this.substr(0, length) + (this.length > length ? tail : '');
};
// how to use:
'this is an string'.limit(5);
// or it can be like the below
let name = 'this is my name';
@abdallahokasha
abdallahokasha / Install_robo3t_Ubuntu.md
Last active September 24, 2023 14:54
Install Robo3t on Ubuntu18.04 and make a desktop icon for it

Install Robo3t On Ubuntu 18.04

Download the package form Robo3t or using wget
wget https://download.robomongo.org/1.2.1/linux/robo3t-1.2.1-linux-x86_64-3e50a65.tar.gz
Extract here using

tar -xvzf robo3t-1.2.1-linux-x86_64-3e50a65.tar.gz

@khanzadimahdi
khanzadimahdi / laravel-on-delete.js
Last active February 4, 2019 06:51
laravel on delete request ask yes-no question
//use jquery and sweetAlert2
$(document).ready(function() {
$("form input[name~=_method][value~=DELETE]").closest('form').submit(function(event) {
event.preventDefault();
var form = $(this); //wrap this in jQuery
swal({
title: "are you sure?",
text: "do you realy want to delete this item?",
type: "warning",
showCancelButton: true,
@khanzadimahdi
khanzadimahdi / download-file-with-server.php
Last active January 23, 2019 20:38
download file in server using php
<?php
error_reporting(E_ALL);
ini_set('display_errors',1);
set_time_limit(0);
function download ($file_source, $file_target) {
echo 'starting';
$rh = fopen($file_source, 'rb');
$wh = fopen($file_target, 'w+b');
if (!$rh || !$wh) {