Skip to content

Instantly share code, notes, and snippets.

View xcooper's full-sized avatar

Cooper xcooper

  • Commscope
  • Taiwan
View GitHub Profile
@xcooper
xcooper / index.html
Created May 4, 2023 06:48
JS for converting Prometheus format to JSON
<!DOCTYPE html>
<html>
<head>
<title>Exposition to JSON Converter</title>
</head>
<body>
<h1>Exposition to JSON Converter</h1>
<form id="expositionForm">
<label for="expositionInput">Exposition String:</label>
<br>
@xcooper
xcooper / nc.py
Created July 11, 2022 07:00
wait on socket and redirect to stdout
import socket, os, sys
addr = ("", 4444)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(addr)
s.listen(1)
conn, addr = s.accept()
while 1:
data = conn.recv(1024)
if not data: break
@xcooper
xcooper / HHKB.json
Last active February 17, 2021 07:08
key-mapper configuration for mapping Keychrone K6 to HHKB
{
"mapping": {
"1,58,1": "key_leftctrl",
"1,56,1+1,38,1": "key_pageup",
"1,56,1+1,52,1": "key_pagedown",
"1,56,1": "disable",
"1,56,1+1,2,1": "key_f1",
"1,56,1+1,3,1": "key_f2",
"1,56,1+1,5,1": "key_f4",
"1,56,1+1,6,1": "key_f5",
#!/usr/bin/python
import os, sys, re, os.path, shutil
from datetime import date, timedelta
RESERVED_DAYS = 30
date_pattern = re.compile('[0-9]+-[0-9]+-[0-9]+')
def logcleanup(reserveddays, dirname, names):
for name in names:
@xcooper
xcooper / spring-config.groovy
Created September 7, 2015 03:42
Sample groovy config for Spring Framework.
import org.springframework.orm.hibernate4.HibernateTransactionManager
import org.springframework.jdbc.datasource.embedded.*
import org.springframework.orm.hibernate4.LocalSessionFactoryBean
beans {
importBeans("classpath:META-INF/spring/cwep-popularity-storage/data-access.xml")
importBeans("classpath:META-INF/spring/cwep-popularity-storage/service.xml")
dataSource(EmbeddedDatabaseFactoryBean) {
databaseType = EmbeddedDatabaseType.H2
}
@xcooper
xcooper / svn-ignore.txt
Last active November 3, 2015 09:30
common svn ignore list
*.iml
*.ipr
.classpath
.gradle
.idea
.project
.settings
build
classes
bin
@xcooper
xcooper / httpd-proxy.conf
Last active August 31, 2015 10:35
Apache httpd reverse proxy
<IfModule proxy_module>
<IfModule proxy_http_module>
#LogLevel alert trace3
#################
# Reverse Proxy #
#################
ProxyRequests Off
ProxyTimeout 3600
# turn this on if there are https URL to handle with.
@xcooper
xcooper / init-postgres.txt
Last active August 29, 2015 14:22
PostgreSQL initdb
$ su
# postgresql-setup initdb
# su - postgres
$ psql
\password postgres
$ echo "host all all 192.168.133.0/24 md5" >> /var/lib/pgsql/data/pg_hba.conf
$ exit
# service postgres start
# exit
@xcooper
xcooper / setup-environment.sh
Last active April 25, 2016 03:08
My script to setup environment after Ubuntu installed.
#!/bin/bash
mkdir -p ~/bin
mkdir -p ~/workspace
# startup environment
cat >> ~/.profile <<EOF
export PATH=~/bin:$PATH
export TEMP=${TEMP:-"/tmp"}
EOF
chmod u+x ~/.profile
@xcooper
xcooper / genkey.sh
Last active August 4, 2020 06:06
Generate private key, certification request, optional PEM files at once
#!/bin/bash
echo "edit this file before you execute it!!"
echo "make sure keytool and openssl commands are in PATH"
echo "Contiune?" | read ANS
echo "give me CN(www.xxx.com.tw)" | read CN
echo "give me default password(length >= 8)" | read -s PASS
set -e
# Edit these arguments