- An Enumerable of Rubyists @raganwald
- An Indentation of Pythonistas @raganwald
- A fold of Haskellers! @ReinH
- A Din of Twitterers @raganwald
- A callback of JavaScripters @irvingreid
- An NCC-1701 of Java Programmers @raganwald
- A relation of SQLers @raganwald
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# MIT © Sindre Sorhus - sindresorhus.com | |
# git hook to run a command after `git pull` or `git checkout` if a specified file was changed | |
# Run `chmod +x post-checkout` to make it executable then put it into `.git/hooks/`. | |
changed_files="$(git diff-tree -r --name-only --no-commit-id HEAD@{1} HEAD)" | |
check_run() { | |
echo "$changed_files" | grep --quiet "$1" && echo " * changes detected in $1" && echo " * running $2" && eval "$2" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Demo showing how to use the usefulOrientation function. | |
*/ | |
function onDeviceOrientationChange(e){ | |
console.log("deviceOrientation", e.alpha, e.beta, e.gamma); | |
var orientation = usefulOrientation(e.alpha, e.beta, e.gamma); | |
console.log("usefulOrientatino", orientation.alpha, orientation.beta, orientation.gamma); | |
} | |
window.addEventListener("deviceorientation", onDeviceOrientationChange, false); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Example 11: add with params | |
// Use params to take several ints, each representing 3 digits | |
public static void Add<TKey>(this IDictionary<TKey, int> dictionary, TKey key, params int[] values) | |
=> dictionary.Add(key, values.Aggregate(0, (s, v) => s*1000 + v)); | |
// Now we can write it like this | |
var populations = new Dictionary<string, int> | |
{ | |
{ "China", 1,409,517,397 }, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Example 10: add a tuple | |
// This is just a dummy class that we can use in the example | |
public class City | |
{ | |
public City(string name, int population, string country) | |
{ | |
Name = name; | |
Population = population; | |
Country = country; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Example 7: add a dictionary | |
// These are just some dummy methods for the example to work | |
public static IDictionary<string, int> GetAfricanCountries() => new Dictionary<string, int>{ | |
{ "Nigeria", 190_886_311 }, | |
{ "Ethiopia", 104_957_438 }, | |
{ "Egypt", 97_553_151 } | |
}; | |
public static IDictionary<string, int> GetEuropeanCountries() => new Dictionary<string, int>{ | |
{ "Russia", 146_864_513 }, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Example 8: add a new instance | |
// This is just a dummy class that we can use in the example | |
public class City | |
{ | |
public City(string name, int population, string country) | |
{ | |
Name = name; | |
Population = population; | |
Country = country; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Example 9: multi or single dimensional arrays? | |
// We define this extension method | |
public static void Add<T>(this List<T> list, params T[] items) | |
=> list.AddRange(items); | |
// And then we can make a flattened matrix | |
var matrix = new List<double> | |
{ | |
{ 1, 0, 0 }, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Example 6: Add a list | |
// This is just a dummy method that returns some ints | |
public static IEnumerable<int> GetAnotherListOfInts() | |
=> new[] { 10, 11, 12, 13 }; | |
// With this extension method... | |
public static void Add<T>(this List<T> list, IEnumerable<T> items) | |
=> list.AddRange(items); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Runtime.CompilerServices; | |
using System.Threading.Tasks; | |
// Example 5: await tuple of Tasks | |
// Just some dummy async functions | |
public static Task<string> GetSomethingAsync(int number) => Task.FromResult($"Something {number}"); | |
public static Task<int> GetAnotherThingAsync(string text) => Task.FromResult(text.Length); | |
// This extension method lets us await a tuple with two values |
NewerOlder