Skip to content

Instantly share code, notes, and snippets.

View Rafailong's full-sized avatar
🤠

ravila Rafailong

🤠
  • Mexico
View GitHub Profile
@Rafailong
Rafailong / index.js
Created December 10, 2015 04:44
Y-Combinator
var Y = require('./y');
function factorial(proc) {
return function (n) {
return n === 0 ? 1 : (n * proc(n - 1));
}
}
var fact = Y(factorial);
var r = fact(3);
console.log(r);
'use strict';
function task(number) {
var r = 0;
for (var i = 0; i < number; i++) {
var frac = 1 / ((3 * i) + 1);
r = r + frac;
}
@Rafailong
Rafailong / unique.js
Created January 26, 2017 19:39
unique based on reduce
var rr = [1,2,3,1,3,4,5];
var r = rr.reduce(function (acc, current) {
return acc.indexOf(current) < 0 ? acc.concat(current) : acc;
}, []);
// r = [1, 2, 3, 4, 5]
@Rafailong
Rafailong / script.scala
Created March 9, 2017 23:57
Usergrid Java SDK Retrieving Counter
private def retrieveCounters(counter: String): Unit = {
val usergridBaseURL = Usergrid.getInstance().clientAppUrl() // https://api.usergrid.com/my-org/my-app
val url = s"$usergridBaseURL/counters?counter=$counter"
val request = new UsergridRequest(UsergridHttpMethod.GET, UsergridRequest.APPLICATION_JSON_MEDIA_TYPE, url, Usergrid.authForRequests())
val result = Usergrid.sendRequest(request)
println(result.getStatusCode, result.getResponseError.getErrorDescription)
}
// run this in VsCode command palette
// F#
ext install Ionide.ionide-fsharp
ext install Ionide.ionide-fake
ext install Ionide.ionide-paket
// varia
ext install nwolverson.ide-purescript
ext install UCL.haskelly
@Rafailong
Rafailong / init.coffee
Last active June 21, 2017 16:48
atom editor sync-settings
# Your init script
#
# Atom will evaluate this file each time a new window is opened. It is run
# after packages are loaded/activated and after the previous editor state
# has been restored.
#
# An example hack to log to the console when each text editor is saved.
#
# atom.workspace.observeTextEditors (editor) ->
# editor.onDidSave ->
@Rafailong
Rafailong / fpmax.scala
Created August 2, 2018 15:19 — forked from jdegoes/fpmax.scala
FP to the Max — Code Examples
package fpmax
import scala.util.Try
import scala.io.StdIn.readLine
object App0 {
def main: Unit = {
println("What is your name?")
val name = readLine()
@Rafailong
Rafailong / DockerKafkaService.scala
Created February 28, 2019 15:50
Integration Tests in sbt projects.
package me.rafaavila
import com.whisk.docker._
trait DockerKafkaService extends DockerKit {
def KafkaAdvertisedPort = 9092
val ZookeeperDefaultPort = 2181
lazy val kafkaContainer = DockerContainer("spotify/kafka")
@Rafailong
Rafailong / one.scala
Created March 22, 2019 17:45
path to fp - currying
// base function
def add(a: Int, b: Int): Int = a + b
// curried form
def addCurried(a: Int)(b: Int): Int = a + b
/**
* In scala functions have the method `curried`
*/
val addCurriedTwo = (add _).curried
@Rafailong
Rafailong / five.scala
Created April 16, 2019 15:38
path to fp - partial function applicaiton
val addCurried: Int => Int => Int = (add _).curried
print(addCurried(1)(2))