Skip to content

Instantly share code, notes, and snippets.

View FurkanKozen's full-sized avatar

Furkan Közen FurkanKozen

View GitHub Profile
@FurkanKozen
FurkanKozen / CommandLineArgs.cs
Last active May 17, 2020 17:18
Using command-line arguments in a console application
class Program
{
static void Main(string[] args)
{
foreach (var arg in args)
{
Console.WriteLine(arg);
}
}
}
@FurkanKozen
FurkanKozen / NetworkResourceTimingApis.js
Created May 15, 2020 14:42
Simple use of Network and Resource Timing APIs in JavaScript
//Collects performance metrics for HTML documents.
performance.getEntries();
performance.getEntriesByType("navigation")[0];
performance.getEntriesByType("navigation")[0].serverTiming[0];
//Collects performance metrics for document-dependent resources.
//Stuff like style sheets, scripts, images, et cetera.
performance.getEntriesByType("resource")[0];
performance.getEntriesByType("resource")[0].serverTiming[0];
performance.getEntriesByType("resource")[1];
@FurkanKozen
FurkanKozen / InfinityAsString.js
Created May 15, 2020 12:12
Infinity as string in JavaScript
console.log(Infinity.toLocaleString()); //∞
console.log(Infinity.toString()); //Infinity
@FurkanKozen
FurkanKozen / BananaRiddle.js
Created May 15, 2020 11:34
How this code writes "banana" to console?
console.log(("b" + "a" + + "b" + "a").toLowerCase()); //writes banana to console
//Explanation:
//The key point is + "b"
//+ is 'unary plus operator' that can be used to convert a variable to a number
//when "b" is converted to number, its value would be NaN
@FurkanKozen
FurkanKozen / TypeConversionMethods.js
Created May 15, 2020 10:52
Some type conversion methods in JavaScript
var numberContent = ~~"1";
var stringContent = ~~"string sample";
var stringContent2 = +"string sample 2";
var booleanContent = !!"false";
console.log(typeof numberContent); //"number"
console.log(numberContent); //1
console.log(typeof stringContent); //"number"
console.log(stringContent); //0, but should be NaN!
console.log(typeof stringContent2); //"number"
@FurkanKozen
FurkanKozen / FilteringUndefinedNullEmpty.js
Created May 15, 2020 09:36
Filtering null, undefined and empty strings in JavaScript
var list = [1, 3, null, undefined, 5, "", "not-empty"];
var filtered = list.filter(Boolean);
console.log(filtered);
@FurkanKozen
FurkanKozen / CuriousCaseOfNull.js
Created May 15, 2020 09:23
Null isn't greater than 0, isn't equal to 0, but is greater than or equal to 0 in JavaScript
console.log(null > 0); //'false'
console.log(null == 0); //'false'
console.log(null >= 0); //'true'!
//Explanation:
//https://blog.campvanilla.com/javascript-the-curious-case-of-null-0-7b131644e274
@FurkanKozen
FurkanKozen / FindingKeyByItsValue.cs
Created May 13, 2020 21:52
Finding the key by its value
using System;
using System.Linq;
using System.Collections.Generic;
class Program
{
public static void Main(string[] args)
{
var dict = new Dictionary<string, int>();
dict.Add("A", 25);
@FurkanKozen
FurkanKozen / HtmlHelperForModelBinding.cs
Last active May 13, 2020 21:26
Html helper snippet for binding properties of model dynamically
using System;
using System.Linq.Expressions;
public class Person
{
public int ID { get; set; }
public string Name { get; set; }
public int Age { get; set; }
}