Skip to content

Instantly share code, notes, and snippets.

View dehghani-mehdi's full-sized avatar
💭
Waiting ...

Mehdi Dehghani dehghani-mehdi

💭
Waiting ...
  • Rightek
  • That's what she said
View GitHub Profile
@dehghani-mehdi
dehghani-mehdi / git-commit.bat
Last active May 2, 2020 22:42
Commit on GitHub/GitLab using batch file (.bat file)
@echo off
echo Commit on GitHub/GitLab
echo.
set /p comment="Enter comment: "
git.exe add .
git.exe commit -m "%comment%"
git.exe push
@dehghani-mehdi
dehghani-mehdi / trim-start.js
Created July 4, 2017 08:16
C# like trimStart method in JavaScript
String.prototype.trimStart = function(c) {
if (this.length == 0) return this;
c = c ? c : ' ';
var i = 0;
for (; i < this.length && this.charAt(i) == c; i++);
return this.substring(i);
}
// Example
@dehghani-mehdi
dehghani-mehdi / trim-end.js
Created July 4, 2017 08:18
C# like trimEnd method in JavaScript
String.prototype.trimEnd = function(c) {
if (this.length == 0) return this;
c = c ? c : ' ';
var i = this.length - 1;
for (; i >= 0 && this.charAt(i) == c; i--);
return this.substring(0, i + 1);
}
// Example
@dehghani-mehdi
dehghani-mehdi / custom-font.cs
Last active December 28, 2017 13:21
[Xamarin.Android] Using custom font
// First you need to put .ttf of the font to Assets folder
// Let's say the font file name is: MyFont.ttf
// create typeface
var typeface = Typeface.CreateFromAsset(Assets, "MyFont.ttf");
// find the TextView
var tvTitle = FindViewById<TextView>(Resource.Id.tvTitle);
// assign the typeface to the TextView
@dehghani-mehdi
dehghani-mehdi / backup-restore-firefox-data.md
Last active September 16, 2018 12:13
[Firefox] How to backup and restore important data

BACKUP

  1. Head to C:\Users\%USERNAME%\AppData\Roaming\Mozilla\Firefox\Profiles\
  2. Copy/Backup the directory in some place safe

Do you have multiple directories? that means you have multiple Firefox's profiles, in most cases xxxxxxxx..default is the main one (if you have multiple Firefox's profiles, you are pro user, what the hell you doing here?!)

RESTORE

@dehghani-mehdi
dehghani-mehdi / slugify.cs
Created October 1, 2018 10:24
Generate clean url slug in C#
public string Slugify(string s)
{
if (string.IsNullOrWhiteSpace(s)) return "";
// removing extra spaces and keeping just one
s = string.Join(" ", Regex.Split(s, @"\s+")).ToLower();
var specialPhases = new Dictionary<string, string>
{
{"c#","c-sharp"},
@dehghani-mehdi
dehghani-mehdi / validate-national-code.js
Last active December 20, 2024 22:30
Validate Iranian national code in JavaScript - بررسی صحت کد ملی در جاوا اسکریپت
// C# version -> https://gist.github.com/dehghani-mehdi/2af3d913786d8b1b286f9c28cc75d5f4
var isValidNationalCode = function(code) {
if (code.length !== 10 || /(\d)(\1){9}/.test(code)) return false;
var sum = 0,
chars = code.split(''),
lastDigit,
remainder;
@dehghani-mehdi
dehghani-mehdi / discount.md
Last active November 12, 2020 08:08
Get discount price and discount percentage in C# and JavaScript

C#

public decimal GetDiscountPercentage(decimal sellPrice, decimal discountPrice)
    => sellPrice == 0 ? 0 : Math.Abs((((discountPrice - sellPrice) / sellPrice) * 100));

public decimal GetDiscountPrice(decimal sellPrice, byte discountPercentage)
    => discountPercentage == 0 ? 0 : sellPrice == 0 ? 0 : sellPrice - (sellPrice * discountPercentage / 100);
@dehghani-mehdi
dehghani-mehdi / git-commands.md
Last active October 4, 2022 12:12
Useful git commands
  • Pull (Update repo): git pull
  • Commit:
    • git add .
    • git commit -m "COMMIT COMMENT"
    • Short version: git commit -am "COMMIT COMMENT"
  • Push (Update remote): git push <remote-name> <branch-name>
  • Clone: git clone <url>
  • Clone a branch: git clone <url> BRANCH_NAME
  • Clone and create a branch: git clone <url> -b BRANCH_NAME
  • Get repo's remote URL: git config --get remote.origin.url
@dehghani-mehdi
dehghani-mehdi / commands.md
Last active November 2, 2020 06:15
Linux Commands frequently used by Linux Sysadmins
  1. ip – from Iproute2, a collection of utilities for controlling TCP/IP networking and traffic control in Linux.
  2. ls – list directory contents.
  3. df – display disk space usage.
  4. du – estimate file space usage.
  5. free – display memory usage.
  6. scp – securely Copy Files Using SCP, with examples.
  7. find – locates files based on some user-specified criteria.
  8. ncdu – a disk utility for Unix systems.
  9. pstree – display a tree of processes.
  10. last – show a listing of last logged in users.