Skip to content

Instantly share code, notes, and snippets.

View up1's full-sized avatar

Somkiat Puisungnoen up1

View GitHub Profile
@up1
up1 / MyApplication.java
Created August 20, 2013 10:28
Change Local in Android application
public class MyApplication extends Application
{
private Locale locale = null;
@Override
public void onConfigurationChanged(Configuration newConfig)
{
super.onConfigurationChanged(newConfig);
if (locale != null)
{
@up1
up1 / gist:9579437
Created March 16, 2014 06:45
mirrored-packages.conf
{
"name": "My Composer Mirror",
"homepage": "http://localhost:4680",
"repositories": [
{ "type": "vcs", "url": "https://github.com/SynetoNet/monolog" },
{ "type": "composer", "url": "https://packagist.org" }
],
"require": {
@up1
up1 / composer.json
Created March 16, 2014 07:27
Example of composer.json use a local mirror composer
{
"repositories": [
{
"type": "composer",
"url": "http://localhost:4680"
}
{
"packagist": false
}
]
@up1
up1 / after_di.go
Created April 28, 2014 13:31
Demo for Dependency Injection with Golang
package di
import (
"fmt"
)
func AverageScore() float64 {
score := getTotalScore()
member := getAllMember()
return float64(score / member)
@up1
up1 / index.html
Created May 1, 2014 16:20
Demo :: Nginx + Push stream module
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title>WebSocket Example</title>
</head>
<body>
<p>Messages:</p>
<div id="messages" style="width:800px;height:300px;overflow:scroll;"></div>
@up1
up1 / DemoApplication.java
Last active August 29, 2015 14:00
Demo-Dropwizrd
package up1.demo;
import health.TemplateHealthCheck;
import io.dropwizard.Application;
import io.dropwizard.setup.Bootstrap;
import io.dropwizard.setup.Environment;
import resource.DemoResource;
public class DemoApplication extends Application<DemoConfiguration> {
@up1
up1 / my_json.go
Last active October 7, 2015 13:42
GO :: REST API + JSON
package main
import (
"encoding/json"
"fmt"
"io"
"log"
"strings"
)
@up1
up1 / 1.go
Last active August 29, 2015 14:01
Demo :: Go with database
package main
import (
"database/sql"
_ "github.com/go-sql-driver/mysql"
)
func main() {
db, err := sql.Open("mysql", "user1:user1password@/todo")
if err != nil {
@up1
up1 / 1.go
Last active August 29, 2015 14:01
Demo :: Go with html template
package main
import (
"html/template"
"os"
)
func main() {
t, err := template.New("foo").Parse(`{{define "T"}}Hello, {{.}}!{{end}}`)
err = t.ExecuteTemplate(os.Stdout, "T", "Up1")
@up1
up1 / size.go
Last active August 29, 2015 14:01
Go :: coverage
package size
func Size(a int) string {
switch {
case a < 0:
return "negative"
case a == 0:
return "zero"
case a < 10:
return "small"