Skip to content

Instantly share code, notes, and snippets.

Avatar

Michelle Chen cwchentw

View GitHub Profile
@cwchentw
cwchentw / profile.ps1
Last active Nov 9, 2020
Yet Another PowerShell Profile
View profile.ps1
# 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 Oct 19, 2020
Fibonacci Number in Clang Block
View fibonacci.c
/* 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 Oct 17, 2020
Check the Version of System Swift in a Swift Program
View swiftVersion.swift
/* 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 Oct 11, 2020
Boilerplate for Cross-browser Scripting in Vanilla JavaScript
View ajax.js
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 Oct 11, 2020
Utility Function for Cross-browser Scripting in Vanilla JavaScript
View utility.js
/* 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 Sep 29, 2020
Depoly a MSYS2 Executable to Native Windows Environment
View deploy2win
#!/bin/sh
# deploy2win - Deploy a MSYS2 executable to native Windows environment
#
# Copyright (c) 2020, Michael Chen. Licensed under MIT.
target="$1"
# Check whether `$target` is an executable.
@cwchentw
cwchentw / install-dependencies-opensuse
Last active Sep 24, 2020
Install the dependencies of GNUstep on openSUSE Leap 15.2
View install-dependencies-opensuse
#!/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.
View jmdict2sqlite.groovy
/* 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
View kedict2sqlite.groovy
/* 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 Apr 27, 2020
Wrapper and utilities for Clojure on Windows
View build.bat
@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