Skip to content

Instantly share code, notes, and snippets.

@Timshel
Timshel / Settings
Created November 2, 2022 13:19
Edit TrueBattleLoot.dll
using System;
namespace TrueBattleLoot
{
// Token: 0x0200000B RID: 11
public class Settings
{
// Token: 0x17000001 RID: 1
// (get) Token: 0x0600000A RID: 10 RVA: 0x00002059 File Offset: 0x00000259
public string Id
@Timshel
Timshel / Dockerfile
Created November 26, 2020 17:01
AiStore test
FROM ubuntu:20.04
RUN apt-get clean \
&& apt-get update \
&& apt-get --no-install-recommends -y install \
curl \
git \
ca-certificates \
wget \
vim \
@Timshel
Timshel / query.md
Last active May 3, 2018 08:24
Sort switch (tested on PG 9.6 and 10.3)
SET trace_sort TO on;
SET client_min_messages TO log;
explain analyze select id, sum(count) from sort_test group by id order by sum(count) desc limit 100

Output :

LOG:  begin tuple sort: nkeys = 1, workMem = 4096, randomAccess = f
LOG:  switching to bounded heapsort at 201 tuples: CPU 0.01s/1.30u sec elapsed 1.31 sec
@Timshel
Timshel / RawSqlInterpolator.scala
Last active April 9, 2018 10:13
Doobie Raw sql interpolation
import doobie.util.param.Param
import doobie.util.pos.Pos
/**
* Custom Interpolator with support for raw sql.
* `Composite.toList` is used retrieve and insert raw sql.
*/
final class RawSqlInterpolator(private val sc: StringContext)(implicit pos: Pos) {
private def mkFragment[A](a: A)(implicit ev: Param[A]): Fragment = {
val interleave = ev.composite.toList(a).map {
@Timshel
Timshel / JsonStreaming.scala
Created March 28, 2017 16:35
Stream a Json array
import akka.NotUsed
import akka.stream.scaladsl.Flow
import akka.util.ByteString
import jto.validation._
import play.api.libs.json._
object JsonStreaming {
implicit val facade: jawn.Facade[JsValue] =
new jawn.SimpleFacade[JsValue] {
@Timshel
Timshel / Service.scala
Last active October 12, 2016 08:33
Preparation for Play 2.5 migration
package service.campaigns
import org.slf4j.LoggerFactory
class Service(
apnClient: ApnClient,
mmClient: MediaMathClient,
pushedCampaigns: PushedCampaigns,
fanoutHelper: FanoutHelper.type
) {
@Timshel
Timshel / Ring.scala
Created October 4, 2016 13:30
RingBuffer
/**
* Implementation of a ring buffer optimised for our use case.
* There is minimum check and it's not thread safe
*/
class Ring[T: reflect.ClassTag](size: Int) {
import java.lang.ArrayIndexOutOfBoundsException
protected val buffer = Array.ofDim[T](size)
protected var first: Int = 0
protected var last: Int = -1
@Timshel
Timshel / RateLimiter.scala
Last active January 24, 2019 20:29
RateLimiter (call per time and parallelism)
import akka.stream.{ActorMaterializer, OverflowStrategy}
import akka.stream.scaladsl.{Keep, Sink, Source}
import scala.concurrent.{ExecutionContext, Future, Promise}
import scala.concurrent.duration.FiniteDuration
class RateLimiter(
val limit: Int,
val time: FiniteDuration,
val parallelism: Int,
val bufferSize: Int
@Timshel
Timshel / SlidingThrotlle.scala
Last active January 24, 2019 20:30
Implementation of a Throttle with a sliding window (with a probably useless `nice` delay)
import akka.stream.impl.fusing.GraphStages.SimpleLinearGraphStage
import akka.stream.stage._
import akka.stream._
import scala.concurrent.duration.{ FiniteDuration, _ }
/**
* Implementation of a Throttle with a sliding window
*/
class SlidingThrottle[T]
@Timshel
Timshel / helpers.scala
Created June 29, 2016 16:09
Custom `WithApplication` to expose main component
package helpers
import org.openqa.selenium.WebDriver
import org.specs2.execute.{ AsResult, Result }
import org.specs2.mutable.Around
import org.specs2.specification.Scope
import play.api.{ Application, ApplicationLoader, Environment, Mode }
import play.core.server.{ NettyServer, ServerProvider }
abstract class WithApplication extends Around with Scope {