Skip to content

Instantly share code, notes, and snippets.

View sfertman's full-sized avatar
💭
🐗 🌳

sfertman

💭
🐗 🌳
View GitHub Profile
@sfertman
sfertman / 0_Mirror a repository using GitLab CI.md
Created February 29, 2024 15:52 — forked from cfstras/0_Mirror a repository using GitLab CI.md
How to mirror a repository using GitLab CI

Mirroring a repository using GitLab CI

inspired by https://gitlab.com/freifunkks/mirror-scripts

This can be used, for example, to clone a repository living on github over to GitLab in order to run CI

Setup

  • Setup separate repository with mirror scripts. We'll call it "mirror-scripts"
  • push the two files below.
  • in the .gitlab-ci.yml replace MY_REPO with your repo name
@sfertman
sfertman / api_backends.conf
Created January 26, 2024 23:12 — forked from nginx-gists/api_backends.conf
Deploying NGINX Plus as an API Gateway, Part 1
upstream warehouse_inventory {
zone inventory_service 64k;
server 10.0.0.1:80;
server 10.0.0.2:80;
server 10.0.0.3:80;
}
upstream warehouse_pricing {
zone pricing_service 64k;
server 10.0.0.7:80;
@sfertman
sfertman / wait-for.js
Last active May 19, 2021 02:36
Await the not awaitable
var obj = {
k: null
}
function waitable() {
return obj.k
}
async function waitFor(f) {
let r = f();
class AsyncObject {
constructor() {
this.__kvs = {};
this.__promises = {};
}
add(k, v) {
Object.defineProperty(this, k, {
get: () => {
this.__kvs[k]
@sfertman
sfertman / clj_robbery.py
Last active October 24, 2023 17:50
Useful JS clones of select Clojure functions (only pure fns go here)
def get_in(m, ks, not_found=None):
l = len(ks)
def _get_in(m, k_id):
if m == None or k_id < 1:
return not_found
elif k_id == 1:
return m[ks[l-1]] or not_found
else:
return _get_in(m[ks[l-k_id]], k_id-1)
return _get_in(m,l)
@sfertman
sfertman / GraphQLTimestamp.js
Created March 7, 2021 18:10 — forked from langpavel/GraphQLTimestamp.js
GraphQLTimestamp.js
import { Kind } from 'graphql/language';
import { GraphQLScalarType } from 'graphql';
function serializeDate(value) {
if (value instanceof Date) {
return value.getTime();
} else if (typeof value === 'number') {
return Math.trunc(value);
} else if (typeof value === 'string') {
return Date.parse(value);
@sfertman
sfertman / user.clj
Created August 20, 2020 20:36
My user clj for lein
(ns user
(:require
[clojure.tools.namespace.repl :refer [refresh]]
[clojure.pprint :refer [pprint]]))
(defn into-ns
[ns-name]
(require ns-name)
(in-ns ns-name))
function git_pull_rebase () {
local rebase_target='master'
if [ ! -z "${1}" ]; then
rebase_target="${1}"
fi
local this_branch=`git rev-parse --abbrev-ref HEAD`
if [ "${this_branch}" = "${rebase_target}" ]; then
echo "Current branch is the same as rebase target. Nothing to do."
return
fi
@sfertman
sfertman / jm.md
Last active June 24, 2020 17:50
Java versoin Manager?

I'm REALLY tired of managing java versions on any given computer! First I got to find it and download it. Then fiddle with the env until its visible to jenv. Then use jenv which is fine but the user experience there could be smoother. Why don't we have a small utility like n for java versions. It should be stupid easy to build with clojure and maybe compile with graal vm for command line speed. I should just be able to type:

jm search <some regexp> # to search all available resources online and mark the ones already installed (a-la brew)
jm 11 # to get the latest version of java 11.x.y if doesn't exist on machine or switch to whatever java 11.x.y already exists on machine (will error if not exist in the wild)
jm 11.4.5 # to get/switch a specific version (will error if not exists in the wild)
jm add x.y.z # to add a java version explicitly (will error if not exists in the wild)
jm rm 11.4.5 # to remove a java version (will error if not exists)
jm switch x.y.z # to switch to a java version explicitly
@sfertman
sfertman / add_certs.sh
Created June 10, 2020 20:57
Add let's encrypt certs to your openvpn access server web ui
#!/bin/sh
function sacli_kv_config_put () {
/usr/local/openvpn_as/scripts/sacli --key "${1}" --value_file "${2}" ConfigPut
}
sacli_kv_config_put "cs.priv_key" "/etc/letsencrypt/live/${1}/privkey.pem"
sacli_kv_config_put "cs.priv_key" "/etc/letsencrypt/live/${1}/cert.pem"
sacli_kv_config_put "cs.priv_key" "/etc/letsencrypt/live/${1}/fullchain.pem"