Skip to content

Instantly share code, notes, and snippets.

View muuki88's full-sized avatar
😘
Taking care of my daugther

Muki Seiler muuki88

😘
Taking care of my daugther
View GitHub Profile
@muuki88
muuki88 / adtag.js
Last active May 28, 2024 21:40
TCF 2.2 Wait for consent
// example loading adtag.js , 755 is the google vendor id
loadWithConsent(755, [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ], function() {
var adtag = document.createElement('script');
adtag.type = 'module'; adtag.async = true;
adtag.src = 'https://studis.h5v.eu/latest/moli.min.mjs';
var outs = document.getElementsByTagName('script')[0];
outs.parentNode.insertBefore(adtag, outs);
});
@muuki88
muuki88 / KeyValueStore.serialization.ts
Created September 14, 2018 08:29
KeyValueStore Serialization
const deserializeBoolean = (value: string) => value === 'true';
const deserializeString = (value: string) => value;
const deserializeNumber = (value: string) => parseInt(value);
const serializeBoolean = (value: boolean) => value ? 'true' : 'false';
const serializeString = (value: string) => value;
const serializeNumber = (value: number) => number.toFixed();
/**
* Each key-value storage key needs a function to deserialize its string value
* from the database into its own type. Each type is specified in KeyValueStorage.
@muuki88
muuki88 / KeyValueStore.v3.ts
Created September 14, 2018 08:21
KeyValue Storage
type KeyValueStorage = {
'setting1': boolean;
'setting2': string;
'setting3': number;
};
/** all possible keys for the key-value storage */
type KeyValueStorageKey = keyof KeyValueStorage;
interface UserStorage {
@muuki88
muuki88 / KeyValueStore.v2.ts
Created September 14, 2018 08:15
KeyValue Storage - Typed Keys
type UserStorageKey = 'setting1' | 'setting2' | 'setting3';
interface UserStorage {
/** set a value for a specific key */
set(key: UserStorageKey, value: string): void;
/** get the value for a specific key. If not present return null*/
get(key: UserStorageKey): string | null;
}
@muuki88
muuki88 / KeyValueStore.v1.ts
Created September 14, 2018 07:49
KeyValue Storage - Untyped
interface UserStorage {
/** set a value for a specific key */
set(key: string, value: string): void;
/** get the value for a specific key. If not present return null*/
get(key: string): string | null;
}
@muuki88
muuki88 / jenkins-sbt.groovy
Created November 2, 2016 17:03
Jenkins 2.0 SBT build pipeline
node {
stage('Git') {
git 'https://github.com/muuki88/activator-play-cluster-sample.git'
}
stage('Build') {
def builds = [:]
builds['scala'] = {
// assumes you have the sbt plugin installed and created an sbt installation named 'sbt-0.13.13'
sh "${tool name: 'sbt-0.13.13', type: 'org.jvnet.hudson.plugins.SbtPluginBuilder$SbtInstallation'}/bin/sbt compile test"
}
// user endpoint which sets a UserContext
val userMean: Endpoint[MeanForUser] = get("weather" / "mean" / "user" :: long) { userId: Long =>
val userContext = UserContext(userId)
Contexts.broadcast.let(UserContext, userContext) {
client.mean().map(mean => Ok(MeanForUser(mean, userId)))
}
}
package net.gutefrage.context
import com.twitter.finagle.context.Contexts
import com.twitter.finagle.util.ByteArrays
import com.twitter.io.Buf
import com.twitter.util.{Return, Throw, Try}
case class UserContext(userId: Long)
/**
// import flaggable type class
import Env._
// start a service in an environment with
// --env prod
val env = flag[Env]("env", Env.Local, "environment this server runs")
val port = flag[Int]("port", 8080, "port this server should use")
val server = ThriftMux.server
.withLabel("temperature-service")
package net.gutefrage
import com.twitter.finagle.Dtab
/**
* Holds different delegation tables
*/
object Dtabs {
def init(): Unit = {