Skip to content

Instantly share code, notes, and snippets.

View giabao's full-sized avatar

Bùi Việt Thành giabao

View GitHub Profile
@redox
redox / base.html.haml
Last active May 16, 2020 13:13
Algolia extends HipChat to customer support
#chat-box.ubuntu.hidden-xs
.closed
.pull-right
= link_to_function content_tag(:i, nil, class: 'glyphicon glyphicon-chevron-up').html_safe, 'chat.show()'
.m-l-small
= link_to_function 'Chat with us', 'chat.show()'
.opened{style: 'display: none'}
.header
.pull-right
= link_to_function content_tag(:i, nil, class: 'glyphicon glyphicon-plus-sign').html_safe, 'chat.maximize()', class: 'maximize', style: 'display: none'
The Union Type Quiz
===================
0. Please give your typing approach an intuitive name:
Consistent, Unified Subsumption
1. Please describe the guiding principle of your typing approach in one sentence:
class Cell[T](value: T) {
var other: T = value
}
object Test {
def g[T, U](x: T, y: U) = if (util.Random.nextBoolean) x else y
def f1 = g(1f, "abc")
def f2 = g(1: Byte, "abc")
def f3 = g(f1, f2)
/*** Inferred return types:
@alternegro
alternegro / gist:4568362
Created January 18, 2013 20:43
play scala soap client plus json transformation
def interday(symbol:String, range:String) = Action {request =>
Async {
WS.url("http://api.sproutwerks.com/api/TimeSeries/TimeSeries.svc").withHeaders(CONTENT_TYPE -> "application/soap+xml").post(ChartRequests.interdayRequest(symbol, range)).map { response =>
Ok(timeSeriesToJson(range.toUpperCase, response.xml, noFilter, timeLabeler(range))).as(JSON)
}
}
}
def intraday(symbol:String) = Action {request =>
Async {
@naholyr
naholyr / _service.md
Created December 13, 2012 09:39
Sample /etc/init.d script

Sample service script for debianoids

Look at LSB init scripts for more information.

Usage

Copy to /etc/init.d:

# replace "$YOUR_SERVICE_NAME" with your service's name (whenever it's not enough obvious)
@ushkinaz
ushkinaz / cygwin-mirror-speed.py
Last active February 22, 2025 23:45
Tests HTTP mirrors of Cygwin by measuring download times.
#!/usr/bin/env python3
"""
Script to test HTTP mirrors of Cygwin by measuring download times.
Originally written in 2011, modernized in 2025.
"""
from math import floor
from urllib.request import urlopen
import argparse
import sys
@viktorklang
viktorklang / ScalaEnum.scala
Created June 30, 2011 23:12
DIY Scala Enums (with optional exhaustiveness checking)
trait Enum { //DIY enum type
import java.util.concurrent.atomic.AtomicReference //Concurrency paranoia
type EnumVal <: Value //This is a type that needs to be found in the implementing class
private val _values = new AtomicReference(Vector[EnumVal]()) //Stores our enum values
//Adds an EnumVal to our storage, uses CCAS to make sure it's thread safe, returns the ordinal
private final def addEnumVal(newVal: EnumVal): Int = { import _values.{get, compareAndSet => CAS}
val oldVec = get
@wfaler
wfaler / scalap_extracted.scala
Created April 10, 2011 18:24
Scalap signature reading extracted into what will be a util class for Scala 2.9 reflection compatibility.
package com.recursivity.commons.bean.scalap
import scala.tools.scalap.scalax.rules.scalasig._
import tools.scalap._
import scalax.rules.scalasig.ClassFileParser.{ConstValueIndex, Annotation}
import reflect.generic.ByteCodecs
import java.io.{StringWriter, ByteArrayOutputStream, PrintStream}
@jorgeortiz85
jorgeortiz85 / PrivateMethodCaller.scala
Created April 7, 2011 15:41
Calling private methods in Scala
// Usage:
// p(instance)('privateMethod)(arg1, arg2, arg3)
class PrivateMethodCaller(x: AnyRef, methodName: String) {
def apply(_args: Any*): Any = {
val args = _args.map(_.asInstanceOf[AnyRef])
def _parents: Stream[Class[_]] = Stream(x.getClass) #::: _parents.map(_.getSuperclass)
val parents = _parents.takeWhile(_ != null).toList
val methods = parents.flatMap(_.getDeclaredMethods)
val method = methods.find(_.getName == methodName).getOrElse(throw new IllegalArgumentException("Method " + methodName + " not found"))
@rbranson
rbranson / crossdomain.conf
Created February 3, 2011 21:13
nginx Flash XML policy server
# Add this to your nginx.conf under http { }
server {
listen 843;
server_name localhost;
location / {
rewrite ^(.*)$ /crossdomain.xml;
}