Skip to content

Instantly share code, notes, and snippets.

@ccw
ccw / git-buggy.sh
Created April 1, 2019 04:53
Revised from git-effort to filter files by line changed
#!/usr/bin/env bash
# reset environment variables that could interfere with normal usage
export GREP_OPTIONS=
# put all utility functions here
# make a temporary file
git_extra_mktemp() {
mktemp -t "$(basename "$0")".XXXXXXX
}
object Turnstile {
def getTimes(time: Array[Int], direction: Array[Int]): Array[Int] = {
var lt = -1
var ld = 1
val result = Array.fill(time.length) { 0 }
time.foldLeft(time.zipWithIndex) { (q, _) =>
val nt = q.head._1
package main
import "sort"
type byLength []string
func (s byLength) Len() int {
return len(s)
}
package main
import "fmt"
type Person struct {
idx int
ts int32
dir int32
}
@ccw
ccw / git-victim.sh
Last active October 10, 2021 17:43
modified from git-guilt to show the line changes per file
#!/usr/bin/env bash
# make a temporary file
git_extra_mktemp() {
mktemp -t "$(basename "$0")".XXXXXXX
}
for param in $*
do
case $param in
@ccw
ccw / euler_26.go
Created December 3, 2018 01:10
Project Euler #26 in Golang
package main
import (
"fmt"
"math/big"
"sort"
"strings"
)
func findReciprocal(s string) string {
@ccw
ccw / FinatraOperation.scala
Last active January 7, 2017 04:18
FinatraSwagger parameter resolution example
package com.github.xiaodongw.swagger.finatra
import com.google.inject.Guice
import com.twitter.finatra.json.Parameterizable
import com.twitter.finagle.http.MediaType
import com.twitter.finatra.json.ParameterizableResolver._
import com.twitter.inject.Injector
import io.swagger.models._
import io.swagger.models.parameters._
import io.swagger.models.properties.{ArrayProperty, Property, RefProperty}
@ccw
ccw / Dockerfile
Created December 9, 2016 08:55
Redis Sentinel Docker
FROM redis:3-alpine
COPY master.conf /usr/local/etc/redis/master.conf
COPY slave.conf /usr/local/etc/redis/slave.conf
COPY sentinel.conf /usr/local/etc/redis/sentinel.conf
RUN mkdir -p /var/log/redis
RUN mkdir -p /var/run/redis
RUN mkdir -p /var/lib/redis
RUN chown redis:redis /var/log/redis
package com.twitter.finagle.zookeeper
import com.twitter.common.zookeeper.ServerSet.EndpointStatus
import com.twitter.common.zookeeper.{ServerSet, ServerSetImpl, ZooKeeperClient}
import com.twitter.finagle.{Announcer, Announcement}
import com.twitter.util.{Future, NonFatal, Promise}
import java.net.InetSocketAddress
import java.util.concurrent.LinkedBlockingQueue
import scala.collection.JavaConverters._
import scala.collection.mutable
@ccw
ccw / proxy.scala
Created April 20, 2016 16:41
type parameters and type fields
trait Service {
type A
type B
def getA:Option[A]
def getB:Option[B]
}