Skip to content

Instantly share code, notes, and snippets.

@AfonsoTsukamoto
AfonsoTsukamoto / typescript-immutablejs.d.ts
Created June 3, 2020 07:43
Utility types for immutable js with typescript
// import types: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-9.html#import-types
// allow us to import types on global type definitions
// To use, eg, for a map of User:
// type UserMap = ImmutableMap<User>;
interface ImmutableMap<T> extends import('immutable').Map<string, any> {
get<K extends keyof T>(name: K): T[K];
}
type ImmutableMapList<T> = import('immutable').List<ImmutableMap<T>>;
@AfonsoTsukamoto
AfonsoTsukamoto / split-keep-mark.clj
Created July 2, 2019 10:00
Keep the separator for a clojure split using lookahead+lookbehind
;; example to split on @
(clojure.string/split "carolyne.jones@gnail.com" #"(?=@)|(?<=@)")
al: Albania
dz: Algeria
ao: Angola
ai: Anguilla
ag: Antigua and Barbuda
ar: Argentina
am: Armenia
au: Australia
at: Austria
az: Azerbaijan
@AfonsoTsukamoto
AfonsoTsukamoto / js.vim
Last active February 1, 2018 13:27
vim navigate to import
" From https://damien.pobel.fr/post/configure-neovim-vim-gf-javascript-import/
set path=.,src
set suffixesadd=.js,.jsx
function! LoadMainNodeModule(fname)
let nodeModules = "./node_modules/"
let packageJsonPath = nodeModules . a:fname . "/package.json"
if filereadable(packageJsonPath)
return nodeModules . a:fname . "/" . json_decode(join(readfile(packageJsonPath))).main
(ns question.pool
(:refer-clojure :exclude [take])
(:require
[clojure.tools.logging :as log]))
(def pool (ref []))
(defn take
[pool]
(dosync
(def queue-size 30)
(defn make-object []
(.. some object ..))
(defn build-queue [_]
(let [block-queue (LinkedBlockingQueue. (int queue-size))]
(do
(repeat queue-size (.put block-queue (make-object)))
block-queue)))
(defn trutty-map [matcher]
(if (.find matcher)
(lazy-seq
(cons (.group matcher)
(trutty-map matcher)))))
{
"explain": true,
"query": {
"filtered": {
"query": {
"match": {
"content": "github"
}
},
"filter": {
@AfonsoTsukamoto
AfonsoTsukamoto / parallel_multiprocess.py
Last active September 25, 2015 17:39
A function for the min definition necessary for parallel operations with python's multiprocessing
import multiprocessing
# Parallel
# So, it goes like this:
# Given the number of 'to process' items,
# Check how the distribution for cores will be (eg: 100 items on 2 cores = 50)
# Then, split items in *number of cores* collections and spread them aroung a
# subprocess pool
# To split the set, we create the interval [0, number_of_items] and make it
# go up the original items collection *number of cores* times
@AfonsoTsukamoto
AfonsoTsukamoto / ner_py_serv.py
Last active September 18, 2015 18:38
StanfordNER with python wrapper
In [4]: ext.extract(u"""Hi Sebastian, Thanks for reaching out to us. My name is Kevin and I'll be happy to help you out! :) I understand that you're looking to use OAuth 2.0. Unfortunately, we don't support OAuth 2.0. We support HTTP Basic Auth. If you haven't already, you can find your API Key under your Account Details. Would you mind telling me a little more about why you'd like you use OAuth 2.0? Cheers, Kevin""")
Out[4]: [u'HTTP Basic Auth', u'Sebastian', u'Kevin', u'Kevin']