Skip to content

Instantly share code, notes, and snippets.

View AmaranthLIS's full-sized avatar

Igor Lu AmaranthLIS

View GitHub Profile
@AmaranthLIS
AmaranthLIS / gist:c979832d6472e27853aa80a725bf4d3c
Created August 21, 2017 10:21
show and kill process by PID
pstree 32567
pstree -p 32567
pstree -p 32567| perl -ne 'print "$_\n" foreach /\((\d+)\)/g;'
pstree -p 32567| perl -ne '`kill -9 $_` foreach /\((\d+)\)/g;'
pstree -p 32567| perl -ne 'print "$1\n" while /\((\d+)\)/g;'
pstree -p 32567| perl -ne '`kill -9 $1` while /\((\d+)\)/g;'
@AmaranthLIS
AmaranthLIS / find.sh
Last active August 23, 2017 11:27
unix find file
#find string in any file for dir/subdir
grep -lir 'go api' ./
#useful util for a lof of commands, example:
tldr grep
tldr find
#list of dir
grep mkyong -lr /path/folder
@AmaranthLIS
AmaranthLIS / trick-console.sh
Created August 22, 2017 07:36
trick console
#scheduler; list
$ atq
#add
echo wget https://sample.com | at 3:00 PM
$ cp /home/sample.txt{,-old}
$ ls
text_comes_here_1.txt
@AmaranthLIS
AmaranthLIS / runit
Created August 23, 2017 10:18
runit
sv s /service/*
Stops a service immediately (would still start on next boot):
# sv d ssh
Restarts a service:
# sv t ssh
# sv i postgresql
Reloads a service:
# sv h ssh
Shows status of a service and it's log service:
@AmaranthLIS
AmaranthLIS / gist:67d3fb992b48746b426166fba7aff27a
Created October 4, 2018 08:29
Strange thing with CompletableFuture
System.out.println("CompletableFuture");
Future<String> foo = new CompletableFuture<>();
System.out.println(foo.cancel(true));
System.out.println(foo.cancel(true));
System.out.println("Guava SettableFuture");
foo = SettableFuture.create();
System.out.println(foo.cancel(true));
System.out.println(foo.cancel(true));
@AmaranthLIS
AmaranthLIS / Fibonacci
Last active October 4, 2018 09:55
calculate Fibonacci
public class Fibonacci {
public static long fibonacci(int n) {
if (n <= 1) return n;
else return fibonacci(n-1) + fibonacci(n-2);
}
public static void main(String[] args) {
int n = Integer.parseInt(args[0]);
for (int i = 1; i <= n; i++)
System.out.print(i + ": " + fibonacci(i));
@AmaranthLIS
AmaranthLIS / justUpload.go
Created October 15, 2018 12:34
Go upload file(s)
package main
import (
"bytes"
"fmt"
"io"
"mime/multipart"
"net/http"
"os"
"strings"
@AmaranthLIS
AmaranthLIS / receiveFile.go
Created October 15, 2018 12:36
Receive file with Gin
package main
import (
"fmt"
"log"
"net/http"
"github.com/gin-gonic/gin"
)
func main() {
package main
import (
"io/ioutil"
"log"
"net/http"
"crypto/tls"
"crypto/x509"
)
@AmaranthLIS
AmaranthLIS / HTTP-server with Shutdown
Created October 19, 2018 23:46
Golang: Shutdown HTTP server by requesting specific URL
package main
import (
"context"
"fmt"
"log"
"net/http"
)
func main() {