Skip to content

Instantly share code, notes, and snippets.

View tauzen's full-sized avatar

Krzysztof Mioduszewski tauzen

View GitHub Profile
@joost-de-vries
joost-de-vries / recordSuspend.kt
Last active June 14, 2023 12:17
micrometer record Kotlin coroutine suspend functions
class Service(val microMeter: MicroMeterRegistry, val otherService: OtherService){
suspend fun service(id: Long){
recordAsync("theService") { otherService.getTheThing(id) }
}
private suspend fun <A> recordAsync(name: String, block: suspend () -> A): A = metricsRegistry.timer(name)
.recordSuspend(block)
}
suspend fun <A> Timer.recordSuspend(block: suspend () -> A): A =
@eribeiro
eribeiro / search_relevance_evaluation_metric.py
Last active August 21, 2022 13:20
Search relevance evaluation metrics
##
## Python implementations of the search relevance evaluation metrics described at
## https://opensourceconnections.com/blog/2020/02/28/choosing-your-search-relevance-metric/
##
##
def precision(docs):
return sum(docs) / len(docs) if docs else 0
def avg_precision(docs):
@jiahao87
jiahao87 / text_preprocessing.py
Last active August 17, 2023 01:31
Full code for preprocessing text
from bs4 import BeautifulSoup
import spacy
import unidecode
from word2number import w2n
import contractions
nlp = spacy.load('en_core_web_md')
# exclude words from spacy stopwords list
deselect_stop_words = ['no', 'not']
/**
* Educational "Free-list" memory allocator.
*
* Maintains explicit list of free memory blocks, reuses blocks on free.
* Implements "first-fit" strategy. Uses pre-allocated heap of 64 bytes,
* with 32-bit machine word size.
*
* TODO:
*
* - Implement "best-fit" strategy
@filipstachura
filipstachura / poland_woj.json
Last active July 29, 2022 21:24
GeoJSON with Polish Administrative Areas Boundaries
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@bhtucker
bhtucker / upsert.py
Last active April 3, 2024 15:56
A demonstration of Postgres upserts in SQLAlchemy
"""
Upsert gist
Requires at least postgres 9.5 and sqlalchemy 1.1
Initial state:
[]
Initial upsert:
@jsdf
jsdf / ReactNativeRefreshableListView.js
Last active September 15, 2023 07:29
React Native pull down to refresh ListView
// for an updated version see https://github.com/jsdf/react-native-refreshable-listview
var React = require('react-native')
var {
ListView,
ActivityIndicatorIOS,
StyleSheet,
View,
Text,
} = React
@kamituel
kamituel / gist:38ff7a926cdd96d69076
Last active August 29, 2015 14:14
Read file from app package with extracting to the filesystem first
let app = DOMApplicationRegistry.getAppByManifestURL(manifestURL);
if (!app) {
// handle
}
let appDir = FileUtils.getDir("coreAppsDir", ["webapps", app.id], false);
let appPackage = appDir.clone();
appPackage.append("application.zip");
let zipReader = Cc["@mozilla.org/libjar/zip-reader;1"]
@kamituel
kamituel / gist:0aaf13c6f329c559476c
Created January 26, 2015 13:13
Read file from app package without extracting to the filesystem
Cu.import("resource://gre/modules/FileUtils.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "NetUtil",
"resource://gre/modules/NetUtil.jsm");
let app = DOMApplicationRegistry.getAppByManifestURL(manifestURL);
if (!app) {
// handle
}
@learncodeacademy
learncodeacademy / generators.md
Last active January 7, 2024 11:58
What are Javascript Generators?

##what are generators##

  • They're pausable functions, pausable iterable functions, to be more precise
  • They're defined with the *
  • every time you yield a value, the function pauses until .next(modifiedYieldValue) is called
var myGen = function*() {
  var one = yield 1;
  var two = yield 2;
  var three = yield 3;
 console.log(one, two, three);