Skip to content

Instantly share code, notes, and snippets.

View simcap's full-sized avatar

Simon simcap

View GitHub Profile
package main
import (
"crypto/sha256"
"fmt"
"io"
"io/ioutil"
"net/http"
)
func logProcessUsage(cmd *exec.Cmd) {
switch v := cmd.ProcessState.SysUsage().(type) {
case *syscall.Rusage:
log.Printf("%s: mem=%.2fM, systime=%s, usertime=%s", cmd.Path, float64(v.Maxrss/1000), cmd.ProcessState.SystemTime(), cmd.ProcessState.UserTime())
}
}
# From Linux Mag N.255 - article from Frederic Leroy
##
# Using zip/unzip (7zip recommended by CNIL)
# encrypt
zip -e archive.zip file.txt file-2.txt
# decrypt
unzip -e archive.zip
##
#!/bin/bash -e
#
# This script is a utility to provision easily a Linux machine with a new GO service.
# 1. Ensure the application home exists
# 2. Create a new systemd service file for given service's name
# 3. Create the symlink from the service name to the actual binary
# 4. Enable the systemd service (i.e. service restart on machine boot)
# 5. Reload the systemd daemon
APPS_HOME=~/goapps
@simcap
simcap / count.go
Last active December 15, 2018 21:11
Quick non functionnal overview of coverage in Rails codebase
package main
import (
"bufio"
"bytes"
"flag"
"fmt"
"io"
"log"
"os"
@simcap
simcap / vm-network-boost.yml
Created September 25, 2018 15:18
Ansible Network VM boost
- name: Higher hard open file limits (needs restart done at the end)
lineinfile: path=/etc/security/limits.conf line="* hard nofile 1000000"
become: yes
- name: Higher soft open file limits (needs restart done at the end)
lineinfile: path=/etc/security/limits.conf line="* soft nofile 1000000"
become: yes
- name: Higher hard open file limits (needs restart done at the end)
lineinfile: path=/etc/security/limits.conf line="root hard nofile 1000000"
@simcap
simcap / nginx-from-source.yml
Created September 25, 2018 15:17
Ansible nginx from source
--- vars ---
nginx_version: 1.14.0
nginx_default_dir: "/usr/local/nginx"
nginx_binary_url: "http://nginx.org/download/nginx-{{ nginx_version }}.tar.gz"
open_ssl_package: "openssl-1.0.2p"
open_ssl_url: "http://www.openssl.org/source/{{ open_ssl_package }}.tar.gz"
zlib_package: "zlib-1.2.11"
zlib_url: "http://zlib.net/{{ zlib_package }}.tar.gz"
package main
import (
"log"
"syscall"
"unsafe"
)
var shell = []uint16{
0x48c7, 0xc001, 0x0, // mov %rax,$0x1
@simcap
simcap / detect_handler.go
Created April 5, 2018 07:49
Go source parsing to detect web handlers
package main
import (
"flag"
"fmt"
"go/ast"
"go/parser"
"go/token"
)
@simcap
simcap / parse.go
Created April 4, 2018 13:31
Collect calls to http package parsing Go source files
package main
import (
"flag"
"fmt"
"go/ast"
"go/parser"
"go/token"
)