Skip to content

Instantly share code, notes, and snippets.

View Grohden's full-sized avatar
:shipit:
*tec tec tec noises*

Gabriel Rohden Grohden

:shipit:
*tec tec tec noises*
View GitHub Profile
@Grohden
Grohden / AngularServices.js
Created February 7, 2018 11:38
Get rid of AngularJS dependency injection using webpack
//An memoize fn would be good to use here.
const getService = (serviceName) => angular.element(document.body).injector().get(serviceName);
export default new Proxy({}, {
get (target, prop) {
return getService(prop);
}
});
@Grohden
Grohden / LateMapBox.kt
Last active December 7, 2018 14:58
A lazy way to execute a map on a collection
import java.lang.ref.WeakReference
// It doesn't matter for the receiver which one is the received argument
typealias LateBoxList<R> = List<LateMapBox<*, R>>
fun <T, R> Iterable<T>.mapAsLateBox(mapper: (T) -> R): List<LateMapBox<T, R>> {
return this.map { LateMapBox(it, mapper) }
}
/**
@Grohden
Grohden / IntercomExtensions.kt
Created January 26, 2019 01:31
Intercom issue
/*
* This function doesn't work. I get a tiny error log saying that i cannot
* update the email of a anonymous user and that i should call `registerIdentifiedUser`
*
* In the `RealIntercom` class, on the `registerIdentifiedUser`
* there's a if condition that fails in this case
* `if (userIdentity.canRegisterIdentifiedUser(userRegistration))`
*
* It fails cuz the `Registration` class expects the `updateState` to be called
* at least once, `withEmail` and `withUserId` are the ones that do that
<- $ # module settings where
{ map, join, concat, filter, empty, fold, all, sort-by, any } = require 'prelude-ls'
response = JSON.parse """
{
"requestRepository":true,
"enterprises":[
{
"code":"T1",
@Grohden
Grohden / wubba-lubba-dub-dub.kt
Last active February 5, 2019 23:28
what have i done
abstract class QuerySpec<Manager, Entity, TRepository : Repository<Manager, Entity>, Return> {
abstract fun fetchResult(arg: Manager): Return
}
abstract class Repository<Manager, Entity> {
abstract val manager: Manager
fun <TQuerySpec : QuerySpec<Manager, Entity, Repository<Manager, Entity>, Return>, Return> executeQuery(querySpec: TQuerySpec): Return {
return querySpec.fetchResult(manager)
}
@Grohden
Grohden / StdExtensions.kt
Last active March 14, 2019 13:41
My common extension functions for kotlin
/**
* Forks a nullable into a non nullable,
*
* This differs from the if else expression
* which is thread unsafe and doesn't guarantee
* the non nullability even if the value was validated as non null
* by the if expression (due to concurrency)
* NOTE: need to check this :D, probably i need to use contracts like the std to assure what
* i said above
*
@Grohden
Grohden / ExampleActivity.kt
Last active March 14, 2019 16:40
Menu icon with count/badge - Android
/* All the massive/repetitive/boring activity code above */
override fun onPrepareOptionsMenu(menu: Menu) {
super.onPrepareOptionsMenu(menu)
val filterMenu = menu.findItem(R.id.actionFilter)
/*
@Grohden
Grohden / marcelo_php.md
Last active April 17, 2019 20:20
monorepo

Desvantagens

  • Tempos de build e testes
  • Tamanho do repositório (tempo de checkout)
  • Nescessidade de tooling dedicado
  • Tendencia a aumentar o acoplamento entre as dependências

Vantagens

@Grohden
Grohden / test.ts
Last active May 7, 2019 21:15
My try on dependent types + conditional types using typescript to validate optional args based on a key
type Routes = {
a: {
string: string
}
b: undefined
}
type NullableKeys<T, K extends keyof T> = T[K] extends null | undefined
? K
@Grohden
Grohden / make-revision-file.js
Created May 16, 2019 04:56
NodeJs script to read two specific files for translation and write them together for better revision
const fs = require('fs');
const english = require("./english.json").text
const portuguese = require("./portuguese.json").text
const DEFAULT_KEY = "en-US"
const accumlator = {}
// Acc the english ones
english.reduce((all, value) => {
all[value.key] = {