Skip to content

Instantly share code, notes, and snippets.

View telekosmos's full-sized avatar
💭
👻

Guillermo C. Martínez telekosmos

💭
👻
View GitHub Profile
@telekosmos
telekosmos / aps_certificates_howto.md
Last active April 18, 2023 19:25
Preparing APS certificates

After requesting the certificate from Apple (to do this, go to Apple Developer site -> APNs Auth key -> [+]), download the .cer file (usually named aps_production.cer or aps_development.cer) from the iOS Provisioning Portal, save in a clean directory, and import it into Keychain Access.

It should now appear in the keyring under the "Certificates" category, as Apple Push Services. Inside the certificate you should see a private key (only when filtering for the "Certificates" category).

Export this private key as a .p12 file:

  • Right click in the certificate we are interested in Keychain and select Export...
  • Accept the default .p12 file format and then click Save
@telekosmos
telekosmos / guidesmiths.md
Last active January 25, 2023 19:03
Short intro to a microservices-cqrs-kafka experiment (Spanish only for now!!!)

Intro

El "experimento" que se me ha ocurrido es simplemente un tipo de tracking de actividad. El dominio para mí es bien conocido: se trata de simular usuarios jugando a un juego de mach-3 (cake swap de zynga en este caso) y hacer un seguimiento de los combos que en cada movimiento se generan en el tablero (un combo en estos juegos se logra al unir más de 3 fichas de cada color).

Simulando los clientes

Un poco off-topic porque no es node, he hecho un programa en Groovy para simular los jugadores/partidas/movimientos. El tema de elegir una plataforma Java es por el multithreading para simular usuarios jugando simultáneamente. Se le puede echar un vistazo al código en https://bitbucket.org/telekosmos/cakebot.

Las partes de backend están menos desarrolladas, es todavía un WIP con muchas cosas que hacer. Hasta ahora estuve más enfocado en los temas de arquitectura (DDD, CQRS) porque pienso que meterse a hacer microservicios puede ser muy bonito pero si se tiene algo a la vista o en mente, un big pict

@telekosmos
telekosmos / permissions-user-schema.sql
Last active November 21, 2022 17:47
Redshift querying system tables
-- username and permissions for a particular schema
select u.usename,
has_schema_privilege(u.usename,s.schemaname,'create') AS user_has_select_permission,
has_schema_privilege(u.usename,s.schemaname,'usage') AS user_has_usage_permission
FROM pg_user u
cross join (select distinct schemaname from pg_tables) s
where u.usename = '<the_username>'
and s.schemaname = '<the_schemaname>';
@telekosmos
telekosmos / uniq.js
Last active November 15, 2022 17:13
Remove duplicates from js array (ES5/ES6)
var uniqueArray = function(arrArg) {
return arrArg.filter(function(elem, pos,arr) {
return arr.indexOf(elem) == pos;
});
};
var uniqEs6 = (arrArg) => {
return arrArg.filter((elem, pos, arr) => {
return arr.indexOf(elem) == pos;
});
@telekosmos
telekosmos / functional-tree.ts
Created September 20, 2022 12:56
Tree and map
import * as O from 'fp-ts/Option'
import { pipe } from 'fp-ts/function'
// interface Tree<A> {
type Tree<A> = {
readonly left: O.Option<Tree<A>>
readonly data: A
readonly right: O.Option<Tree<A>>
}
const subt: Tree<number> = { left: O.none, data: 7, right: O.none }
@telekosmos
telekosmos / dynamic-accessors.js
Created December 17, 2015 16:47
ES6 Dynamic accessors
describe('dynamic accessors', () => {
it('a dynamic getter name is enclosed in [ and ]', function() {
const balance = 'yourMoney';
class YourAccount {
get [balance]() { return -Infinity; }
}
assert.equal(new YourAccount().yourMoney, -Infinity);
});
You will be given a list of stock prices for a given day and your goal is to return the
maximum profit that could have been made by buying a stock at the given price and then selling the
stock later on. For example if the input is: [45, 24, 35, 31, 40, 38, 11] then your program should
return **16** because if you bought the stock at $24 and sold it at $40, a profit of $16 was made and
this is the largest profit that could be made. If no profit could have been made, return -1.
If the given array is {100, 180, 260, 310, 40, 535, 695}, the maximum profit can earned by buying
on day 0, selling on day 3 (+210). Again buy on day 4 and sell on day 6 (+650). If the given array of prices is
sorted in decreasing order, then profit cannot be earned at all.
val jobOne: IO[Int] = IO(1+1)
val jobTwo: IO[String] = IO(List("hello", "guys").mkString(" "))
// Concurrent execution (manually)
for {
j1Fiber <- jobOne.start
j2Fiber <- jobTwo.start
i <- j1Fiber.join
s <- j2Fiber.join
} yield (i, s)
@telekosmos
telekosmos / semigroup-on-type-classes.md
Last active May 1, 2022 14:42
Type classes + implicit values + extension methods

First, we define the type classes, which are just traits in scala:

// Type classes for Semigroup and Monoid (we will be using monoid, but this is more formal)
trait Semigroup[A] {
  def op(x: A, y: A): A // should be associative
}

trait Monoid[A] extends Semigroup[A] {
  def zero: A