Skip to content

Instantly share code, notes, and snippets.

View ball6847's full-sized avatar
🎯
Focusing

Porawit Poboonma ball6847

🎯
Focusing
  • 7 Peaks Software Co., Ltd.
  • Bangkok, Thailand
View GitHub Profile
@ball6847
ball6847 / Caddyfile
Created February 6, 2024 08:02
Simple caddyfile with cors enabled for local development
(cors) {
@cors_preflight{args.0} method OPTIONS
@cors{args.0} header Origin {args.0}
handle @cors_preflight{args.0} {
header {
Access-Control-Allow-Origin "{args.0}"
Access-Control-Allow-Methods "GET, POST, PUT, PATCH, DELETE, OPTIONS"
Access-Control-Allow-Headers *
Access-Control-Max-Age "3600"
@ball6847
ball6847 / publish.ts
Last active February 6, 2024 08:03
Using deno to subscribe or publish realtime message via Mercure Hub
import { load } from "https://deno.land/std@0.214.0/dotenv/mod.ts";
import jwtEncode from "https://esm.sh/jwt-encode@1.0.1";
const env = await load();
// create jwt token for publishing
const jwtSecret = env["JWT_SECRET_KEY"];
const jwtPayload = {
mercure: {
publish: ["/messages/{event}"],
@ball6847
ball6847 / ansible.ts
Last active January 26, 2024 18:43
Parse ansible module args in Deno
export function parseAnsibleArgs(argsStr: string) {
const parsedArgs: Record<string, string | boolean | string[] | null> = {};
const argRegex = /(\S+)=('[^']*'|[^ ]+)/g;
const matches = argsStr.matchAll(argRegex);
for (const match of matches) {
const key = match[1];
let value = match[2];
if (value === "None") {
#!/usr/bin/env -S deno run --unstable --allow-read --allow-write --allow-run --allow-net
import { ensureDirSync } from "https://deno.land/std@0.123.0/fs/mod.ts";
import { join } from "https://deno.land/std@0.123.0/path/mod.ts";
import pLimit from "https://cdn.skypack.dev/p-limit@v4.0.0";
function readJson(file: string) {
const jsonString = Deno.readTextFileSync(file);
const json = JSON.parse(jsonString);
return json;
}
@ball6847
ball6847 / place-signal-order.mq4
Created June 24, 2021 02:22
mt4 script to place order for multi tp at once
//+------------------------------------------------------------------+
//| ball6847_SendOrder.mq4 |
//| Copyright 2021, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2021, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
#property version "1.00"
#property strict
#property script_show_inputs
@ball6847
ball6847 / reclaim-wsl-memory.sh
Created August 18, 2020 05:31
Reclaim wsl2 memory and release it to host
# run this as root
echo 1 > /proc/sys/vm/drop_caches
echo 1 > /proc/sys/vm/compact_memory
sh -c "echo 1 > /proc/sys/vm/drop_caches; 1 > /proc/sys/vm/compact_memory"
@ball6847
ball6847 / docker-compose.yml
Created June 10, 2020 10:17
prerender server - docker-compose.yml
version: '3'
services:
prerender:
image: ball6847/prerender:5.6.0-1
restart: unless-stopped
environment:
CACHE_TTL: 86400
CACHE_DIR: /tmp/prerender
ports:
@ball6847
ball6847 / simple-changes.ts
Created April 29, 2020 06:53
Generic SimpleChanges for angular
import { SimpleChanges } from '@angular/core';
type SimpleChanges<T> = Record<keyof T, SimpleChange>
@ball6847
ball6847 / Dockerfile
Last active March 17, 2020 20:28
vscode devcontainer dotnet - put these files in .devcontainer directory at project root
FROM ball6847/vscode-remote-dotnet:1.1.4
# dotnet-install.sh
# follow the instuction here https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-install-script
# or if you dont want to read, then run
wget https://dot.net/v1/dotnet-install.sh
# make this file in our PATH, I already have my profile based PATH setup at ~/.local/bin
# then give it a permission to be executed
mv dotnet-install.sh ~/.local/bin
chmod +x ~/.local/bin/dotnet-install.sh