This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
from numpy.random import uniform | |
def update(S, k, v): | |
"Update value position `k` in time O(log n)." | |
d = S.shape[0] | |
i = d//2 + k | |
S[i] = v | |
while i > 0: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import Union | |
from tianshou.data import Batch | |
from tianshou.policy import RainbowPolicy | |
import numpy as np | |
import argparse | |
# See https://arxiv.org/abs/2006.01782 for paper - Temporally-Extended ε-Greedy Exploration | |
# See https://www.youtube.com/watch?v=Gi_B0IqscBE for video explaining where it's helpful | |
# See https://github.com/thu-ml/tianshou/blob/master/examples/atari/atari_rainbow.py for full example of how to setup args/net/collectors/etc. | |
def get_args(): | |
parser = argparse.ArgumentParser() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.lapanthere.bohemia | |
import kotlinx.coroutines.flow.Flow | |
import kotlinx.coroutines.flow.flow | |
import org.apache.kafka.clients.consumer.ConsumerRecord | |
import org.apache.kafka.clients.consumer.KafkaConsumer | |
import java.time.Duration | |
fun <K, V> KafkaConsumer<K, V>.asFlow(timeout: Duration = Duration.ofMillis(500)): Flow<ConsumerRecord<K, V>> = |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package nl.avwie | |
interface Tag<T> | |
interface Tagged<T> { | |
val tag: Tag<T> | |
} | |
class ComponentBag { | |
private val components = mutableMapOf<Tag<*>, Any>() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const myOwnEscapeFn = (sql, sqlFragment, type) => { | |
const actualType = type.domainBaseType || type; | |
if (actualType.category === "N") { | |
if (actualType.id === 20) { | |
return sql.fragment `to_b64_extid(${sqlFragment})`; | |
} | |
if (["21" /* int2 */, | |
"23" /* int4 */, | |
"700" /* float4 */, | |
"701" /* float8 */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
/* | |
* References: | |
* Initial idea: https://www.cse.wustl.edu/~jain/papers/ftp/psqr.pdf | |
* Based on implementation: https://github.com/skycmoon/P2 | |
* | |
* Author: | |
* Emrul Islam <[email protected]> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import torch | |
from flair.data import Sentence, Dictionary | |
from flair.data_fetcher import NLPTaskDataFetcher, NLPTask | |
from flair.embeddings import TokenEmbeddings, WordEmbeddings, StackedEmbeddings, CharacterEmbeddings, \ | |
PooledFlairEmbeddings, FlairEmbeddings | |
from flair.visual.training_curves import Plotter | |
from flair.trainers import ModelTrainer | |
from flair.models import SequenceTagger | |
from flair.datasets import ColumnCorpus |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# List unique values in a DataFrame column | |
# h/t @makmanalp for the updated syntax! | |
df['Column Name'].unique() | |
# Convert Series datatype to numeric (will error if column has non-numeric values) | |
# h/t @makmanalp | |
pd.to_numeric(df['Column Name']) | |
# Convert Series datatype to numeric, changing non-numeric values to NaN | |
# h/t @makmanalp for the updated syntax! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Assuming you have an enum type like this. | |
You want to rename 'pending' to 'lodged' | |
*/ | |
CREATE TYPE dispute_status AS ENUM('pending', 'resolved', 'open', 'cancelled'); | |
BEGIN; | |
ALTER TYPE dispute_status ADD VALUE 'lodged'; | |
UPDATE dispute SET status = 'lodged' WHERE status = 'pending'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data class User(@JsonProperty("userName") val name: String) | |
val userObj = User("John") | |
JsoniterKotlinSupport.enable() | |
JsoniterAnnotationSupport.enable() | |
val jsonUserString = JsonStream.serialize(userObj) | |
// jsonUserString will contain: {"userName":"John"} |
NewerOlder