Skip to content

Instantly share code, notes, and snippets.

View DanielBlanco's full-sized avatar

Daniel Blanco Rojas DanielBlanco

View GitHub Profile
@DanielBlanco
DanielBlanco / new-theme
Created May 21, 2021 18:38
Sets a new theme for kitty
#!/bin/bash
rm ~/.config/kitty/theme.conf
ln -s ./kitty-themes/themes/$1.conf ~/.config/kitty/theme.conf
@DanielBlanco
DanielBlanco / hello-ammonite
Created May 21, 2021 18:04
Script to be run with ammonite `amm hello-ammonite`
#!/usr/bin/env amm
println("hello world")
@DanielBlanco
DanielBlanco / FetchZioBackend.scala
Created February 9, 2021 19:53
An sttp+zio fetch backend (used in scala.js)
package app.util
import org.scalajs.dom.document
import org.scalajs.dom.experimental.{BodyInit, Response, Request => FetchRequest}
import scala.scalajs.js
import scala.scalajs.js.{Promise, UndefOr}
import sttp.capabilities.Effect
import sttp.client3.{AbstractFetchBackend, FetchOptions}
import sttp.client3.impl.zio._
import sttp.client3.internal.NoStreams
@DanielBlanco
DanielBlanco / PlayRunnableSpec.scala
Last active July 3, 2020 23:23
Starting a Play application within zio-test context.
package zio.test
import play.api.test._
import play.api.test.Helpers._
import zio.{UIO, URIO}
import zio.clock.Clock
import zio.duration._
import zio.test.environment.TestEnvironment
/** A Play 2.3+ runnable spec that provides testable versions of all of the
{
“took”: 2,
“timed_out”: false,
“_shards”: {
“total”: 11,
“successful”: 11,
“skipped”: 0,
“failed”: 0
},
@DanielBlanco
DanielBlanco / report.json
Created May 27, 2019 20:57
Possible migration report
{
"total": 237,
"reports": [
{
"succeed": true,
"details": {
"id": "57d14f5f2c0000491fd32c74"
}
},
{
@DanielBlanco
DanielBlanco / gius-question.hs
Last active June 9, 2022 17:31
Las edades de un padre y su hijo suman 66. La edad del padre es la edad del hijo, pero invertida. Cuantos años tienen?
-- I'm pretty sure the code can be simplified, but for 5mins work is OK :P
-- run with calculate(66)
ages maxAge = [ (a, b) | a <- [1..maxAge], b <- [1..maxAge] ]
calculate :: Integer -> [(Integer, Integer)]
calculate sumedAges = filter (valid sumedAges) $ ages sumedAges
valid:: Integer -> (Integer, Integer) -> Bool
valid sumedAges (x, y) =
@DanielBlanco
DanielBlanco / ecto_to_sql.ex
Created December 29, 2017 17:57
How to output Ecto's generated SQL to console.
{sql, _} = Repo.to_sql(:all, query)
IO.puts sql
class NullCustomer...
def plan=; end
def plan
BillingPlan.basic
end
def name=; end
def name
'occupant'
end
@DanielBlanco
DanielBlanco / replace-conditional-with-polymorphism.rb
Last active September 21, 2017 17:31
Replace Conditional with Polymorphism
class MountainBike
def price
case @type_code
when :rigid
(1 + @commission) * @base_price
when :front_suspension
(1 + @commission) * @base_price + @front_suspension_price
when :full_suspension
(1 + @commission) * @base_price + @front_suspension_price +
@rear_suspension_price