Skip to content

Instantly share code, notes, and snippets.

@AHaliq
AHaliq / ex2.c
Last active October 3, 2019 02:52
CS2106 Lab3 ex2 Haliq
/*************************************
* Lab 3 Exercise 2
* Name: Abdul Haliq
* Student No: A0125431U
* Lab Group: B-08
*************************************/
#include <pthread.h>
#include "rw_lock.h"
@AHaliq
AHaliq / CodeCard.java
Last active October 4, 2019 07:53
Classes to model flashcards
abstract class CodeCard implements FlashCard {
protected String question;
protected String output;
public JavascriptCard(String q, String o) {
question = q;
output = o;
}
abstract render...
package com.core;
public enum Response {
BYE("(?i)^b(ye)?\\s*", (i, s) -> {
Printer.printString("Bye. Hope to see you again soon!");
s.toExit = true;
s.lastError = false;
return true;
}),
RESPONDER_NAME("regex", (commandInput, programState) -> {
@AHaliq
AHaliq / Response.java
Created October 9, 2019 08:36
My dukes responses
package com.core;
import com.core.savedata.SaveFile;
import com.util.datetime.DateTime;
import com.util.datetime.DateTimeParse;
import java.util.stream.IntStream;
import com.util.Printer;
import com.tasks.Deadline;
import com.tasks.DoableTask;
// my motivation to use enum is so you dont need to create new objects everytime a command is executed
// instead you simply call a static method. and to iterate through a list of static methods we use enums.
// So this is a typical enum u encounter all the time
enum MyEnum {
A, B, C;
}
// However enums are capable of having properties and methods!
// if u define a method in an enum all enums will have it
// e.g.
@AHaliq
AHaliq / sketch.js
Last active December 10, 2019 08:44
Coding Train Challenge #125, fourier series implemented in functional style with waves in terms of amplitude, frequency and range
let STAGE_WIDTH = 800;
const STAGE_HEIGHT = 400;
const L_BORDER = 25;
const COLBG = 220;
const COL1 = 100;
const COL2 = 195;
const PIVOTRADI = 10;
const LINEGAP = 5;
let UNITRADI = 50;
let DW;
// NOTE read Responses.java first itll make more sense
public class CreateInputCommand implements ResponseFunc {
private String front = "";
private String back = "";
// handle types??
@Override
public boolean funcCall(String i, State s) {
if (s.state == StateEnum.CREATE_STATE_FRONT) {
front = i;
@AHaliq
AHaliq / comp
Created January 7, 2021 12:20
Compound Stake
rate[x_] := rated[x*365]
rated[x_] :=
If[x < 7, 1.5,
If[x < 30.4167, 3, If[x < 365/2, 5, If[x < 365, 17, 30]]]]
f[ip_, r_, p_, t_, n_] :=
If[t <= 0, ip,
If[t < p, ip + ip*r*t - rate[t],
f[ip + (ip * r * p) - rate[p] - rate[0]*n, r, p, (t - p), n + 1]]]
g[ip_, r_, t_] := ip + ip*r*t - rate[t]
init := 10000
@AHaliq
AHaliq / main.ml
Created March 31, 2021 10:56
export ocaml function to call from js
let global_nctx = ref Kernel.Context.empty
let global_ectx = ref Kernel.Context.empty
let js_run_repl str =
match String.(compare str "quit") with
| 0 -> "bye"
| _ ->
match String.(compare str "reset") with
| 0 ->
global_nctx := Kernel.Context.empty;
@AHaliq
AHaliq / actual.cpp
Created April 30, 2021 12:15
error: too many arguments to function
/******************************************************************************
Online C++ Compiler.
Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include <iostream>
#include <string>