Skip to content

Instantly share code, notes, and snippets.

View meysampg's full-sized avatar
🖖
bit bit 0 bit

Meysam P. Ganji meysampg

🖖
bit bit 0 bit
View GitHub Profile

Keybase proof

I hereby claim:

  • I am meysampg on github.
  • I am meysampg (https://keybase.io/meysampg) on keybase.
  • I have a public key whose fingerprint is ABDC EC9A BDE6 DEC9 0BED 96DC D5A5 8C55 AAC5 9EB5

To claim this, I am signing this object:

@meysampg
meysampg / IranMoney.php
Created December 1, 2016 22:55
Convert a number to Iranian Currency
$iranMoney = function ($m) {
setlocale(LC_MONETARY, 'fa_IR');
return str_replace('IRR', 'ریال', money_format('%i', $m));
};
@meysampg
meysampg / translationInput.jquery.js
Created January 18, 2017 14:15
Convert a table field to input
(function($) {
"use strict";
$.fn.translationInput = function(options) {
options = $.extend({
defaultClass: ".translationField",
defaultRoute: "update"
}, options);
return this.each(function(i, v) {
@meysampg
meysampg / dd.php
Created July 8, 2017 03:10
define `dd` function for Yii2
<?php
// add anywhere after `require(__DIR__ . '/../vendor/autoload.php');` on index.php file
function dd($v) {
\yii\helpers\VarDumper::dump($v, 10, true);
exit();
}
@meysampg
meysampg / Controller.php
Created July 30, 2017 05:34
A Yii2 Controller With Support of DI on Actions
<?php
/**
* Created by PhpStorm.
* User: meysampg
* Date: 7/30/17
* Time: 8:46 AM
*/
namespace app\controllers;
@meysampg
meysampg / influx-rand-data.sh
Created November 11, 2017 16:53
Fake data for test Influx performance
n=100000
for i in {1..$n}
do
s1=$(echo -n "`date +%N`" | sha256sum | sed 's/\s\-//' | head -c 15)
s2=$(echo -n "`date +%N`" | sha256sum | sed 's/\s\-//' | head -c 5)
s3=$(echo -n "`date +%N`" | sha256sum | sed 's/\s\-//' | head -c 60)
s4=$(echo -n "`date +%N`" | sha256sum | sed 's/\s\-//' | head -c 60)
s5=$(echo -n "`date +%N`" | sha256sum | sed 's/\s\-//' | head -c 10)
s6=$(echo -n "`date +%N`" | sha256sum | sed 's/\s\-//' | head -c 20)
query=profile,name=\"$s1\",code=\"$s2\",content=\"$s3\"" "profile_id=\"$s4\",page_id=\"$s5\",eng=\"$s6\"
@meysampg
meysampg / floatToBinary.js
Created July 6, 2018 17:36
Convert a decimal to binary
// suppose num is between 0 and 1, without lost of generality, the theorem could be extended for numbers in [-1,0];
function floatToBinary(num) {
let binDigits = [];
for (let i = 0; i < 23 && num !== 0; ++i) {
num *= 2; // for converting a decimal number between -1 and 1 to its binary representation, we multiply it by 2 repeatedly!
integralPart = Math.floor(num);
binDigits.push(integralPart); // the integral part of number is our binary digit
num -= integralPart;
}
@meysampg
meysampg / fact.cpp
Created November 5, 2018 06:25
Recursive factorial without if :-?
#include <iostream>
bool fact(int n, int* res) {
*res *= n;
return n-1 && fact(n-1, res);
}
int main() {
int i;
@meysampg
meysampg / laravelog-title-extractor
Created January 8, 2019 07:25
Laravel Log Title Extractor
\[(\d{4}-\d{1,2}-\d{1,2} \d{1,2}:\d{1,2}:\d{1,2})\] production\.\w+:([\w\W]*)\[stacktrace\]\n#0 (.*)
package main
import (
"fmt"
"os"
"strconv"
)
func main() {
m, n := sizeOfArea()