Skip to content

Instantly share code, notes, and snippets.

View shinnya's full-sized avatar

foobar shinnya

  • Japan
View GitHub Profile
@eatonphil
eatonphil / thread.ml
Last active April 7, 2018 01:15
Basic thread logic based on condition variables in Poly/ML
(*
* Tested in Poly/ML. To compile: `polyc thread.ml && ./a.out`
*
* Heavily influenced by: http://pages.cs.wisc.edu/~remzi/OSTEP/threads-cv.pdf
* Poly/ML Thread documentation here: http://www.polyml.org/documentation/Reference/Threads.html
* Poly/ML Thread implementation here: https://github.com/polyml/polyml/blob/master/basis/Thread.sml
*)
val done = ref false;
val m = Thread.Mutex.mutex();
@binzume
binzume / dock2local.sh
Last active June 21, 2019 09:45
DockerfileあるのにVMに直接環境作りたくなったときに使うヤツ
#!/bin/sh
# Apply a Dockerfile to local environment.
# usage: sudo ./dock2local.sh [PATH_TO_Dockerfile]
DOCKERFILE=${1:-Dockerfile}
DOCKERFILE=`dirname $DOCKERFILE`/`basename $DOCKERFILE`
LOCALDIR=$(cd `dirname $DOCKERFILE` && pwd)
D_WORKDIR=`pwd`
D_USER=`whoami`
@yancya
yancya / date_trunc.sql
Last active December 15, 2017 03:00
date_trunc alternative of BigQuery
select timestamp(regexp_replace(string(ts), r'^(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}).*', '\\1')) as date_trunc_second,
timestamp(regexp_replace(string(ts), r'^(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:).*', '\\100')) as date_trunc_minute,
timestamp(regexp_replace(string(ts), r'^(\d{4}-\d{2}-\d{2} \d{2}:).*', '\\100:00')) as date_trunc_hour,
timestamp(regexp_replace(string(ts), r'^(\d{4}-\d{2}-\d{2}).*', '\\1 00:00:00')) as date_trunc_day,
timestamp(regexp_replace(string(ts), r'^(\d{4}-\d{2}).*', '\\1-01 00:00')) as date_trunc_month,
timestamp(regexp_replace(string(ts), r'^(\d{4}).*', '\\1-01-01 00:00')) as date_trunc_year,
timestamp(regexp_replace(string(ts), r'^(\d{3}).*', '\\10-01-01 00:00')) as date_trunc_decade,
timestamp(regexp_replace(string(ts), r'^(\d{2}).*', '\\100-01-01 00:00')) as date_trunc_century,
timestamp(regexp_replace(string(ts), r'^(\d{1}).*', '\\1000-01-01 00:00')) as date_trunc_millennium
from (select cast('2014-08-19 12:41:35.220000' as t
# Multiple inheritance with Modules as an alternative to injected composition
# from Sandi Metz's talk [Nothing is Something](http://confreaks.tv/videos/bathruby2015-nothing-is-something)
# Like Sandi's 'direct' DI method this has behavior outside of the base class
# that gets composed together. However in this gist I compose modules in class
# definitions instead of injecting collaborators.
# Tradeoffs between this and Sandi's version are that in this case the API consumer doesn't
# have to know how to make a RandomEchoHouse (no `house = House.new(formatter: Whatever.new)`),
# but also the API consumer can't make anything not already accounted for either.
@markusklems
markusklems / lambda-dynamo
Last active November 24, 2024 01:48
Short aws lambda sample program that puts an item into dynamodb
// create an IAM Lambda role with access to dynamodb
// Launch Lambda in the same region as your dynamodb region
// (here: us-east-1)
// dynamodb table with hash key = user and range key = datetime
console.log('Loading event');
var AWS = require('aws-sdk');
var dynamodb = new AWS.DynamoDB({apiVersion: '2012-08-10'});
exports.handler = function(event, context) {
@knutwalker
knutwalker / FSM.scala
Last active April 3, 2022 13:51
Simple Encoding of a purely functional Finite State Machine using Scala and scalaz
package example.statemachine
import scalaz.{State, Scalaz}, Scalaz._
object FSM {
def apply[I, S](f: PartialFunction[(I, S), S]): FSM[I, S] =
new FSM((i, s) => f.applyOrElse((i, s), (_: (I, S)) => s))
private def states[S, O](xs: List[State[S, O]]): State[S, List[O]] =
xs.sequence[({type λ[α]=State[S, α]})#λ, O]
@maiha
maiha / gist:9f305fb909fd357eb467
Last active November 9, 2016 11:30
akka: killとstopとPoisonPillの違い
stop: 現在処理中のメッセージを完了させる。それ以外のMailboxに溜まっているメッセージは処理しない
PoisonPill: メッセージの追加なので、投げた時点でたまっているメッセージが処理される (キュー消化+stop)
kill: ActorKilledExceptionが速攻出る(処理中の動作を破棄?)。その後はsupervisorのstrategyに依存(default:stop)。Mailboxはそのまま残る(restartしたactorが継続)
http://stackoverflow.com/questions/13847963/akka-kill-vs-stop-vs-poison-pill
@gakuzzzz
gakuzzzz / 1_Implicits.scala
Last active April 18, 2021 02:29
Play2 Controller Utilities
package controllers.util
import play.api.mvc.{Result, Controller}
import play.api.data.Form
import scala.util.Either.RightProjection
object Implicits {
implicit def formToEither[A](form: Form[A]): Either[Form[A], A] = form.fold(Left.apply, Right.apply)
@exoego
exoego / 転職先に訊きたいチェックリスト.md
Last active May 25, 2024 15:30
転職活動してて訊きたいことのメモ

制度

  • 有休…
  • 病休…
  • 育休…
  • 年収(月給、賞与など)…
  • 残業代…
  • 早朝/深夜手当…
  • 休出手当…
  • 住宅補助…
@jozefg
jozefg / closconv.lhs
Last active April 2, 2025 03:08
Tutorial on Closure Conversion and Lambda Lifting
This is my short-ish tutorial on how to implement closures in
a simple functional language: Foo.
First, some boilerplate.
> {-# LANGUAGE DeriveFunctor, TypeFamilies #-}
> import Control.Applicative
> import Control.Monad.Gen
> import Control.Monad.Writer
> import Data.Functor.Foldable