Skip to content

Instantly share code, notes, and snippets.

@miguelsaddress
miguelsaddress / actions-1.js
Created April 24, 2018 12:56
A Basic React + Redux introductory tutorial
// reducer_active_contact.js
export default function(state = null, action) {
switch (action.type) {
case 'CONTACT_SELECTED':
return action.payload
}
// i dont care about the action because it is not inside my
// list of actions I am interested int (case statements inside the switch)
return state
}
# code from: https://code.tutsplus.com/articles/what-is-genserver-and-why-should-you-care--cms-29143
defmodule MathServer do
def start do
spawn &listen/0
end
defp listen do
receive do
{:sqrt, caller, arg} -> send(caller, {:result, do_sqrt(arg)})
// actions/action_select_contact.js
function selectContact(contact) {
return {
type: 'CONTACT_SELECTED',
payload: contact
}
}
export default selectContact;
@miguelsaddress
miguelsaddress / Main.scala
Created May 26, 2017 09:10
Fetching Public User info from Github with Github4s
import scala.concurrent.Future
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.duration._
import scala.concurrent.Await
import github4s.Github
import github4s.Github._
import github4s.GithubResponses.GHResult
import github4s.jvm.Implicits._
import akka.actor._
import scala.concurrent.Await
import scala.concurrent.duration._
object RebelAkktorsGist extends App {
/****************************
* Messages *
***************************/
@miguelsaddress
miguelsaddress / Optionals.php
Last active June 15, 2019 15:18
A take on optionals in PHP
<?php
error_reporting(E_ALL ^ E_NOTICE);
abstract class Option {
protected $value;
public function __construct($value) {
if (isset($value)) return some($value);
else return none();
}
@miguelsaddress
miguelsaddress / FizzBuzz.scala
Created March 6, 2016 14:24
Scala FizzBuzz implementation
import scala.util.Try
object FizzBuzz {
def main(args: Array[String]): Unit = {
val iterations = Try(args(0).toInt).getOrElse(0)
(1 to iterations).foreach {i =>
if (i % 15 == 0) println(s"$i - FizzBuzz")
else if (i % 3 == 0) println(s"$i - Fizz")
else if (i % 5 == 0) println(s"$i - Buzz")
else println(s"$i")
@miguelsaddress
miguelsaddress / Output.txt
Created March 6, 2016 13:48
Este gist contiene las pruebas de Scala Rx de los post del blog : https://scalerablog.wordpress.com
***************************************
ScaleraBlog: Scala Rx Example, 1st Post
***************************************
a vale 1
b vale 2
Lo guardamos en resultado, que es reactiva de a y b: 3
Cambiamos el valor de b=6
Resultado ahora debería valer 7
7
@miguelsaddress
miguelsaddress / memInfo.scala
Last active October 26, 2020 16:13
Fetch info about the memory of you machine with Scala
import scala.language.postfixOps
import scala.util.{Success, Failure}
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.duration._
import scala.concurrent._
import scala.util.Try
import sys.process._
import concurrent.Future
import concurrent.Promise
@miguelsaddress
miguelsaddress / ProgressBarExample.scala
Created February 18, 2016 11:22
Progress bar in scala. Simulates a line with progress feedback of an action in the console
import scala.util.Random
object ProgressBar extends App {
// list of times to sleep between each step of the progess, with different probabilities
val timesToSleep = List(500, 500, 500, 500, 600, 600, 600, 1000, 1000, 1000, 2000, 2000, 5000)
print("Progress [ ]")
Thread.sleep(500);
// 11 backspaces to override " ]"