Skip to content

Instantly share code, notes, and snippets.

@bchazalet
bchazalet / README.md
Last active August 29, 2015 14:25
Quick and dirty CORS proxy (serving local files and remote API from the same origin)

This is a quick and dirty proxy to be used locally in order to avoid all the pain of CORS during development (and development only!).

Use case

Typically you'd have:

  • a html page on your hard drive, say index.html, embedding some javascript that you are currently working on
  • some javascript making XHR calls to a remote API, located on a server locally or elsewhere in your domain, which you do not wish to touch

Your browser will normally blocks the javascript requests because of its same-origin policy.

The problem goes away if you serve both the fixed assets (html, javascript) and the API from the same origin.

@bchazalet
bchazalet / example.scala
Last active August 29, 2015 14:22
Exhaustiveness warning for class with private constructor?
final class Currency private (val code: String) extends AnyVal
object Currency {
val USD: Currency = new Currency("USD")
val EUR: Currency = new Currency("EUR")
def from(code: String) : Option[Currency] = code match {
case USD.code => Option(USD)
case EUR.code => Option(EUR)
/**
* Created by arya on 1/2/15.
*/
/*
scalaVersion := "2.11.4"
libraryDependencies += "com.ning" % "async-http-client" % "1.9.3"
libraryDependencies += "org.scalaz" %% "scalaz-concurrent" % "7.1.0"
@bchazalet
bchazalet / play-centos-init-script.sh
Last active August 29, 2015 14:04
A basic init script (start/status/stop/restart) for a play 2.3.x applications running on a CentOS machine.
#!/bin/bash
# chkconfig: 2345 85 15
# description: starts your play application as a service
############################################################################################
# CentOs init.d start/stop script for your play application packaged with the dist command #
# Tested on CentOS 6.5 #
# You should: #
# 1. Update your project's parameters #
# 2. Copy this file to /etc/init.d/ #
@bchazalet
bchazalet / TrafficSnapshot.java
Last active December 10, 2015 21:18
List all installed application's uids
package com.commonsware.android.tuning.traffic;
import java.util.HashMap;
import android.content.Context;
import android.content.pm.ApplicationInfo;
class TrafficSnapshot {
TrafficRecord device=null;
HashMap<Integer, TrafficRecord> apps = new HashMap<Integer, TrafficRecord>();