Skip to content

Instantly share code, notes, and snippets.

💭
What?!

Mehdi Dehghani dehghani-mehdi

💭
What?!
Block or report user

Report or block dehghani-mehdi

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@dehghani-mehdi
dehghani-mehdi / git-commands.md
Last active Aug 25, 2019
Useful git commands
View git-commands.md
  1. Pull (Update repo): git pull
  2. Commit:
    • git add .
    • git commit -m "COMMIT COMMENT"
    • git push
  3. Clone: git clone <url>
  4. Clone a branch: git clone <url> -b BRANCH_NAME
  5. Get repo's remote URL: git config --get remote.origin.url
  6. Update repo's remote URL: git remote set-url origin <url>
  7. See changed files before commit (differences between current commit and working tree): git diff HEAD or git diff [filename]
@dehghani-mehdi
dehghani-mehdi / discount.md
Created Mar 16, 2019
Get discount price and discount percentage in C# and JavaScript
View discount.md

C#

public double GetDiscountPercentage(double sellPrice, double discountPrice)
{
    return sellPrice == 0 ? 0 : Math.Abs((((discountPrice - sellPrice) / sellPrice) * 100));
}

public double GetDiscountPrice(double sellPrice, int discountPercentage)
{
@dehghani-mehdi
dehghani-mehdi / validate-national-code.js
Created Oct 10, 2018
Validate Iranian national code in JavaScript - بررسی صحت کد ملی در جاوا اسکریپت
View validate-national-code.js
var isValidNationalCode = function(code) {
if (code.length !== 10 || /(\d)(\1){9}/.test(code)) return false;
var sum = 0,
chars = code.split('');
for (var i = 0; i < 9; i++) sum += +chars[i] * (10 - i);
var lastDigit,
remainder = sum % 11;
@dehghani-mehdi
dehghani-mehdi / slugify.cs
Created Oct 1, 2018
Generate clean url slug in C#
View slugify.cs
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 / backup-restore-firefox-data.md
Last active Sep 16, 2018
[Firefox] How to backup and restore important data
View backup-restore-firefox-data.md

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 / custom-font.cs
Last active Dec 28, 2017
[Xamarin.Android] Using custom font
View custom-font.cs
// 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 / trim-end.js
Created Jul 4, 2017
C# like trimEnd method in JavaScript
View trim-end.js
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 / trim-start.js
Created Jul 4, 2017
C# like trimStart method in JavaScript
View trim-start.js
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 / git-commit.bat
Last active Apr 12, 2017
Commit on GitHub/GitLab using batch file (.bat file)
View git-commit.bat
@echo off
echo Commit on GitHub/GitLab
echo.
set /p comment="Enter comment: "
git.exe add .
git.exe commit -m "%comment%"
git.exe push
You can’t perform that action at this time.