Skip to content

Instantly share code, notes, and snippets.

@cwchentw
cwchentw / set.lua
Last active February 9, 2019 07:17
Math Set in Pure Lua (Apache 2.0)
local Set = {}
package.loaded["Set"] = Set
Set.__index = Set
Set.__eq = function (a, b)
for e in a:iter() do
if not b:contains(e) then
return false
end
@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 / employee.c
Last active November 1, 2023 17:29
Polymorphism with Function Pointer in C.
#include <stdlib.h>
#include <assert.h>
#include "person.h"
#include "employee.h"
#include "iperson.h"
// Private helper function declaration.
static void check_salary(double salary);
static char* _name(void *self);
static void _set_name(void *self, char *name);
@cwchentw
cwchentw / animal.c
Last active May 30, 2022 23:35
Polymorphism with Union in C (Apache 2.0)
#include <assert.h>
#include <stdbool.h>
#include <stdlib.h>
#include <stdio.h>
#include "animal.h"
#include "dog.h"
#include "duck.h"
#include "tiger.h"
struct animal {
@cwchentw
cwchentw / Makefile
Last active April 1, 2023 13:04
Cross-Platform Makefile for Application (Apache 2.0)
# Detect underlying system.
ifeq ($(OS),Windows_NT)
detected_OS := Windows
else
detected_OS := $(shell sh -c 'uname -s 2>/dev/null || echo not')
endif
export detected_OS
# Set default C compiler.
@cwchentw
cwchentw / prog.c
Last active February 9, 2019 07:13
Pass separators to C programs (Apache 2.0)
#include <stddef.h>
#include <stdio.h>
#include <string.h>
#ifdef _WIN32
#define SEP "\r\n"
#else
#define SEP "\n"
#endif
@cwchentw
cwchentw / separator_parse.c
Last active February 9, 2019 07:12
Home-made mini separator interpreter (Apache 2.0)
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char * separator_parse(const char *sep);
int main(int argc, char *argv[])
{
@cwchentw
cwchentw / main.c
Last active September 18, 2023 01:35
Generic Queue by C Macro (Apache 2.0)
#include <assert.h>
#include <stdbool.h>
#include <stdio.h>
#include "queue.h"
queue_declare(int);
int main(void)
{
bool failed = false;
@cwchentw
cwchentw / YahooFinanceCrawler.java
Created October 14, 2018 23:47
Yahoo Finance Crawler as a Java Swing app
/*
YahooFinanceCrawler
Version: 1.0
Copyright: 2018, Michael Chen; Apache 2.0.
System Requirments:
- JDK 8
- Selenium Java package and its dependencies.
- MgntUtils
@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 #