Skip to content

Instantly share code, notes, and snippets.

View jacyzon's full-sized avatar

Yizhang Chen jacyzon

View GitHub Profile
@jacyzon
jacyzon / flatten_nested_directory.sh
Created July 30, 2015 13:09
flatten a nested directory
# Using ZSH
mv dir1/*/**/*(.D) dir1
# Using POSIX Tool
find dir1 -type f -exec mv {} dir1 \;
find dir1 -depth -exec rmdir {} \;
p "測試".each_byte.map { |b| b.to_s(16) }.join .scan(/../).map { |x| x.hex.chr }.join
# output: "\xE6\xB8\xAC\xE8\xA9\xA6"
@jacyzon
jacyzon / google_first_url.rb
Created May 8, 2015 07:05
Get first URL in google search result
require 'rubygems'
require 'mechanize'
agent = Mechanize.new
page = agent.get('http://www.google.com/')
q = %w(
google
microsoft
)
@jacyzon
jacyzon / ruby _cert_json
Created January 15, 2015 05:08
convert cert, key into json format
ruby -rjson -e 'puts JSON[Hash[Hash[*ARGV].map { |k,v| [k, File.read(v)] }]]' -- \
cert cert.pem \
key key.pem \
> example.com.json
@jacyzon
jacyzon / build.gradle
Last active August 29, 2015 14:12 — forked from orip/build.gradle
android {
def gitTag = {
def tagMatchOptions
try {
tagMatchOptions = "--match ${tagToBuildFrom}"
} catch (MissingPropertyException) {
tagMatchOptions = ""
}
"git describe --exact HEAD ${tagMatchOptions}".execute().text.trim()
}()
@jacyzon
jacyzon / trailing_whitespace.sh
Created December 9, 2014 03:21
trailing whitespace
for a in $(find . -name "*.java"); do sed -i 's/[ \t]*$//' "$a"; done
@jacyzon
jacyzon / conven.sh
Created December 9, 2014 02:58
convert chinese encoding file to utf8
for a in $(find . -name "*.java"); do enconv -L chinese -x UTF-8 "$a"; done
@jacyzon
jacyzon / RegularEx.cs
Created June 22, 2014 09:56
Regular expression capturing MQTT device ID
using System;
using System.Text;
using System.Text.RegularExpressions;
class RegularEx
{
static void Main(string[] args)
{
string pattern = @"(?<=^mqtt-subscription-).+(?=qos1$)";
Regex regex = new Regex(pattern);
-- mux_reg Circuits -------------------
ENTITY Reg_ckt03 IS
PORT (clk: IN BIT;
x: IN BIT_VECTOR(7 DOWNTO 0);
sel: IN INTEGER RANGE 0 TO 7;
y: OUT BIT);
END ENTITY;
----- code 3:----------------------------
ARCHITECTURE circuits OF Reg_ckt03 IS
BEGIN
@jacyzon
jacyzon / inv.sp
Created April 1, 2014 04:04
Basic Gate Hspice
************************************************************************
* auCdl Netlist:
*
* Library Name: my_lib
* Top Cell Name: inv
* View Name: schematic
* Netlisted on: Mar 25 09:46:00 2014
************************************************************************
.lib "~/cic018.l" TT
*.BIPOLAR