This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"context" | |
"fmt" | |
"net/http" | |
"github.com/RussellLuo/appx" | |
"github.com/gin-gonic/gin" | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package werror | |
import ( | |
"fmt" | |
) | |
type Error struct { | |
Err error // the underlying error | |
Str string | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package httpclient | |
import ( | |
"net" | |
"net/http" | |
"time" | |
) | |
// Options includes common Client configurations that need to be tuned. | |
type Options struct { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BaseEncoder: | |
""" | |
An encoder that can encode a decimal number to a string in any base, and vice versa. | |
Example usage: | |
>>> import string | |
>>> chars_62 = string.digits + string.ascii_letters[:52] | |
>>> encoder = BaseEncoder(chars_62) | |
>>> encoder.encode(10765432100123456789) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
""" | |
JPEG encoder based on gstreamer. | |
Many thanks to the following code and docs: | |
- The usage of `appsrc` in Python: https://github.com/tamaggo/gstreamer-examples/blob/master/test_gst_appsrc_testvideo_mp4mux.py | |
- The usage of `appsink` in Python: https://gist.github.com/willpatera/7984486 | |
- The usage of both `appsrc` and `appsink` in C++: https://github.com/dkorobkov/gstreamer-appsrc-appsink-example/blob/master/JpegGstEncoder.cpp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
def time_span_range(begin, end, span): | |
"""Returns a list of time tuples that represents a series of timespans between a time range. | |
:param begin: begin time | |
:param end: end time | |
:param span: span of each timespan | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Method 1 | |
# Pros: really short | |
# Cons: unicode will be escaped | |
echo '{"hello":"你好"}' | python -mjson.tool | |
# Method 2 | |
# Pros: avoid unicode escapes, output string is always UTF-8 encoded | |
# Cons: a little long | |
echo '{"hello":"你好"}' | python -c 'import json, sys; print(json.dumps(json.load(sys.stdin), ensure_ascii=False, indent=2).encode("utf-8"))' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding=utf-8 -*- | |
"""Generate a pythonic interface based on the code generated by `grpcio-tools`. | |
Example: | |
$ python grpc_pi.py --proto-package-name='xx' --pb2-module-name='python.path.xx_pb2' | |
""" | |
import argparse | |
import itertools |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from cStringIO import StringIO | |
from PIL import Image | |
from django.http import HttpResponse | |
ALLOWED_FORMAT = ( | |
'JPEG', | |
'PNG', | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="http://cdn.sockjs.org/sockjs-0.3.min.js"></script> | |
<script> | |
var sock = new SockJS('http://' + window.location.host + '/realtime-news'); | |
sock.onopen = function() { | |
console.log('open'); | |
}; | |
sock.onmessage = function(e) { | |
console.log('message', e.data); | |
}; | |
sock.onclose = function() { |
NewerOlder