Skip to content

Instantly share code, notes, and snippets.

@hisui
hisui / test.tf
Created June 2, 2023 06:24
Expose a Cloud Run service via an HTTP LB
resource "google_cloud_run_v2_service" "my_svc" {
name = "my-svc"
location = "asia-northeast1"
ingress = "INGRESS_TRAFFIC_ALL"
template {
containers {
image = "us-docker.pkg.dev/cloudrun/container/hello"
resources {
limits = { "cpu": "4000m", "memory" : "2Gi" }
}
@hisui
hisui / seq_cst.cpp
Last active December 6, 2022 05:22
memory order SeqCst demo
#include <thread>
#include <atomic>
#include <assert.h>
using namespace std;
static atomic<int> a = 0;
static atomic<int> b = 0;
static atomic<int> A = 0;
static atomic<int> B = 0;
@hisui
hisui / highlight.tsx
Created July 1, 2022 07:52
highlight.js + React
import React, { ReactElement, useMemo } from "react"
import hljs from "highlight.js"
import 'highlight.js/styles/dark.css'
export function Code(props: { lang: string, text: string }): ReactElement {
const { value } = useMemo(() =>
hljs.highlight(props.lang, trimMargin(props.text)),
[props.lang, props.text]
)
return <pre className="hljs"><code dangerouslySetInnerHTML={{ __html: value }} /></pre>
@hisui
hisui / dasym.rb
Last active February 20, 2022 13:19
Disassemble specific functions with "llvm-objdump" in macOS.
#!/usr/bin/env ruby
LLVM_OBJDUMP = "objdump"
options = %w(
--no-leading-addr
--no-show-raw-insn
--symbolize-operands
--x86-asm-syntax=intel
)
@hisui
hisui / kperf.rb
Created February 10, 2022 09:37
Execute perf-record in a pod-in-cluster and pref-script in local and then generate a flame graph.
#!/usr/bin/env ruby
require "json"
# https://github.com/brendangregg/FlameGraph
FG_SCRIPTS = raise "`FG_SCRIPTS` must be set by hand."
if ARGV.empty?
$stderr.puts("Usage: ruby kperf.rb $POD [ $CONTAINER ] > out.svg")
exit(-1)
@hisui
hisui / dead-lock.rb
Created December 8, 2021 10:25
Dead-lock on two parallel "SELECT FOR UPDATE" executions with the same condition.
require "mysql2"
require "pp"
def connect(iso: nil)
db = Mysql2::Client.new(
host: "127.0.0.1",
username: "root",
password: '',
database: 'test'
)
@hisui
hisui / config.json
Created November 3, 2021 06:14
Resize GKE node pools at once.
{
"clusters": [
{
"project": "<project-name>",
"name": "<cluster-name>",
"zone": "<cluster-zone>",
"nodePools": {
"my-node-pool-1": 0,
"my-node-pool-2": 1
}
import React, { Component } from 'react'
import { Subscription } from 'rxjs';
import Hls from "hls.js";
type HlsJSPlayerProps = {
broadcastId: string
};
type HlsJSPlayerState = {};
@hisui
hisui / clouddns.certbot-hook.rb
Created March 1, 2019 03:34
Certbot hook script for Cloud DNS
#!/usr/bin/env ruby
require 'timeout'
require 'rake'
CLOUD_DNS_ZONE = "..."
def cloud_dns(action, args = [])
sh "gcloud dns record-sets transaction #{action} --zone=#{CLOUD_DNS_ZONE} #{args.join(" ")}"
end
require "open-uri"
require "uri"
playlist_uri = "http://127.0.0.1:9001/broadcasts/1/hls/index.m3u8"
Segment = Struct.new :uri, :duration
Playlist = Struct.new :seq_no, :segments
def parse_m3u8(src, uri = "")