Skip to content

Instantly share code, notes, and snippets.

View truizlop's full-sized avatar
🏹
FP'ing with Bow

Tomás Ruiz-López truizlop

🏹
FP'ing with Bow
View GitHub Profile
@truizlop
truizlop / GetAchievements.java
Last active August 29, 2015 14:27
Retrieving achievements to display them in a custom view
public abstract class GetAchievements{
public void loadAchievements(final GoogleApiClient googleApiClient){
PendingResult<Achievements.LoadAchievementsResult> pendingAchievements = Games.Achievements.load(googleApiClient, true);
pendingAchievements.setResultCallback(new ResultCallback<Achievements.LoadAchievementsResult>() {
@Override
public void onResult(Achievements.LoadAchievementsResult loadAchievementsResult) {
Game game = Games.GamesMetadata.getCurrentGame(googleApiClient);
extractAchievements(loadAchievementsResult, game);
}
});
@truizlop
truizlop / GetLeaderboard.java
Last active June 6, 2017 07:29
Retrieving leaderboards to display them in a custom view
public abstract class GetLeaderboard{
private static final int MAX_RESULTS = 25;
/**
* Check documentation for LeaderboardVariant to see possible values for timeSpan and collection
*/
public void getTopScores(GoogleApiClient googleApiClient, String leaderboardID, int timeSpan, int collection) {
PendingResult<Leaderboards.LoadScoresResult> pendingScores = Games.
Leaderboards.loadTopScores(googleApiClient, leaderboardID,
timeSpan, collection, MAX_RESULTS, true);

Advanced Functional Programming with Scala - Notes

Copyright © 2017 Fantasyland Institute of Learning. All rights reserved.

1. Mastering Functions

A function is a mapping from one set, called a domain, to another set, called the codomain. A function associates every element in the domain with exactly one element in the codomain. In Scala, both domain and codomain are types.

val square : Int => Int = x => x * x
@truizlop
truizlop / HigherKinds.swift
Created April 22, 2018 08:48
Typeclasses exploration
import Foundation
class HK<F, A> {}
typealias HK2<F, A, B> = HK<HK<F, A>, B>
func id<A>(_ a : A) -> A {
return a
}
infix operator >>> : AdditionPrecedence
@truizlop
truizlop / Perlin.swift
Created June 28, 2018 09:44
Perlin noise in Swift
import Foundation
class Perlin {
private static let permutation = [
151,160,137,91,90,15,131,13,201,95,96,53,194,233,7,225,140,36,103,
30,69,142,8,99,37,240,21,10,23,190,6,148,247,120,234,75,0,26,197,
62,94,252,219,203,117,35,11,32,57,177,33,88,237,149,56,87,174,20,
125,136,171,168, 68,175,74,165,71,134,139,48,27,166,77,146,158,231,
83,111,229,122,60,211,133,230,220,105,92,41,55,46,245,40,244,102,
143,54, 65,25,63,161, 1,216,80,73,209,76,132,187,208, 89,18,169,200,
func testStringConcat() {
let a = "Hello, "
let b = "World!"
let result = "Hello, World!"
XCTAssertEqual(result, concat(first: a, second: b))
}
func concat(first : String, second : String) -> String {
return "Hello, World!"
}
func testStringConcat() {
let a = "Hello, "
let b = "World!"
let result = "Hello, World!"
XCTAssertEqual(result, concat(first: a, second: b))
let c = "Another "
let d = "example"
let result2 = "Another example"
XCTAssertEqual(result2, concat(first: c, second: d))
func concat(first : String, second : String) -> String {
if first == "Another " && second == "example" {
return "Another example"
} else {
return "Hello, World!"
}
}
func testStringConcat() {
let examples = [ ("Hello, ", "World!", "Hello, World!"),
("Another ", "example", "Another example"),
("Property-based ", "Testing", "Property-based Testing"),
("Swift ", "rocks", "Swift rocks"),
("One more ", "thing", "One more thing")]
examples.forEach{
XCTAssertEqual($0.2, concat(first: $0.0, second: $0.1))
}