Skip to content

Instantly share code, notes, and snippets.

@sp3c73r2038
sp3c73r2038 / screenshot
Last active April 14, 2023 19:52
a script using ImageMagick to take screenshots
#!/bin/bash
DIR="${HOME}/images/screenshots"
DATE="$(date +%Y%m%d-%H%M%S)"
NAME="${DIR}/screenshot-${DATE}.png"
LOG="${DIR}/screenshots.log"
# Check if the dir to store the screenshots exists, else create it:
if [ ! -d "${DIR}" ]; then mkdir -p "${DIR}"; fi
@sp3c73r2038
sp3c73r2038 / post.py
Last active April 7, 2023 15:27
urlopen with proxy support
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import urllib
import urllib2
data = urllib2.urlencode({'foo': 'bar'})
r = urllib2.Request('https://www.google.com', # url
data, # post data
@sp3c73r2038
sp3c73r2038 / linux_net_tcp.py
Created February 6, 2015 03:26
a toolkit Python script looking into /proc/net/tcp
# -*- coding: utf-8 -*-
import re
import sys
with open('/proc/net/tcp') as f:
lineno = 0
sockets = []
for line in f:
lineno += 1
if lineno == 1:
@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):
@sp3c73r2038
sp3c73r2038 / archlinux.install.20130115.markdown
Last active July 13, 2021 02:47
how to install archlinux on a BIOS i386 (64 bit supported) virtualbox machine.

archlinux install

latest info and more instructions, please refer to the original archlinux wiki page!

  • get archboot and insert it into cdrom
  • network config (generally done)
  • prepare the storage (using cfdisk, a boot and root partition)
  • mount partitions
@sp3c73r2038
sp3c73r2038 / model.py.tpl
Created March 26, 2015 06:36
reflect and generate models code from database schema :)
# -*- coding: utf-8 -*-
class {{ table.name }}:
__tablename__ = '{{ table.name }}'
{% for col in table.columns %}
{{ col.name }} = Column({{col.type}}{% if col.primary_key %}, primary_key=True{% endif%}{% if not col.nullable %}, nullable=False{% endif %})
{% endfor -%}
@sp3c73r2038
sp3c73r2038 / app.py
Last active May 24, 2021 11:51
how to acccess multiple database with same tablename, in Flask and SQLAlchemy.
# -*- coding: utf-8 -*-
from flask import Flask
from sqlalchemy import SQLAlchemy
app.config['SQLALCHEMY_DATABASE_URI'] = "mysql+oursql://foo:bar@localhost/test1"
# binds multiple database definition
app.config['SQLALCHEMY_BINDS'] = {
"db1": "mysql+oursql://foo:bar@localhost/test1",
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 / b64.js
Last active September 23, 2020 06:13
pure javascript implemented base64 encoding/decoding library.
;
(
function () {
'use strict'
var root = this
var b64
if (typeof exports !== 'undefined') {
@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"
)