Skip to content

Instantly share code, notes, and snippets.

@ericxyan
ericxyan / Python notes.py
Created November 5, 2015 21:25
My study notes
# Python 2.7
# 1. Iterator
def f(n):
return [x**4 for x in range(n)]
def f2(n):
for x in range(n):
yield x**3
# Check if is a prime
def isPrime(n):
import {Hero} from './hero';
import {HEROES} from './mock-heroes';
import {Injectable} from 'angular2/core';
@Injectable()
export class HeroService {
getHeroes() {
return Promise.resolve(HEROES);
}
// See the "Take it slow" appendix
getHeroesSlowly() {
@ericxyan
ericxyan / http-stream-file.hs
Created March 14, 2016 18:34 — forked from singpolyma/http-stream-file.hs
Stream a file as it is created (such as a video)
module Main (main) where
import Control.Monad (forever, when)
import System.Environment (getArgs)
import System.IO (withBinaryFile, hIsEOF, IOMode(ReadMode), hSetBuffering, BufferMode(BlockBuffering))
import Control.Concurrent (threadDelay)
import Blaze.ByteString.Builder.ByteString (fromByteString)
import Data.ByteString (ByteString)
import Data.ByteString as BS
import Data.Text as T
@ericxyan
ericxyan / myNetlify.js
Created March 16, 2016 00:44
Customized Netlify authentication.js
(function(window, undefined) {
var SITE_ID = null;
var NETLIFY_API = "https://api.netlify.com";
var NetlifyError = function(err) {
this.err = err;
};
NetlifyError.prototype.toString = function() {
return this.err.message;
};
var authWindow, base, providers;
@ericxyan
ericxyan / bgr2rgb.py
Last active March 28, 2016 18:30
Opencv read image as BGR, a
import cv2
import numpy as np
import matplotlib.pyplot as plt
# show diff
# Approach 0
img = cv2.imread('messi4.jpg')
b,g,r = cv2.split(img)
img2 = cv2.merge([r,g,b])
plt.subplot(121);plt.imshow(img) # expects distorted color
plt.subplot(122);plt.imshow(img2) # expect true color
import cv2
import numpy as np
from matplotlib import pyplot as plt
# show gray image
plt.imshow(img, cmap=plt.get_cmap('gray'))
import httplib2 as http
import json
try:
from urlparse import urlparse
except ImportError:
from urllib.parse import urlparse
headers = {
'Accept': 'application/json',

My Javascript study notes.

My Python study notes.

My Java study notes.