Skip to content

Instantly share code, notes, and snippets.

View shuntksh's full-sized avatar

Shun Takahashi shuntksh

View GitHub Profile
@shuntksh
shuntksh / mov2gif.sh
Created June 30, 2016 16:19
Generate Animated GIF from Mov file on Mac with ffmpeg / imagemagick
brew install imagimagick ffmpeg
ffmpeg -i <INPUT_FILE>.mov -r 10 -f image2pipe -vcodec ppm - | convert -delay 30 -layers Optimize -loop 0 - <OUTPUT_FILE>.gif
@shuntksh
shuntksh / seq_promise.js
Created December 19, 2016 06:01
Promise Sequential Iteration
const urls = ['/task1', '/task2', ];
let promise = Promise.resolve();
tasks.forEach((task) => {
promise = promise.then(() => request.get(task));
});
@shuntksh
shuntksh / file0.js
Last active February 2, 2017 22:45
React.jsのrenderの戻り値の中で.bindで新しい関数を定義してはいけないわけ ref: http://qiita.com/shuntksh/items/fd81ca9aa31ea8f962e2
// 悪い例:render関数内で新しい関数を定義
class MyComponent extends React.Component {
render() {
const { value, handleChange } = this.props;
return <input value={value} onChange={handleChange.bind(this)} />
}
}
@shuntksh
shuntksh / file0.js
Last active March 31, 2017 13:49
WebpackってCSS周りのLoaderがいっぱいあって分かりにくいので整理してみる ref: http://qiita.com/shuntksh/items/bb5cbea40a343e2e791a
{
test: /\.css$/,
loader: "style-loader!css-loader?modules&importLoaders=1&camelCase!postcss-loader",
},
package main
import (
"fmt"
"strings"
"bufio"
"bytes"
"strconv"
"io"
"os"
)
@shuntksh
shuntksh / bloom-filter.ts
Last active November 4, 2023 04:23
Bloom Filter in Typescript
/**
* BloomFilter is a probabilistic data structure used to test whether an element
* is a member of a set, allowing for false positives.
*/
export class BloomFilter {
static readonly DEFAULT_BIT_LEN = 8;
#size: number;
#bitArray: Uint8Array; // Uint8Array might be slower than BigInt64Array but easier to debug
#hashPassCount: number;
@shuntksh
shuntksh / trie.ts
Created November 5, 2023 04:54
Simple Trie for Domain Matching
class TrieNode {
children: Map<string, TrieNode> = new Map();
isValidDomain = false;
hasWildcard = false;
}
class Trie {
static build(allowedDomains: string | string[] | Trie, allowedSubDomains: string[]): Trie {
if (allowedDomains instanceof Trie) return allowedDomains;
if (!Array.isArray(allowedDomains)) allowedDomains = [allowedDomains];
@shuntksh
shuntksh / bm25.py
Created November 7, 2023 06:32
TF-IDF and BM25
import math
from collections import Counter
import string
# Example collection of documents
documents = [
'the quick brown fox jumps over the lazy dog',
'never jump over the lazy dog quickly',
'bright sun and the quick lazy dog',
'good dogs jump high'
@shuntksh
shuntksh / is-arc-browser.js
Created November 12, 2023 01:20
Is Arc Browser
// https://stackoverflow.com/questions/76123232/can-javascript-detect-the-arc-browser
console.log(
getComputedStyle(document.documentElement)
.getPropertyValue('--arc-palette-title') ? 'Is Arc' : 'Is Not Arc'
);
@shuntksh
shuntksh / copy-button.tsx
Created November 12, 2023 04:49
React Component to Copy Value to Clipboard
import { useCallback, useState } from 'react';
import { CheckIcon, CopyIcon } from 'lucide-react';
type Timeout = number | undefined;
type ClipboardProps = {
value: string;
onError?: (err: Error) => void;
} & React.HTMLAttributes<HTMLButtonElement>;