Skip to content

Instantly share code, notes, and snippets.

Avatar
🍂

Yuji Sugiura leader22

🍂
View GitHub Profile
@leader22
leader22 / next-preact.d.ts
Created Sep 1, 2020
Use nextjs Link component w/ Preact + TypeScript
View next-preact.d.ts
import type { VNode, JSX } from "preact";
declare module "react" {
export = React;
export as namespace React;
declare namespace React {
type DetailedReactHTMLElement<
P extends JSX.HTMLAttributes<T>,
T extends HTMLElement
@leader22
leader22 / verify-slack-request.js
Last active Jul 30, 2020
Simple function to verify request w/ Slack Signed Secret for Node.js
View verify-slack-request.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;
@leader22
leader22 / example.svelte
Last active Jul 19, 2020
Use IntersectionObserver as Svelte action.
View example.svelte
<script>
import { onIntersect } from "./svelte-action-intersection-observer.js";
</script>
<h2 class="animation-name" use:onIntersect={{ className: "-animated", once: true }}>
Animated heading!
</h2>
@leader22
leader22 / index.svelte
Last active Jun 2, 2020
React useState() utility in Svelte 3.
View index.svelte
<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>
@leader22
leader22 / memo.js
Last active May 27, 2020
hmac auth
View memo.js
// 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");
@leader22
leader22 / manifest.json
Last active Oct 12, 2020
Chrome extension to remove **annoying** unavailable tweets for TweetDeck.
View manifest.json
{
"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"]
}
@leader22
leader22 / .eslintrc.js
Last active Apr 28, 2020
Preact x TypeScript x Babel x webpack x ESLint
View .eslintrc.js
module.exports = {
env: {
es6: true,
browser: true,
jasmine: true,
node: true
},
settings: {
react: {
pragma: "h",
@leader22
leader22 / history.js
Created Apr 10, 2020
Minimul data structure for undo/redo operation.
View history.js
class History {
constructor(initialValue = null) {
this._past = [];
this._present = initialValue;
this._future = [];
}
get value() {
return this._present;
}
@leader22
leader22 / notworking.js
Created Feb 16, 2020
[NOT WORKING] Discord.js voice echo bot
View notworking.js
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);
@leader22
leader22 / webrtc-p2p-dc.js
Created Jan 27, 2020
Use playwright for WebRTC P2P DataChannel testing
View webrtc-p2p-dc.js
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");
You can’t perform that action at this time.