Skip to content

Instantly share code, notes, and snippets.

@Noeyfan
Noeyfan / RingBuffer.cc
Created January 19, 2023 22:03
Lock Free Ring Buffer
#include <iostream>
#include <vector>
class RingBuffer {
public:
RingBuffer(int size) :
// allocate 1 more element so its easier
// to detect if a buffer is full
buffer_(size+1),
head_(0),
@Noeyfan
Noeyfan / LFQueue.cc
Created January 18, 2023 04:31
Lock Free Queue
#include <cstdlib>
#include <cstdio>
#include <pthread.h>
#include <unistd.h>
bool running = true;
int ITERATION = 10000;
struct Node {
int value;
@Noeyfan
Noeyfan / redfin_fetcher.py
Last active September 13, 2022 05:41
ClickHouse and Metabase Setup
import json
import os
import time
import requests
import datetime
import pathlib
# run fetch
dir = str(pathlib.Path(__file__).parent.resolve())
with open(dir + '/urls.json') as rf:
curl 'https://www.epicpass.com/api/LiftAccessApi/SubmitPassReservation' \
-H 'authority: www.epicpass.com' \
-H 'accept: application/json, text/javascript, */*; q=0.01' \
-H 'x-queueit-ajaxpageurl: https%3A%2F%2Fwww.epicpass.com%2Fplan-your-trip%2Flift-access%2Freservations.aspx' \
-H 'x-requested-with: XMLHttpRequest' \
-H '__requestverificationtoken: EMzGtuKsgkt6x29YviEYIJtzn2j_VetKM1BZQ03uJ1uu0nGBW1kY3jaWwFzMvFUJ-LFLjd8oJF4Pz5W98sNOYSeNvlo1:7iOZ0ZFGGfI4q80ZB6yCcMlTXdiScqwf3YTZLLmfQzuPOnYscxMM98N0CbIWxs8iQl9EhhO5odOAGuWWl9o4RruUxq1aCJi7kN4CgUhCITxU7E2f0' \
-H 'user-agent: Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Mobile Safari/537.36' \
-H 'content-type: application/json; charset=UTF-8' \
-H 'origin: https://www.epicpass.com' \
-H 'sec-fetch-site: same-origin' \
module Tree where
import Data.Map
import Debug.Trace
data Ion = IonSymbol String | IonStruct (Map String Ion) | IonString String | IonList [Ion] deriving Show
data Tree a = Node String (Map String (Tree a)) (Maybe (DerivedAttribute Ion)) deriving Show
type DerivedAttribute a = Map String a
-- TODO
-- make derived attribute a new type and add other attribute ctors
public class replace {
public static void main(String[] args)
{
String foo = "{foo}";
System.out.println(foo.replaceAll("\\{foo\\}", "\\\"bar\\\"")); // => \"bar\"
System.out.println(foo.replace("{foo}", "\\\"bar\\\"")); // => \\\"bar\\\"
}
}
import mysql from 'mysql';
import user from './user';
import post from './post';
class db {
constructor() {
// init db
this.init();
// init connect pool
void dfs(map<int, vector<int>>& res,
vector<pair<int, int>>& cur,
vector<pair<int, vector<pair<int, int>>>>& result,
int profit,
int start) {
auto itr = res.lower_bound(start);
if (itr == res.end()) {
result.emplace_back(profit, cur);
}
import java.util.Collections;
import java.util.List;
import java.util.ArrayList;
import java.util.HashSet;
public class DependencyGraph
{
static int MAX_WR_ID = 1000,
MAX_CE_ID = 1000;
@Noeyfan
Noeyfan / radix_sort.cc
Last active April 17, 2018 06:15
radix_sort.cc
#include <vector>
#include <string>
using namespace std;
// assume all string have same length
void radixSort(vector<string>& a, int W) {
int R = 256;
int N = a.size();
vector<string> aux(N);
for (int j = W-1; j >= 0; j--) {