Skip to content

Instantly share code, notes, and snippets.

import android.opengl.GLES20;
import android.view.Surface;
import javax.microedition.khronos.egl.EGL10;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.egl.EGLContext;
import javax.microedition.khronos.egl.EGLDisplay;
import javax.microedition.khronos.egl.EGLSurface;
public class SurfaceUtil {
@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 / Poly.java
Last active September 6, 2022 01:09
A concave polygon to triangles.
import java.io.*;
import java.util.*;
import java.util.List;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Poly extends JPanel {
public static void main(String[] args) {
@hisui
hisui / .mm
Created May 22, 2015 00:19
Checking if a given frame is a key frame.
static BOOL isKeyFrame(CMSampleBufferRef sample)
{
auto a = CMSampleBufferGetSampleAttachmentsArray(sample, 0);
if (CFArrayGetCount(a) > 0) {
CFBooleanRef value;
auto b = CFDictionaryGetValueIfPresent
((CFDictionaryRef) CFArrayGetValueAtIndex(a, 0)
, kCMSampleAttachmentKey_NotSync
, reinterpret_cast<const void **>(&value))
;
@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 / cpu-usage.cpp
Last active February 3, 2022 13:53
[iOS] Getting current CPU usage.
#include <mach/mach.h>
// http://stackoverflow.com/questions/8223348/ios-get-cpu-usage-from-application
double getCurrentCPUUsage()
{
thread_array_t threads;
mach_msg_type_number_t threadCount;
if (task_threads(mach_task_self(), &threads, &threadCount) != KERN_SUCCESS) {
return -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'
)