Skip to content

Instantly share code, notes, and snippets.

View liulixiang1988's full-sized avatar

Lixiang Liu liulixiang1988

View GitHub Profile
@liulixiang1988
liulixiang1988 / parse_json.go
Created January 30, 2018 03:30 — forked from mjohnsullivan/parse_json.go
Parse JSON objects with arbitrary key names in Go using interfaces and type assertions
// Parsing arbitrary JSON using interfaces in Go
// Demonstrates how to parse JSON with abritrary key names
// See https://blog.golang.org/json-and-go for more info on generic JSON parsing
package main
import (
"encoding/json"
"fmt"
)
@liulixiang1988
liulixiang1988 / WsChatServlet.java
Created August 4, 2016 02:02 — forked from chitan/WsChatServlet.java
How to use WebSocket of Tomcat
//This sample is how to use websocket of Tomcat.
package wsapp;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.util.ArrayList;
import org.apache.catalina.websocket.MessageInbound;
import org.apache.catalina.websocket.StreamInbound;
import org.apache.catalina.websocket.WebSocketServlet;
@liulixiang1988
liulixiang1988 / LambdaExpressionTree.cs
Created May 17, 2016 09:08 — forked from knjname/LambdaExpressionTree.cs
C#'s lambda expression tree.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
namespace LambdaExpressionTree
{
@liulixiang1988
liulixiang1988 / aecho.py
Created November 13, 2015 06:55 — forked from dabeaz/aecho.py
Live-coded examples from my PyCon Brasil 2015 Keynote
# aecho.py
from socket import *
import asyncio
loop = asyncio.get_event_loop()
async def echo_server(address):
sock = socket(AF_INET, SOCK_STREAM)
sock.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)
@liulixiang1988
liulixiang1988 / flask-upload
Last active August 29, 2015 14:27 — forked from dAnjou/flask-upload
Flask upload example
<VirtualHost *>
ServerName example.com
WSGIDaemonProcess www user=max group=max threads=5
WSGIScriptAlias / /home/max/Projekte/flask-upload/flask-upload.wsgi
<Directory /home/max/Projekte/flask-upload>
WSGIProcessGroup www
WSGIApplicationGroup %{GLOBAL}
Order deny,allow
@liulixiang1988
liulixiang1988 / app.py
Created August 14, 2015 03:02
upload multiple files in Flask
import os
# We'll render HTML templates and access data sent by POST
# using the request object from flask. Redirect and url_for
# will be used to redirect the user once the upload is done
# and send_from_directory will help us to send/show on the
# browser the file that the user just uploaded
from flask import Flask, render_template, request, redirect, url_for, send_from_directory
from werkzeug import secure_filename
# Initialize the Flask application
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>items</key>
<array>
<dict>
<key>assets</key>
<array>
<dict>
public HttpResponseMessage Post(string version, string environment, string filetype)
{
var path = @"C:\Temp\test.exe";
HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);
var stream = new FileStream(path, FileMode.Open);
result.Content = new StreamContent(stream);
result.Content.Headers.ContentType =
new MediaTypeHeaderValue("application/octet-stream");
return result;
}
@liulixiang1988
liulixiang1988 / CalculateMd5.cs
Created May 12, 2015 02:55
Calculate File's Md5 计算文件的MD5
//It's very simple:
using (var md5 = MD5.Create())
{
using (var stream = File.OpenRead(filename))
{
return md5.ComputeHash(stream);
}
}
//(I believe that actually the MD5 implementation used doesn't need to be disposed, but I'd probably still do so anyway.)