Skip to content

Instantly share code, notes, and snippets.

View temon's full-sized avatar
🏠
Working from home

Eko Prastyo temon

🏠
Working from home
View GitHub Profile
@hannesl
hannesl / cantor_pairing.php
Created December 18, 2013 23:02
Cantor pairing functions in PHP. Pass any two positive integers and get a unique integer back. Feed the unique integer back into the reverse function and get the original integers back. Explanation and JS implementation here: http://stevegardner.net/2012/07/09/javascript-cantor-pairing-function-and-reverse-function/
<?php
/**
* Calculate a unique integer based on two integers (cantor pairing).
*/
function cantor_pair_calculate($x, $y) {
return (($x + $y) * ($x + $y + 1)) / 2 + $y;
}
/**
@p1nox
p1nox / using_meld_on_mac.md
Last active June 13, 2023 16:24
Using meld on Mac

Using Meld merging tool on Mac

There are two ways of installing meld on osx (May 2023), using brew and .dmg package (from @yousseb). Since I found https://yousseb.github.io/meld/, I've installed it with .dmg package, but having macOS Ventura Version 13.4 (22F66) in place, it's not even starting for me. So I tried brew installation, and the application is working as expected, including symlink to start it from the terminal.

brew install --cask meld

# set meld as your default git mergetool
@alvinj
alvinj / sbtmkdirs.sh
Last active June 22, 2024 15:13
A shell script to create an SBT project directory structure
#!/bin/bash
#------------------------------------------------------------------------------
# Name: sbtmkdirs
# Version: 1.5
# Purpose: Create an SBT project directory structure with a few simple options.
# Author: Alvin Alexander, http://alvinalexander.com
# License: Creative Commons Attribution-ShareAlike 2.5 Generic
# http://creativecommons.org/licenses/by-sa/2.5/
#------------------------------------------------------------------------------
@kencoba
kencoba / Bridge.scala
Created February 21, 2012 10:49
Bridge pattern (Design Patterns in Scala)
// http://en.wikipedia.org/wiki/Bridge_pattern
trait DrawingAPI {
def drawCircle(x:Double, y: Double, radius:Double)
}
class DrawingAPI1 extends DrawingAPI {
override def drawCircle(x: Double, y: Double, radius: Double) = {
printf("API1.circle at %f:%f radius %f\n", x, y, radius)
}
@daithiocrualaoich
daithiocrualaoich / gist:1189097
Created September 2, 2011 16:37
Scala Collections Pimp to add distinctBy(hash: ... => ...) for hash filterings
implicit def seq2Distinct[T, C[T] <: Seq[T]](tees: C[T]) = new {
import collection.generic.CanBuildFrom
import collection.mutable.{HashSet => MutableHashSet}
def distinctBy[S](hash: T => S)(implicit cbf: CanBuildFrom[C[T],T,C[T]]): C[T] = {
val builder = cbf()
val seen = MutableHashSet[S]()
for (t <- tees) {
if (!seen(hash(t))) {