Skip to content

Instantly share code, notes, and snippets.

@adenosinew
adenosinew / fileExistence.go
Created April 1, 2020 02:28
[os.IsExist and os.IsNotExist] #go #file
/*
Watch out, os.IsExist(err) != !os.IsNotExist(err)
They are error checkers, so use them only when err != nil, and you want to handle
specific errors in a different way!
Their main purpose is to wrap around OS error messages for you, so you don't have to test
for Windows/Unix/Mobile/other OS error messages for "file exists/directory exists" and
"file does not exist/directory does not exist"
@adenosinew
adenosinew / reference.md
Created March 9, 2020 20:10
[Crontab] #linux
@adenosinew
adenosinew / mytimer.timer
Last active March 9, 2020 20:09
[Set up timer] #linux
[Unit]
Description=Runs mytimer every hour
[Timer]
OnUnitActiveSec=1h
Unit=mytimer.service
[Install]
WantedBy=multi-user.target
@adenosinew
adenosinew / read_json.py
Created February 26, 2020 23:05
[read and write a json] #python
# string:
import json
# json.loads(string)
print ( json.loads(open("in.json","r").read() ) )
dictionary:
import json
# json.load(_io)
print( json.load(open("in.json","r")) )
@adenosinew
adenosinew / simple-timing.go
Last active February 24, 2020 04:20
[Measuring execution time] #golang
package main
import (
"time"
"fmt"
)
func main() {
start := time.Now()
@adenosinew
adenosinew / lsyncd.conf.lua
Created December 20, 2019 00:28
[lsyncd]
# https://klionsec.github.io/2017/11/18/lsyncd/
@adenosinew
adenosinew / deployKeys.sh
Created December 18, 2019 19:31
[Github Management]
# https://developer.github.com/v3/guides/managing-deploy-keys/
@adenosinew
adenosinew / checkServiceRunning.sh
Created October 25, 2019 15:25
[Linux Monitoring]
systemctl is-active --quiet <service> && echo <service> is running
@adenosinew
adenosinew / cpuStressTest.sh
Last active February 20, 2024 23:57
[Linux benchmarks]
# Installation
sudo apt-get install stress
yum install stress
# Usage
@adenosinew
adenosinew / findLatestCommit.sh
Last active February 20, 2024 23:57
[Git commands]
# https://stackoverflow.com/questions/5188320/how-can-i-get-a-list-of-git-branches-ordered-by-most-recent-commit
git for-each-ref --sort=-committerdate refs/heads/
# Or using git branch (since version 2.7.0)
git branch --sort=-committerdate # DESC
git branch --sort=committerdate # ASC