Skip to content

Instantly share code, notes, and snippets.

@ferryzhou
ferryzhou / opencv_copy_patch.c
Last active April 9, 2017 20:43
opencv extract and copy patch from a Mat or image
// nY(dst_r_from + (0:rows-1), dst_c_from + (0:cols-1), :) = YY(src_r_from + (0:rows-1), src_c_from + (0:cols-1), :);
void copy_patch(Mat& nY, const Mat& YY, int dst_r_from, int dst_c_from, int src_r_from, int src_c_from, int rows, int cols) {
int row_bytes = cols * YY.channels() * YY.elemSize1();
const uchar* pYY = (const uchar*)YY.data + YY.step[0] * src_r_from + YY.step[1] * src_c_from;
uchar* pnY = (uchar*)nY.data + nY.step[0] * dst_r_from + nY.step[1] * dst_c_from;
for (int i = 0; i < rows; i++, pnY += nY.step[0], pYY += YY.step[0]) {
memcpy(pnY, pYY, row_bytes);
}
}
@ferryzhou
ferryzhou / init_with_hash.rb
Created August 14, 2014 21:30
Ruby Class Initialize with Hash Arguments
def initialize(args = {})
defaults = {
:file_list_cache_dir => 'cache/filelists/',
:img_root => 'cache/img/',
:sensor_res_img_root => 'cache/srimg/'
}
defaults.merge(args).each do |attr, val|
instance_variable_set("@#{attr}", val) if defaults.has_key?(attr) && (not val.nil?)
end if args
setup
@ferryzhou
ferryzhou / github_repos_bigquery.sql
Last active August 29, 2015 14:08
get github repo details from bigquery
select repository_url, repository_language, repository_created_at, repository_description, MAX(repository_watchers) as watches
from [githubarchive:github.timeline]
where repository_watchers > 20
group each by repository_url, repository_language, repository_created_at, repository_description
order by watches desc
@ferryzhou
ferryzhou / create_mappings.sh
Last active August 29, 2015 14:08
get github watch events in a month
curl -XPUT 'http://localhost:9200/_template/github-watch' -d @github-watch-mappings.json
@ferryzhou
ferryzhou / go.vimrc
Created November 8, 2015 15:56
vimrc for go
execute pathogen#infect()
syntax on
filetype plugin indent on
set number
set backspace=2
set t_Co=256
set background=dark
colorscheme PaperColor
@ferryzhou
ferryzhou / 0_reuse_code.js
Created November 28, 2015 16:09
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@ferryzhou
ferryzhou / google_api_go_client.go
Created November 30, 2015 04:15
google api go client initialize
// https://github.com/google/google-api-go-client
import (
"golang.org/x/net/context"
"golang.org/x/oauth2/google"
"google.golang.org/api/compute/v1"
)
func main() {
// Use oauth2.NoContext if there isn't a good context to pass in.
@ferryzhou
ferryzhou / show_mbot_bluetooth.js
Created May 15, 2016 17:05
connect to mbot through bluetooth from nodejs
// Based on tutorial here:
// https://itp.nyu.edu/physcomp/labs/labs-serial-communication/lab-serial-communication-with-node-js/
// Examples:
// node test.js /dev/tty.Makeblock-ELETSPP
var serialport = require('serialport');
var SerialPort = serialport.SerialPort;
var portName = process.argv[2];
// turn led green
@ferryzhou
ferryzhou / README.md
Last active July 11, 2022 15:23
Use riot and ajax to show data from a restful api using postgrest. also use bootswatch for theme.
  1. start restful api server

postgrest "host=localhost dbname=tnews" -a $(whoami) --schema public

  1. serve the html

python -m SimpleHTTPServer 8080

import numpy as np
# A linear function.
# Ax = y
# Given A and y, solve x.
# Standard L2 loss function with l2 regularization.
N = 1000
M = 2
A = np.random.random((N, M))