Skip to content

Instantly share code, notes, and snippets.

@tuan
tuan / fcot.sh
Created April 12, 2022 23:14
Use FZF and Ripgrep to find notes and open it in CotEditor
#!/usr/bin/env bash
# 1. Search for text in files using Ripgrep
# 2. Interactively restart Ripgrep with reload action
# 3. Open the file in Vim
RG_PREFIX="rg --column --line-number --no-heading --color=always --smart-case "
INITIAL_QUERY="${*:-}"
IFS=: read -ra selected < <(
FZF_DEFAULT_COMMAND="$RG_PREFIX $(printf %q "$INITIAL_QUERY")" \
fzf --ansi \
@tuan
tuan / fzf-code.bash
Created March 18, 2022 16:38
Fuzzy search file by content and open the selected file in the existing vscode instance
#!/usr/bin/env bash
# 1. Search for text in files using Ripgrep
# 2. Interactively restart Ripgrep with reload action
# 3. Open the file in existing vscode instance
RG_PREFIX="rg --column --line-number --no-heading --color=always --smart-case "
INITIAL_QUERY="${*:-}"
IFS=: read -ra selected < <(
FZF_DEFAULT_COMMAND="$RG_PREFIX $(printf %q "$INITIAL_QUERY")" \
fzf --ansi \
@tuan
tuan / alfred-safari-history-search.sh
Last active March 6, 2022 18:02
Alfred Safari History Search
sqlite3 ~/Library/Safari/History.db "select json_object('items', json_group_array(json_object('quicklookurl', url, 'uid', title, 'title', title, 'subtitle', url, 'arg', url))) as json_result from (select v.title, i.url, i.visit_count_score from history_items i join history_visits v on (v.history_item = i.id and i.domain_expansion || v.title LIKE '%' || replace('{query}', ' ','%') || '%') group by v.title order by v.visit_time desc)"
@tuan
tuan / openvpn-azure-steps.md
Last active December 27, 2021 16:25
OpenVPN + Pihole on Azure

Create VM

  1. Azure > Marketplace > Ubuntu

Configure VM

  1. Autoshutdown Disabled
  2. Networking: Add inbound rule for port 1194 (TCP and UDP)

Install OpenVPN

wget https://git.io/vpn -O openvpn-install.sh
@tuan
tuan / launch.json
Created February 2, 2019 16:47
Debug configuration for rxjs
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Mocha All",
"program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
"args": [
"--opts",
@tuan
tuan / rxjs-bindCallback-test.js
Created May 9, 2017 23:08
RxJS bindcallback's stream completes after first emit
// jsbin https://jsbin.com/xeyugac/edit?js,console
const { Observable } = Rx;
const testFn = (callback) => {
callback(1,2);
};
const testFnAsObservable = Observable.bindCallback(testFn);
const obs = testFnAsObservable();
@tuan
tuan / throttleAsync.ts
Created May 3, 2017 05:30
Throttle number of observables
import { Observable, Subject, Subscription } from 'rxjs/Rx';
export type FuncAsync<T> = () => Observable<T>;
type QueuedExecution = () => Subscription;
export class ThrottleAsync<T> {
private queue: QueuedExecution[];
@tuan
tuan / 1.procedureal_feeding_time.rb
Last active November 12, 2016 20:27
Functional Core Imperative Shell
def feeding_time
walruses.each do |walrus| /* we know how to destructure walruses array */
walrus.stomach << Cheese.new /* we know the deep structure of a walrus object */
end
end
@tuan
tuan / host.js
Created November 1, 2016 17:40
RxJs and window's postMessage for intercommunication
import * as Rx from "rxjs/Rx";
import * as uuid from "uuid";
import {IRequest} from "./common";
let button = document.querySelector("button");
let iframe = document.createElement("iframe");
iframe.src = "/proxy.html";
document.body.appendChild(iframe);
function unary(fn) {
return (value) => fn.call(this, value);
}