Skip to content

Instantly share code, notes, and snippets.

View leaysgur's full-sized avatar
🫖

Yuji Sugiura leaysgur

🫖
View GitHub Profile
@leaysgur
leaysgur / verify-slack-request.js
Last active July 30, 2020 07:05
Simple function to verify request w/ Slack Signed Secret for Node.js
import { createHmac } from "crypto";
const secret = process.env.SLACK_SIGNING_SECRET;
export isValidRequestFromSlack = ({ headers, body }) => {
return hasValidTimestamp({ headers }) && hasValidSignature({ headers, body });
};
const hasValidSignature = ({ headers, body }) => {
if (!secret) return false;
@leaysgur
leaysgur / example.svelte
Last active July 19, 2020 03:23
Use IntersectionObserver as Svelte action.
<script>
import { onIntersect } from "./svelte-action-intersection-observer.js";
</script>
<h2 class="animation-name" use:onIntersect={{ className: "-animated", once: true }}>
Animated heading!
</h2>
@leaysgur
leaysgur / index.svelte
Last active June 2, 2020 04:25
React useState() utility in Svelte 3.
<script>
import { useState } from "./use-state";
const [count, setCount] = useState(0);
</script>
<p>{$count}</p>
<button on:click={() => setCount(n => n + 1)}>+1</button>
<button on:click={() => setCount(10)}>10</button>
@leaysgur
leaysgur / memo.js
Last active May 27, 2020 13:19
hmac auth
// 1. define secretKey previously(only A: your server and B: our server knows it)
const SECRET_KEY = "XXX";
// 2. client prepare credential at A
const timestamp = Date.now();
const credential = require("crypto")
.createHmac("sha256", SECRET_KEY)
.update(timestamp)
.digest("base64");
@leaysgur
leaysgur / manifest.json
Last active February 28, 2022 23:40
Chrome extension to remove **annoying** unavailable tweets for TweetDeck.
{
"name": "Remove unavailable tweets for TweetDeck",
"version": "1.1",
"description": "Do not show me, please.",
"manifest_version": 2,
"content_scripts": [
{
"matches": ["https://tweetdeck.twitter.com/*"],
"js": ["script.js"]
}
@leaysgur
leaysgur / .eslintrc.js
Last active May 2, 2022 06:32
Preact x TypeScript x Babel x webpack x ESLint
module.exports = {
env: {
es6: true,
browser: true,
jasmine: true,
node: true
},
settings: {
react: {
pragma: "h",
@leaysgur
leaysgur / history.js
Created April 10, 2020 05:37
Minimul data structure for undo/redo operation.
class History {
constructor(initialValue = null) {
this._past = [];
this._present = initialValue;
this._future = [];
}
get value() {
return this._present;
}
@leaysgur
leaysgur / notworking.js
Created February 16, 2020 08:35
[NOT WORKING] Discord.js voice echo bot
const { Readable } = require("stream");
const Discord = require("discord.js");
const client = new Discord.Client();
const TOKEN = "YOUR_TOKEN_HERE";
const SILENCE_FRAME = Buffer.from([0xF8, 0xFF, 0xFE]);
class Silence extends Readable {
_read() {
this.push(SILENCE_FRAME);
@leaysgur
leaysgur / webrtc-p2p-dc.js
Created January 27, 2020 06:44
Use playwright for WebRTC P2P DataChannel testing
const { firefox, webkit, chromium } = require("playwright");
(async () => {
// webkit x webkit can not be tested. no host-candidates appears by restriction
const b1 = await setup(webkit);
const b2 = await setup(firefox);
const offer = await b1.page.evaluate(async () => {
const pc = window.pc = new RTCPeerConnection();
const dc = window.dc = pc.createDataChannel("x");
@leaysgur
leaysgur / util.js
Created December 12, 2019 01:10
Dump of chrome://webrtc-internals by Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.79 Safari/537.36"
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// #import {assertInstanceof} from './assert.m.js';
// #import {dispatchSimpleEvent} from './cr.m.js';
// // Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.