Skip to content

Instantly share code, notes, and snippets.

@cwchentw
cwchentw / profile.ps1
Last active November 9, 2020 11:45
Yet Another PowerShell Profile
# Yet Another PowerShell profile
#
# Copyright (c) 2020. Michael Chen. Licensed under Apache 2.0.
# Tested against PowerShell 7.
# Show the version of PowerShell.
function Version {
Get-Host | Select-Object Version
}
@cwchentw
cwchentw / fetchStockData.py
Created October 14, 2018 23:52
Yahoo Finance Crawler as a Python script
#!/usr/bin/env python
##############################################################################
# fetchStockData.py - a friendly Yahoo Finance crawler. #
# #
# Requirements #
# #
# - Python 3 #
# - Selenium package for Python #
# - The web driver for Chrome #
@cwchentw
cwchentw / fibonacci.c
Created October 19, 2020 03:31
Fibonacci Number in Clang Block
/* copyright (c) 2020 Michael chen.
Licensed under Apache 2.0 */
#include <stdio.h>
#include <Block.h>
typedef unsigned (^uint_block)(void);
typedef uint_block (^uint_closure)(void);
int main(void)
@cwchentw
cwchentw / swiftVersion.swift
Created October 17, 2020 07:44
Check the Version of System Swift in a Swift Program
/* Copyright (c) 2020 Michael Chen.
Licensed under Apache 2.0 */
func swiftVersionMajor () -> UInt {
#if swift(>=5.0)
return 5
#elseif swift(>=4.0)
return 4
#elseif swift(>=3.0)
return 3
@cwchentw
cwchentw / utility.js
Last active October 11, 2020 08:14
Utility Function for Cross-browser Scripting in Vanilla JavaScript
/* Utility to add an event listener for an element. */
function addEvent (event, elem, func) {
if (elem.addEventListener)
elem.addEventListener(event, func, false);
else if (elem.attachEvent)
elem.attachEvent('on'+event, func);
else
elem[event] = func;
}
@cwchentw
cwchentw / ajax.js
Last active October 11, 2020 05:44
Boilerplate for Cross-browser Scripting in Vanilla JavaScript
function ie9 () {
let div = document.createElement("div");
div.innerHTML = "<!--[if lte IE 9]><i></i><![endif]-->";
return div.getElementsByTagName("i").length == 1;
}
function getXHR() {
if (ie9()) {
try {
return new ActiveXObject('Microsoft.XMLHTTP');
@cwchentw
cwchentw / install-dependencies-opensuse
Last active September 24, 2020 10:34
Install the dependencies of GNUstep on openSUSE Leap 15.2
#!/bin/sh
# Install the dependencies of GNUstep on openSUSE.
# Copyright (c) 2020 Michael Chen. Licensed under MIT.
# Note:
#
# Currently, GNUstep GUI fails to compile due to ImageMagick issue.
# Subsequently, GUNstep Backend fails to compile as well.
@cwchentw
cwchentw / bstree.lua
Last active September 12, 2020 12:51
Binary Search Tree in Pure Lua (Apache 2.0)
local Node = {}
Node.__index = Node
function Node:new(data)
self = {}
self._data = data
self.left = nil
self.right = nil
@cwchentw
cwchentw / kedict2sqlite.groovy
Last active August 24, 2020 14:27
KEDICT to SQLite
/* kedict2sqlite.groovy - Load kedict into a SQLite database.
Copyright (c) 2020 Michael Chen.
Licensed under MIT.
Copy kedict.yml to the same path of the script.
Then, run it with the following command:
$ groovy -cp path/to/sqlite-jdbc-x.y.z.jar kedict2sqlite.groovy
@cwchentw
cwchentw / build.bat
Last active April 27, 2020 22:45
Wrapper and utilities for Clojure on Windows
@echo off
rem Build script for Clojure on Windows
rem Copyright (c) 2020 Michael Chen
rem Licensed under MIT
rem Place the script at the scripts/ subdirectory of of a local Clojure repo.
rem *TODO* Use system Maven to compile Clojure
set script_path=%~dp0