Skip to content

Instantly share code, notes, and snippets.

View AoiYamada's full-sized avatar
:octocat:

AoiYamada AoiYamada

:octocat:
View GitHub Profile
@AoiYamada
AoiYamada / routes plan.md
Last active March 16, 2024 18:14
routes plan

API Routes Plan

User

Note: /my/* routes requires cognito user token

GET /users # Return list of users, for admin purpose only

GET /users/:userId/profile # For viewing other's profile

@AoiYamada
AoiYamada / index.html
Created February 20, 2024 19:04
CodePen Home Pure CSS waterfall grid layout
// credit to: https://codepen.io/michellebarker/pen/RwMWYpb
<div class="grid">
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
const DataLoader = require("dataloader");
const users = new Map([
[
1,
{
id: 1,
name: "Tom",
},
],
const DataLoader = require("dataloader");
const users = new Map([
[1, { id: 1, name: "Tom" }],
[2, { id: 2, name: "John" }],
[3, { id: 3, name: "Ann" }],
[4, { id: 4, name: "Peter" }],
[5, { id: 5, name: "May" }],
]);
const DataLoader = require("dataloader");
const stories = new Map([
[1, { id: 1, title: "story 1" }],
[2, { id: 2, title: "story 2" }],
[3, { id: 3, title: "story 3" }],
[4, { id: 4, title: "story 4" }],
[5, { id: 5, title: "story 5" }],
]);
@AoiYamada
AoiYamada / n+1.sql
Last active April 4, 2021 13:02
N + 1 Problems
SELECT * FROM singers LIMIT 5;
SELECT * FROM songs WHERE singer_id = 1;
SELECT * FROM songs WHERE singer_id = 2;
SELECT * FROM songs WHERE singer_id = 3;
SELECT * FROM songs WHERE singer_id = 4;
SELECT * FROM songs WHERE singer_id = 5;
@AoiYamada
AoiYamada / post-receive.sh
Created December 11, 2019 17:07 — forked from benfrain/post-receive.sh
post-receive hook for multiple branches
#!/bin/bash
while read oldrev newrev ref
do
branch=`echo $ref | cut -d/ -f3`
if [ "master" == "$branch" ]; then
git --work-tree=./path/under/root/dir/live-site/ checkout -f $branch
echo 'Changes pushed live.'
fi
@AoiYamada
AoiYamada / .babelrc
Created September 30, 2018 21:36
Babel 6 setting to support IE 9+
// http://imweb.io/topic/59dc5a8b856028aa249e2a58
// https://segmentfault.com/a/1190000006930013
// 總之,IE真的是毒瘤...
{
"presets": [
["es2015",
{
"loose": true
}],
"stage-0"
@AoiYamada
AoiYamada / Counting.js
Last active September 30, 2018 21:19
Extend Array to support swap, combination, permutation... for general counting purpose
class Counting extends Array {
constructor(...items) {
if (items.length > 1) super(...items);
else {
super();
this.push(...items);
}
}
swap(idx1, idx2) {
const length = this.length;
@AoiYamada
AoiYamada / extractContents.js
Last active September 30, 2018 21:17
Remove html tag, css, js of html string to extract the contents
/**
* Remove html tag, css, js of html string to extract the contents
* @param {String} html
* @return {String} contents of the html
*/
function extractContents(html) {
return html
.replace(/(\n|\r|\t)/gm, '') // remove linebreaks
.replace(/<(style|script|link|noscript).*?>.*?<\/(style|script|link|noscript)>/g, '') // remove css, js blocks
.replace(/<!--.*?-->/g, '') // remove comments