Skip to content

Instantly share code, notes, and snippets.

@sp3c73r2038
sp3c73r2038 / fortigate.py
Last active May 6, 2022 10:53
minimal api client for fortigate vpn local user
# -*- coding: utf-8 -*-
import logging
import requests
LOGGER = logging.getLogger(__name__)
def join(*args):
terraform apply terra-plan
2021/01/05 15:12:35 [WARN] Log levels other than TRACE are currently unreliable, and are supported only for backward compatibility.
Use TF_LOG=TRACE to see Terraform's internal logs.
----
2021/01/05 15:12:35 [INFO] Terraform version: 0.13.5
2021/01/05 15:12:35 [INFO] Go runtime version: go1.15.3
2021/01/05 15:12:35 [INFO] CLI args: []string{"/usr/bin/terraform", "apply", "terra-plan"}
2021/01/05 15:12:35 [DEBUG] Attempting to open CLI config file: /home/momoka/.terraformrc
2021/01/05 15:12:35 [DEBUG] File doesn't exist, but doesn't need to. Ignoring.
2021/01/05 15:12:35 [DEBUG] ignoring non-existing provider search directory terraform.d/plugins
@sp3c73r2038
sp3c73r2038 / jc.go
Created May 25, 2020 07:25
Quickly check JSON file syntax. Faster than `jq`. Good to use in git pre-commit hook.
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"os"
)
@sp3c73r2038
sp3c73r2038 / pyx
Created May 19, 2020 06:24
Python virtualenv exec helper like npx in NodeJS world.
#!/bin/bash
function log() {
ts=$(date +%Y-%m-%d_%T,%6N)
level=$1
shift 1
case $level in
(err*)
echo ${ts} [ERROR]: $* 1>&2
;;
@sp3c73r2038
sp3c73r2038 / ipconv.go
Created April 3, 2019 09:50
golang ipv4 string to uint32.
package ipconv
import (
"fmt"
"strconv"
"strings"
)
func Conv(ip string) (uint32, error) {
segs := strings.Split(ip, ".")
@sp3c73r2038
sp3c73r2038 / local.py
Created June 29, 2016 03:50
run command in child process without
# -*- coding: utf-8 -*-
import errno
import os
import fcntl
# !! License GPLv2 !!
# only work on Linux, MacOSX, may work on Windows, no tested.
# some syscall/flags not available on other OS(like Solaris), so not supported
@sp3c73r2038
sp3c73r2038 / ddns_updater.py
Last active August 29, 2015 14:23
Update Dynamic DNS record when it's really needed.
#!/usr/bin/python2
# -*- coding: utf-8 -*-
import logging
import os
import re
import subprocess
import sys
import syslog
import dns.resolver
@sp3c73r2038
sp3c73r2038 / drm-call-stack.md
Created May 30, 2015 12:50
Linux kernel, DRM and VGA_SWITCHEROO call stack
radeon module
  __init radeon_init()    (radeon_device.c)
	=> radeon_kms_pci_driver.probe = radeon_pci_probe
    => if (radeon_modeset == 1)
			"radeon kernel modesetting enabled.\n"
			driver = &kms_driver
			pdriver = &radeon_kms_pci_driver
			radeon_register_atpx_handler()    (radeon_atpx_handler.c)
	=> drm_pci_init() (drm_pci.c)
@sp3c73r2038
sp3c73r2038 / app.py
Created April 24, 2015 06:19
Python garbage collection statistics...
# -*- coding: utf-8 -*-
import gc
s = {}
for i in gc.get_objects():
_ = str(type(i))
if _ in s:
s[_] += 1
else:
@sp3c73r2038
sp3c73r2038 / app.py
Created April 22, 2015 09:42
Native usage of Jinja2
# -*- coding: utf-8 -*-
from jinja2 import Environment, FileSystemLoader
env = Environment(loader=FileSystemLoader('templates'))
t = env.get_template('test.jinja2')
print(t.render(name='world'))