Skip to content

Instantly share code, notes, and snippets.

Eugenio Marletti Takhion

Block or report user

Report or block Takhion

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
@rock3r
rock3r / normalizeColorHex.kts
Last active Mar 24, 2019
A Kotlin script to normalize hex colour representations ("#RGB", "#ARGB", "#RRGGBB", "#AARRGGBB") into "#AARRGGBB", useful for when you're trying to find all unique colours in your app
View normalizeColorHex.kts
/*
* ----------------------------------------------------------------------------
* "THE BEER-WARE LICENSE" (Revision 42):
* Sebastiano Poggi wrote this file. As long as you retain this notice you
* can do whatever you want with this stuff. If we meet some day, and you think
* this stuff is worth it, you can buy me a beer in return. Seb
* ----------------------------------------------------------------------------
* Feel free to attribute this code in compiled products if you feel like it,
* but it's not required.
*/
@Takhion
Takhion / ExhaustiveWhen.kt
Last active Nov 19, 2019
Exhaustive `when` mapping in Kotlin
View ExhaustiveWhen.kt
@file:Suppress("PackageDirectoryMismatch") // root package looks great when importing, ie. `import exhaustive`
/**
* Allows requiring an exhaustive mapping in a `when` block when used with the [rangeTo] operator.
* @sample [exhaustive_when_example]
*/
@Suppress("ClassName") // lowercase because it should look like a keyword
object exhaustive {
@porglezomp
porglezomp / Leftpad.idr
Last active Oct 22, 2018
Taking on Hillel's challenge to formally verify leftpad (https://twitter.com/Hillelogram/status/987432181889994759)
View Leftpad.idr
import Data.Vect
-- `minus` is saturating subtraction, so this works like we want it to
eq_max : (n, k : Nat) -> maximum k n = plus (n `minus` k) k
eq_max n Z = rewrite minusZeroRight n in rewrite plusZeroRightNeutral n in Refl
eq_max Z (S _) = Refl
eq_max (S n) (S k) = rewrite sym $ plusSuccRightSucc (n `minus` k) k in rewrite eq_max n k in Refl
-- The type here says "the result is" padded to (maximum k n), and is padding plus the original
leftPad : (x : a) -> (n : Nat) -> (xs : Vect k a)
@findepi
findepi / sort-commits-for-github.sh
Last active Jan 31, 2020
sort commits for GitHub's sake
View sort-commits-for-github.sh
git rebase "$(git merge-base HEAD master)" -x 'git commit --amend -C HEAD --date="$(date -R)" && sleep 1.05'
@willhbr
willhbr / Units.kt
Created May 23, 2017
Type-safe unit conversion with composite units
View Units.kt
/**
* Based on Ben Trengrove's example: https://gist.github.com/bentrengrove/9759a3fbb564d62e1e63f417c58a3895
*/
package units
import java.util.concurrent.TimeUnit
abstract class Unit(val suffix: String, val ratio: Double) {
internal fun convertToBaseUnit(amount: Double) = amount * ratio
internal fun convertFromBaseUnit(amount: Double) = amount / ratio
@thebitguru
thebitguru / facebook-photo-download.go
Created Jan 14, 2017
A simple go program to download all the high resolution pictures from your facebook albums.
View facebook-photo-download.go
package main
/*
* A simple go program to download all the high resolution pictures from your facebook albums.
*
* To run this:
* 1. Go to https://developers.facebook.com/tools/explorer/?method=GET&path=me&version=v2.8
* 2. Get an Access Token: Get Token > Get User Access Token > Check "user_photos"
* 3. Paste in the app.
*/
@habemus-papadum
habemus-papadum / main.swift
Last active Nov 27, 2019
Single File Swift 3 Gui Sample
View main.swift
// A reminder to myself on how to quickly create a throw away gui app on OSX (i.e. a single file,
// w/o relying on XCode project templates
//Notes: In general it is hard to know how to create a Cocoa based gui without using XCode.
//This issue has existed for both Objective-C and now Swift
//Furthermore, Swift<-->Cocoa syntax has changed dramatically over various Swift versions,
//making stackoverflow posts unreliable
//This file provides a template for creating a throw away gui app
@nickbutcher
nickbutcher / 1_drawable_ic_hash_io16.xml
Last active Jan 8, 2020
Animated Stroke. The google I/O website this year (https://google.com/io) has some funky animated lettering. I especially liked the animated stroke around the letters and wondered how you might implement that on Android. Turns out that AnimatedVectorDrawable makes this very easy! Here's how it looks: https://twitter.com/crafty/status/71077957997…
View 1_drawable_ic_hash_io16.xml
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2016 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
@tiwiz
tiwiz / build.gradle
Last active Jun 12, 2018
How to make Retrolambda work with both Mac OS X and Windows. Thanks to @Takhion - https://gist.github.com/Takhion/5c0f6c0c5aba9db5a488
View build.gradle
import org.gradle.internal.os.OperatingSystem;
String getJavaHome(String version) {
def stdout = new ByteArrayOutputStream()
exec {
commandLine "/usr/libexec/java_home", "-v", version
standardOutput = stdout;
}
return stdout.toString().trim()
}
@mapsam
mapsam / README.md
Last active Jan 6, 2020
Namecheap > Github pages
View README.md

Namecheap > Github pages

Pointing your domains to a gh-pages branch requires three steps.

  1. Add the Github IPs as A records on Namecheap. Both Github IPs are 192.30.252.153 and 192.30.252.154.
  2. Add your Github domain as the CNAME alias on Namecheap. your_username.github.io. (mind the extra period!)
  3. Add a CNAME with your new domain name in your repository. lowercase and nothing else
You can’t perform that action at this time.