Skip to content

Instantly share code, notes, and snippets.

View guizmaii's full-sized avatar
🏄‍♂️

Jules Ivanic guizmaii

🏄‍♂️
View GitHub Profile
@guizmaii
guizmaii / shared-state-in-fp.md
Created June 2, 2018 11:26 — forked from gvolpe/shared-state-in-fp.md
Shared State in pure Functional Programming

Shared State in pure Functional Programming

Newcomers to Functional Programming are often very confused about the proper way to share state without breaking purity and end up having a mix of pure and impure code that defeats the purpose of having pure FP code in the first place.

Reason why I decided to write up a beginner friendly guide :)

Use Case

We have a program that runs three computations at the same time and updates the internal state to keep track of the

@guizmaii
guizmaii / LagomSingletonEntity.scala
Last active July 30, 2018 15:16
Lagom SingletonEntity
import com.lightbend.lagom.scaladsl.persistence.{PersistentEntity, PersistentEntityRef}
import monix.eval.Task
import play.api.libs.json.Format
object SingletonEntityRegistry {
implicit final class SingletonEntityRegistry(val registry: PersistentEntityRegistry) extends AnyVal {
def singletonRefFor[T <: SingletonEntity: ClassTag]: PersistentEntityRef[T#Command] =
registry.refFor[T](SingletonEntity.id.underlying)
}
@guizmaii
guizmaii / tagless_final_crawler.scala
Created September 14, 2018 10:15
Tagless Final Crawler
package net.degoes
import scalaz.Scalaz._
import scalaz._
import scalaz.zio._
import scala.io.{Codec, Source}
import scala.language.higherKinds
import scala.util.{Failure, Success, Try}
package net.degoes
import scalaz.zio._
import scala.io.{Codec, Source}
import scala.util.{Failure, Success, Try}
import scalaz._
import Scalaz._
/**

Applied Functional Programming with Scala - Notes

Copyright © 2016-2018 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
@guizmaii
guizmaii / stats_logger.rb
Created November 14, 2018 16:45 — forked from LeZuse/stats_logger.rb
Puma plugin for stats logging on Heroku
Puma::Plugin.create do
def production?
ENV.fetch('RACK_ENV', 'development') == 'production'
end
def log(msg)
if production?
Rails.logger.info msg
else
puts msg
Flat profile of 398.33 secs (23810 total ticks): Ruby-0-JIT-1
Interpreted + native Method
0.7% 8 + 0 org.jruby.ir.targets.IRBytecodeAdapter6.pushBoolean
0.4% 5 + 0 java.lang.Class.getDeclaredFields0
0.3% 4 + 0 org.jruby.ir.targets.JVMVisitor.PushMethodBindingInstr
0.3% 3 + 0 org.jruby.ir.targets.JVMVisitor.oneFixnumArgNoBlockCallInstr
0.3% 3 + 0 org.jruby.ir.representations.CFG.build
0.3% 3 + 0 java.util.regex.Pattern.split
0.2% 2 + 0 org.jruby.ir.targets.JVMVisitor.RescueEQQInstr
=> Booting Puma
=> Rails 4.2.10 application starting in production on http://localhost:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
E, [2018-11-27T17:20:38.796620 #93071] ERROR -- ddtrace: [ddtrace] (/Users/jules/.rvm/gems/jruby-9.1.17.0/gems/ddtrace-0.17.2/lib/ddtrace/transport.rb:212:in `log_error_once') Connection refused - Failed to open TCP connection to 127.0.0.1:8126 (Connection refused - connect(2) for "127.0.0.1" port 8126)
Puma starting in single mode...
* Version 3.12.0 (jruby 9.1.17.0 - ruby 2.3.3), codename: Llamas in Pajamas
* Min threads: 16, max threads: 16
* Environment: production
* Listening on tcp://localhost:3000
=> Booting Puma
=> Rails 4.2.10 application starting in production on http://localhost:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
Puma starting in single mode...
* Version 3.12.0 (jruby 9.1.17.0 - ruby 2.3.3), codename: Llamas in Pajamas
* Min threads: 16, max threads: 16
* Environment: production
* Listening on tcp://localhost:3000
Use Ctrl-C to stop
@guizmaii
guizmaii / each_benchmark.rb
Created December 10, 2018 19:59 — forked from jodosha/each_benchmark.rb
Ruby benchmark: Array#each vs for x in array
#!/usr/bin/env ruby -w
require "benchmark"
TIMES = 100_000
ARRAY = (1..1_000).to_a
Benchmark.bm(30) do |b|
b.report "each" do
TIMES.times do |i|
ARRAY.each do |element|