Skip to content

Instantly share code, notes, and snippets.

View jiachen247's full-sized avatar

jiachen :-) jiachen247

  • fb
  • Singapore
  • 21:02 (UTC +08:00)
View GitHub Profile
# https://leetcode.com/problems/search-insert-position/
class Solution(object):
def searchInsert(self, nums, target):
"""
:type nums: List[int]
:type target: int
:rtype: int
"""
l = 0
"""
Clean historical bitcoin price data
- from min to 12 hours
"""
source_fn = 'bitstampUSD_1-min_data_2012-01-01_to_2021-03-31.csv'
dest_fn = 'bitstampUSD_12-hours_data_2012-01-01_to_2021-03-31.csv'
# source = open("bitstampUSD_1-min_data_2012-01-01_to_2021-03-31.csv", "r")
# dest = open("bitstampUSD_12-hours_data_2012-01-01_to_2021-03-31.csv", "w+")
def twoSum(nums, target):
seen = {}
for i in range(len(nums)): # O(N)
if (target - nums[i]) in seen: # O(1)
prev = seen[target - nums[i]]
return [prev, i]
else:
seen[nums[i]] = i #O(1)
print(twoSum([2, 13, 16, 8], 10))
@jiachen247
jiachen247 / mergeSort.py
Created March 5, 2022 10:18
Merge Sort Example
def mergeSort(arr):
def combine(L, R):
i = j = k = 0
while i < len(L) and j < len(R):
if L[i] < R[j]:
arr[k] = L[i]
i += 1
else:
arr[k] = R[j]
// $ node index.js celcius fahrenheit 1 2 3
const CELCIUS = "celcius";
const FAHRENHEIT = "fahrenheit";
const source = process.argv[2];
const dest = process.argv[3];
process.argv // ['node', 'index.js', 'celcius', 'fahrenheit', '1', '2', '3']
.slice(4) // ['1', '2', '3']
.map(s => parseInt(s, 10)) // [1, 2, 3]
.map(convert) // [33.8, 35.6, 37.4]
#include <iostream>
#include <vector>
#include <string>
#include <fstream>
#include <ctype.h>
using namespace std;
// === LEXER === //
@jiachen247
jiachen247 / nix-setup.MD
Created April 23, 2021 13:51
LLVM Sauce Nix Setup

LLVM Sauce Nix Setup

For Nix we require some extra packages. Use this shell.nix, it gets you everything in one shot:

with import <nixpkgs> {};

pkgs.stdenv.mkDerivation rec {
  name = "yarn";
  buildInputs = with pkgs; [
 xorg.libX11
@jiachen247
jiachen247 / SETUP.MD
Last active April 23, 2021 13:21
LLVM Sauce VM Setup Guide

🍊 LLVM Sauce VM Setup Guide

Note: Alternatively, you can spin up a AWS EC22 t2.micro instance and skip steps 1 and 2!

Step 1: Download Ubuntu ISO

  • Download Ubuntu 20.04.2.0 LTS from https://ubuntu.com/download/desktop

Step 2: Create a VM

  • Using VirtualBox or another virtualization tool, spin up a VM using the Ubuntu ISO just downloaded from step 1
  • Provision at a hard disk with at least 40 GB

// Source Program

const x = 1;
{
    const x = 2;
    if (x * 2 === 4) {
        display("Hello world!");
    } else {
         display("boo");
    }
def count_water(walls):
n = len(walls)
stack = list() # use a list as a stack
stack.append((walls[0], 0)) # base case
# go over the list of walls once
for i in range(1, n):
current_wall_height = walls[i]
prev_wall_height = stack[-1][0]