Skip to content

Instantly share code, notes, and snippets.

View Ronmi's full-sized avatar

Ronmi Ren Ronmi

View GitHub Profile
@Ronmi
Ronmi / cache.md
Created January 13, 2025 09:20
Enable local cache for Forgejo action runner

By default, cache location when running CI tasks is /opt/hostedtoolcache. It's okay to change it by setting 3 envvars in config.yaml

runner:
  envs:
    RUNNER_TOOL_CACHE: /path/to/cache
    AGENT_TOOLSDIRECTORY: /path/to/cache
    RUN_TOOL_CACHE: /path/to/cache
@Ronmi
Ronmi / tw covid sms.md
Created May 23, 2021 21:45
Android 一鍵實聯制

使用 Automate 啟動 Binary Eye 掃碼後,自動傳送簡訊到 1922

  1. 安裝 Binary Eye
  2. 安裝 Automate
  3. 下載 Automate Flow 並匯入
  4. 把 flow 加到桌面 (新增桌面小工具 -> automate -> flow shortcut -> TW COVID SMS)

Automate 預設簡訊每小時只能發 10 封,若經常需要出入實聯制場所,請自行更改設定 (在主選單的 Settings -> SMS sent limit)

((前 轉 前) 反轉)
@Ronmi
Ronmi / ioc.php
Created October 31, 2017 03:37
poorman IoC
<?php
class SomeClass {
public function process($c) {
if ($c instanceof ClassA) {
$this->processA($c);
} elseif ($c instanceof ClassB) {
$this->processB($c);
} else {
// error process

Worst-case matching

This benchmark matches the last route and unknown route. It generates a randomly prefixed and suffixed route in an attempt to thwart any optimization. 1,000 routes each with 9 arguments.

This benchmark consists of 16 tests. Each test is executed 1,000 times, the results pruned, and then averaged. Values that fall outside of 3 standard deviations of the mean are discarded.

Test Name Results Time + Interval Change
r3 - unknown route (1000 routes) 995 0.0000081977 +0.0000000000 baseline
r3 - last route (1000 routes) 997 0.0000102492 +0.0000020514 25% slower
@Ronmi
Ronmi / compiled.php
Last active October 20, 2015 01:58
PoC of router - compiled php
<?php
class FruitRouteKitGeneratedMux implements Fruit\RouteKit\Router
{
public function __construct()
{
}
private function dispatchGET($uri)
{
@Ronmi
Ronmi / mux.php
Created October 19, 2015 10:21
PoC of router - creating routing table
<?php
require('vendor/autoload.php');
$mux = new Fruit\RouteKit\Mux;
$mux
->get('/', ['\A\B\C', 'methodA'])
->get('/obj/methodA', ['Obj', 'methodA'])
->get('/obj/methodB', ['Obj', 'methodB'])
@Ronmi
Ronmi / DNSQuery.php
Created December 3, 2014 01:30
Pure php code to query DNS record
<?php
/**
* Usage:
* $obj = new DNSQuery('www.google.com', '8.8.8.8', 1, 'A', 'IN');
* if ($obj->isSuccess()) var_dump(DNSQuery::parse($obj->response));
*/
class DNSQuery
{
private $name;
@Ronmi
Ronmi / array_slice_test.vala
Created June 5, 2014 02:39
Vala array slicing test
class Test : Object {
public static int main (string[] args) {
int[] r = {1,2,3,4,5};
stdout.printf ("original: %d %d\n", r[1], r[2]);
int[] a = r[1:2];
a[0] = a[1] = 9;
stdout.printf ("default : %d %d\n", r[1], r[2]);
unowned int[] b = r[1:2];
@Ronmi
Ronmi / gist:385c9c37feccf913cd77
Last active August 29, 2015 14:01
某 SQL Builder 將使用的 FROM 建立語法
<?php
// (`model1` LEFT JOIN `model2` ON `model2`.`col2`=`model1`.`id`)
$from = $b->tables(
$b->left_join($m1, $m2, $b->eq($m2->col2, $m1->id))
);
// `model1`,`model2`,`model3`
$from = $b->tables($m1, $m2, $m3);