Skip to content

Instantly share code, notes, and snippets.

@richbai90
richbai90 / pizza_plot.ipynb
Created August 25, 2024 01:21
jupyter notebook for pizza plot
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@richbai90
richbai90 / Help.md
Created June 21, 2023 20:53
A guide for memory optimization in machine learning

Optimizing Memory in Machine Learning: List vs Numpy Pre-allocation

In many machine learning applications, data handling is done using lists, which are then converted into numpy arrays. This practice can be memory inefficient, especially when dealing with large datasets. Below, I illustrate the problem and provide a solution using numpy pre-allocation.

The Problem

Let's take an example of data pre-processing with a list:

pre_processed = []
@richbai90
richbai90 / appSearch.d.ts
Last active May 26, 2021 23:03
app-search-node typings
/* eslint-disable */
declare module '@elastic/app-search-node' {
export = AppSearchClient;
declare class AppSearchClient {
/**
* Creates a jwt search key that can be used for authentication to enforce a set of required search options.
*
* @param {String} apiKey the API Key used to sign the search key
* @param {String} apiKeyName the unique name for the API Key
* @param {Object} options Object see the <a href="https://swiftype.com/documentation/app-search/authentication#signed">App Search API</a> for supported search options
@richbai90
richbai90 / search.js
Created September 18, 2019 22:05
An example of how to implement a generic search object with a single API
const axios = require("axios");
const Spotify = require("node-spotify-api");
const moment = require("moment");
/**
*
* @param searchType {{'concert' | 'movie' | 'spotify'}}
* @param spotifyCredentials {Object=}
* @param spotifyCredentials.id {string}
* @param spotifyCredentials.secret {string}
@richbai90
richbai90 / PageA.jsx
Last active January 12, 2020 01:30
Next.js + ApolloClient + ApolloLinkState
import Paper from "@material-ui/core/Paper";
import { withStyles } from "@material-ui/core/styles";
import { graphql } from "react-apollo";
import { compose } from 'recompose';
import getTree from './queries/getTree';
import styles from './styles';
const Canvas = ({
classes,
// activeItem,
@richbai90
richbai90 / cookies-js.js
Created December 13, 2017 16:48
Minified Cookies-js for the modern browser
var exports = {};
/*!
* JavaScript Cookie v2.2.0
* https://github.com/js-cookie/js-cookie
*
* Copyright 2006, 2015 Klaus Hartl & Fagner Brack
* Released under the MIT license
*/
!function(e){var n=!1;if("function"==typeof define&&define.amd&&(define(e),n=!0),"object"==typeof exports&&(exports.Cookies=e(),n=!0),!n){var o=window.Cookies,t=window.Cookies=e();t.noConflict=function(){return window.Cookies=o,t}}}(function(){function e(){for(var e=0,n={};e<arguments.length;e++){var o=arguments[e];for(var t in o)n[t]=o[t]}return n}function n(o){function t(n,r,i){var c;if("undefined"!=typeof document){if(arguments.length>1){if("number"==typeof(i=e({path:"/"},t.defaults,i)).expires){var a=new Date;a.setMilliseconds(a.getMilliseconds()+864e5*i.expires),i.expires=a}i["max-age"]=i.expires?0:null,i.expires=i.expires?i.expires.toUTCString():"";try{c=JSON.stringify(r),/^[\{\[]/.test(c)&&(r=c)}catch(e){}r=o.write?o.write(r,n):encodeURIComponent(String(r)).replace(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7