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 / 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 / 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 / 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 / deploy2win
Last active June 18, 2021 07:47
Depoly a MSYS2 Executable to Native Windows Environment
#!/bin/sh
# deploy2win - Deploy a MSYS2 executable to native Windows environment
#
# Copyright (c) 2020, Michelle Chen. Licensed under MIT.
target="$1"
# Check whether `$target` is an executable.
@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 / jmdict2sqlite.groovy
Last active May 3, 2021 10:48
JMdict to SQLite
/* jmdict2sqlite.groovy - Load JMdict into a SQLite database.
Copyright (c) 2020 Michael Chen.
Licensed under MIT.
Copy JMdict_e to the same path of the script.
Then, run it with the following command:
$ groovy -cp path/to/sqlite-jdbc-3.30.1.jar -DentityExpansionLimit=1000000 jmdict2sqlite.groovy
@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