Skip to content

Instantly share code, notes, and snippets.

View LesleyLai's full-sized avatar

Lesley Lai LesleyLai

View GitHub Profile
@LesleyLai
LesleyLai / README.md
Created March 31, 2024 13:52
Modified version of the Obsidian Cornell note template

Modified Version of the Cornell Note Template

Adapted from this gist, as the original one seems to have some formatting problems. All credits go to the original creator.

@LesleyLai
LesleyLai / locate_asset_path.cpp
Created November 11, 2022 09:19
Little C++ utility to searching upward until finding a "assets" subdirectory. Useful during development when I don't want to copy the assets to build directory every time.
auto locate_asset_path(const std::filesystem::path& current_path)
-> std::optional<std::filesystem::path>
{
namespace fs = std::filesystem;
std::optional<fs::path> result = std::nullopt;
for (auto path = current_path; path != current_path.root_path();
path = path.parent_path()) {
const auto assets_path = path / "assets";
if (exists(assets_path) && is_directory(assets_path)) {
@LesleyLai
LesleyLai / curry.hpp
Last active February 4, 2022 04:16
C++ currying implementation by Ben Deane
template <typename Callable, typename... Params>
auto curry(Callable f, Params... ps)
{
if constexpr (requires { f(ps...); }) {
return f(ps...);
} else {
return [f, ps...] (auto... qs)
{
return curry(f, ps..., qs...);
};
@LesleyLai
LesleyLai / blogs.opml
Last active June 24, 2024 18:46
This gist contains blogs I follow as of 2024-02-11. You can import the blog.opml file to your RSS software, or you can han pick the blogs you want to follow manually.
<?xml version="1.0" encoding="UTF-8"?>
<opml version="1.0">
<head>
<title>Feeds of Lesley Lai from Inoreader [https://www.inoreader.com]</title>
</head>
<body>
<outline text="Arts" title="Arts">
<outline text="Sarah's&#10;Scribbles" title="Sarah's&#10;Scribbles" type="rss" xmlUrl="https://sarahcandersen.com/rss" htmlUrl="http://sarahcandersen.com/"/>
</outline>
<outline text="Tech Blog" title="Tech Blog">
@LesleyLai
LesleyLai / function_deduce_signature.cpp
Last active March 30, 2020 18:09
Given an invocable object, discover its return type and the function type
#include <type_traits>
namespace detail {
template <typename Func>
struct function_trait;
#define BEYOND_NOARG
#define BEYOND_FUNCTION_TRAIT(CV_OPT, NOEXCEPT_OPT) \
@LesleyLai
LesleyLai / monte-carlo-pi-estimator.elm
Last active September 3, 2020 17:53
A live-coded Monte Carlo Pi Estimator in the club meeting of the CU Computer Graphics Group. Copy it to https://elm-lang.org/try if you want to try to run it.
module Main exposing (..)
import Browser
import Html exposing (Html)
import Svg exposing (..)
import Svg.Attributes exposing (..)
import Svg.Lazy
import Task
import Time
import Random
@LesleyLai
LesleyLai / and_then.hpp
Last active October 26, 2018 18:00
Exceptional Monad in C++ with std::optional
#ifndef AND_THEN_HPP
#define AND_THEN_HPP
#include <optional>
#include <functional>
#include <type_traits>
template<typename T1,
typename Func,
typename Input_Type = typename T1::value_type,
@LesleyLai
LesleyLai / benchmark.hpp
Last active June 29, 2017 00:05
Benchmark for functions in C++
#ifndef BENCHMARK_HPP
#define BENCHMARK_HPP
/*!
* \file benchmark.hpp
*
* Benchmark for functions in C++. Use it only in release mode.
*/
#include <iostream>
#include <functional>
@LesleyLai
LesleyLai / recompile-on-save.el
Last active September 9, 2022 22:28
Recompile the emacs lisp file on save if the byte-compiled file exist
(defun recompile-elc-on-save ()
"If you're saving an elisp file, likely the .elc is no longer valid."
(make-local-variable 'after-save-hook)
(add-hook 'after-save-hook
(lambda ()
(if (file-exists-p (byte-compile-dest-file buffer-file-name))
(byte-compile-file buffer-file-name)))))
(add-hook 'emacs-lisp-mode-hook 'recompile-elc-on-save
)