Skip to content

Instantly share code, notes, and snippets.

View MichaelPolla's full-sized avatar

Michaël Polla MichaelPolla

View GitHub Profile
MichaelPolla / GetMemberName.cs
Created June 13, 2018 09:12
Get the name of the provided member (C# < 6.0)
View GetMemberName.cs
/// <summary>
/// Get the name of the provided member.
/// Same as using the operatore nameof provided by C# >= 6.0.
/// Usage: GetMemberName(() => myMember);
/// </summary>
/// <param name="memberExpression"></param>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
private static string GetMemberName<T>(Expression<Func<T>> memberExpression)
MichaelPolla /
Last active May 10, 2018 20:02
Installation instruction (using Brew) for the Fish shell on Mac OS X

Install Fish shell on Mac OS X

  1. Install Brew, a nice package manager for MacOS

  2. Install Fish : brew install fish

  3. Add fish to the list of available shells : sudo -s then echo /usr/local/bin/fish >> /etc/shells

  4. (optional) Set fish as the default shell
    3.1 ...for root (assumed as the current user because of point 2.) : chsh -s /usr/local/bin/fish\

MichaelPolla /
Last active February 5, 2024 12:21
Markdown - Resize pictures in GitHub, including in comments comment

Markdown - Resize pictures in GitHub

I found that the "best" way is to use HTML, as it works both in Readme/.md files and also in comments (within Issues, Gist...)

E.g. when adding/editing a comment (within Issues, Gist...) :

  • Upload the picture by drag-and-drop in the text field
  • replace ![image](https://your-image-url.type) with <img src="https://your-image-url.type" width="100" height="100">

As mentioned by @cbestow (thanks!), it's not mandatory to set both width and height. If only one is set, the other will be adjusted accordingly to preserve the aspect ratio of the image.

MichaelPolla /
Created March 5, 2018 13:04 — forked from seanbuscay/
Create an orphan branch in a repo.
cd repository
git checkout --orphan orphan_name
git rm -rf .
rm '.gitignore'
echo "#Title of Readme" >
git add
git commit -a -m "Initial Commit"
git push origin orphan_name
MichaelPolla / UpdateIntervals.cs
Created December 2, 2017 21:50
[Unity3D] Execute code in Update() only at certain intervals
View UpdateIntervals.cs
public class UpdateIntervals : MonoBehaviour {
private float updateStep = 0.1f; // in seconds
private float currentUpdateTime = 0f;
void Start() {}
void Update() {
currentUpdateTime += Time.deltaTime;
if(currentUpdateTime > updateStep) {
MichaelPolla /
Created July 19, 2016 12:34
Get the path of a file from its URI
/* Used for example when you get an Uri within the onActivityResult :
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// Process the result if it's OK (user finished the action) and the request code matches.
if (resultCode == RESULT_OK && requestCode == PICK_IMAGE) {
imageUri = data.getData(); // <==== THERE
MichaelPolla /
Last active July 19, 2016 12:30
[Android] Open the document app on the phone to pick a picture (or any kind of files)
private static final int PICK_IMAGE = 1; // number that identify the request (can be any number)
// Called e.g. when clicking on a button
public void addPicture() {
Intent intent = new Intent();
intent.setType("image/*"); // the type of data we are interested of
startActivityForResult(Intent.createChooser(intent, "Select picture"), PICK_IMAGE);
MichaelPolla / getAge.js
Created June 13, 2016 14:57
[JS] Calculate age (years) from a date
View getAge.js
function getAge(dateString) {
var birthDate = new Date(dateString);
var today = new Date();
var diff = today-birthDate; // Difference in milliseconds
var age = Math.floor(diff/31557600000); // Divide by 1000*60*60*24*365.25 <- length of a year (365 days and 6 hours) in milliseconds
return age;