Skip to content

Instantly share code, notes, and snippets.

View geraldyeo's full-sized avatar
🎯
Focusing

Gerald Yeo geraldyeo

🎯
Focusing
View GitHub Profile
@geraldyeo
geraldyeo / replaceme.js
Created November 29, 2023 03:49
Simple template replacement
function replaceMe(template, data) {
const pattern = /{\s*(\w+?)\s*}/g; // {property}
return template.replace(pattern, (_, token) => data.hasOwnProperty(token) ? data[token] : '');
}
@geraldyeo
geraldyeo / .gitconfig
Created January 10, 2023 01:29
Multiple git configs
[includeIf "gitdir:~/Code/Personal/"]
path = ~/Code/Personal/.gitconfig-personal
[includeIf "gitdir:~/Code/Work/"]
path = ~/Code/Work/.gitconfig-work
@geraldyeo
geraldyeo / .gitconfig
Created October 21, 2021 04:04
git prune tags
# in ~/.gitconfig
[alias]
... ... ... # your existing aliases
pt = !git tag -l | xargs git tag -d && git fetch -t
@geraldyeo
geraldyeo / launch.json
Created September 30, 2021 02:32
vscode debug launch config
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "attach",
"name": "Attach to Nest Framework",
@geraldyeo
geraldyeo / git-tags.sh
Last active August 20, 2021 03:16
Delete a git tag
# list local tags with description
git tag -n
# delete local tag
git tag -d 3.3.1 # Deleted tag '3.3.1' (was 56469e1)
# delete remote tag
git push origin :refs/tags/3.3.1
# list remote tags
@geraldyeo
geraldyeo / deepFreeze.js
Last active August 2, 2021 09:44
Object deep freeze
// https://blog.klipse.tech/javascript/2021/02/26/structural-sharing-in-javascript.html
function deepFreeze(object) {
const propNames = Object.getOwnPropertyNames(object);
// Freeze properties before freezing self
for (const name of propNames) {
const value = object[name];
if (value && typeof value === "object") {
deepFreeze(value);
}
}
@geraldyeo
geraldyeo / Animal.js
Last active June 26, 2020 01:46
Spot the bugs
const Animal = (name, type) => {
this.name = name
this.type = type
this.age = 0
}
Animal.prototype.birthday = function () {
this.age++
}
@geraldyeo
geraldyeo / mac.md
Last active November 18, 2020 05:04
Setting up your mac for the first time

Setting Up Macbook

Applications

  • iTerm2 - If you want to customise your terminal
  • BetterTouchTool - Actually makes your touchbar useful
  • Rambox - Puts all your chat apps and emails into one convenient place
  • IntelliJ - IDE of choice
  • VSCode - If you don't want an IDE but still want to get shit done
  • Sublime Text - Better than Notes
@geraldyeo
geraldyeo / getScrollTop.js
Created June 26, 2018 07:43
cross browser scrolltop
function getBodyScrollTop() {
const el = document.scrollingElement || document.documentElement;
return Math.max(window.pageYOffset, el.scrollTop);
}
@geraldyeo
geraldyeo / flow-checks.md
Last active May 4, 2018 07:34
Flow checks playgrounds