Skip to content

Instantly share code, notes, and snippets.

View brainkim's full-sized avatar
🚲
just keep pedaling

Brian Kim brainkim

🚲
just keep pedaling
View GitHub Profile
@brainkim
brainkim / resolve.js
Created March 17, 2023 02:10
ChatGPT implementation of resolve using node.js pseudocode
// This code was generated with the help of OpenAI's ChatGPT-4.
import * as FS from 'fs/promises';
import * as Path from 'path';
import {fileURLToPath, pathToFileURL} from 'url';
async function resolvePackageImports(basePath, specifier, conditions) {
const pkgJson = JSON.parse(await FS.readFile(fileURLToPath(basePath) + '/package.json'));
const imports = pkgJson.imports;
if (typeof imports === 'object' && !Array.isArray(imports)) {
@brainkim
brainkim / gist:96fc27c8e7a0e6212cee51fc49cf425d
Last active November 21, 2016 12:29
frontend-puzzle.md

Okay you have an array of concentric rectangles: each concentric rectangle has a type:

{
 outer: {
   width,
   height,
 },
 inner: {
   width,
 height,
@brainkim
brainkim / slime-volleyball.elm
Last active August 29, 2015 14:26
Slime Volleyball in Elm - go to elm-lang.org/try, paste this in, and compile!
import Signal
import Time exposing (Time)
import Keyboard
import Window
import Text
import Color
import Graphics.Collage exposing (Shape, circle, rect, collage, filled, move, toForm)
import Graphics.Element exposing (Element, container, show)
-- MODEL
set @now = now();
set @six_months_ago = date_sub(now(), interval 6 month);
set @three_months_ago = date_sub(now(), interval 3 month);
create temporary table if not exists `marketing_contact` (
id int(11) unique,
first_name varchar(100),
email varchar(100),
index `marketing_contact_id` (id)
) as (
@brainkim
brainkim / justice.js
Last active August 29, 2015 14:04
Scrape those hubspot email templates (probably doesn't work anymore?)
function getLink(id) {
var links = $('.zoomer-cover a')
.map(function() { return $(this).attr('href'); })
.filter(function() { return this.indexOf(id) > -1; });
return links[0];
}
function extractRowData(row) {
var id = $(row).data('content-id');
var link = getLink(id);
@brainkim
brainkim / merge_sort.py
Created March 17, 2014 16:54
Purely functional merge sort in python
def merge(chunk1, chunk2):
if len(chunk1) == 0:
return chunk2
elif len(chunk2) == 0:
return chunk1
else:
c1 = chunk1[0]
c2 = chunk2[0]
if c1 < c2:
return [c1] + merge(chunk1[1:], chunk2)
@brainkim
brainkim / sudoku.clj
Created February 19, 2014 18:14
Kinda like Norvig's sudoku thing I guess?
(ns sudoku.core)
(def empty-board (vec (repeat 9 (vec (repeat 9 0)))))
(def four-by-four
[[0 1 3 2]
[2 3 1 0]
[1 0 2 3]
[3 2 0 1]])
(def solved-board
@brainkim
brainkim / boggle.clj
Last active August 29, 2015 13:56
Boggle in Clojure
(ns boggle.core
(:require [clojure.java.io :as io]
[clojure.string :as st]))
(defprotocol ITrie
(next? [this letter])
(insert [this word])
(subtree [this letter])
(terminal? [this]))
@brainkim
brainkim / example.jsx
Created October 21, 2013 22:39
Dream-code for react component and flight component baby.
var LikeButton = React.defineClass(LikeButton, withAnimation); //withAnimation is a mixin
//The LikeButton function is called on the React component prototype.
function LikeButton() {
//initialstate would be a method that is already mixed into the component.
this.initialState({
liked: false
});
this.defaultProps({