Skip to content

Instantly share code, notes, and snippets.

package main

func reverse(str string) string {
	if len(str) == 0 || str == " " {
		return str
	}
	index := 0
	for index < len(str) && str[index] != ' ' {
 index = index + 1
package main

func reverse(str string) string {
	if len(str) == 0 || str == " " {
		return str
	}
	index := 0
	for index < len(str) && str[index] != ' ' {
 index = index + 1
@hellojukay
hellojukay / fetch.pl
Last active May 29, 2020 06:55
fetch all github stars
#!/usr/bin/env perl
use LWP::UserAgent;
use HTTP::Request;
use JSON::Parse;
my $ua = LWP::UserAgent->new();
$ua->agent("Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36");
# if you nedd proxy , don`t foreget it
# $ua->proxy(https => 'http://proxy.exmaple:3128');
# loop all stars util get empty response
@hellojukay
hellojukay / ss.pl
Created June 15, 2020 09:29
count tcp connection by process, base on ss command line
use strict;
use warnings;
my @lines = `ss -atp`;
my %hash;
for my $line (@lines) {
if($line =~ /pid=(\d{1,9})/) {
$hash{$1}++;
}
}
@hellojukay
hellojukay / exif.py
Created July 28, 2020 02:14
读取照片的 EXIF 信息
#!/bin/python
import glob
import exifread
from dateutil.parser import parse
files = glob.glob("*.JPG")
for file in files:
fh = open(file,"rb")
tags = exifread.process_file(fh)
@hellojukay
hellojukay / Certificates.go
Created August 27, 2020 10:18 — forked from Mattemagikern/Certificates.go
Create x509 certificate chain using Golang. Root CA, Designated CA, server CA
package main
import (
"crypto/rand"
"crypto/rsa"
"crypto/x509"
"crypto/x509/pkix"
"encoding/pem"
"fmt"
"math/big"
@hellojukay
hellojukay / perl_modules.pl
Created June 2, 2021 10:43
perl list installed modules
#!/usr/bin/env perl
sub find_modules {
my $dir = shift;
my @modules = ();
if(-d $dir){
chdir $dir;
my @files = glob "**/*.pm";
foreach (@files) {
$_ =~ s/$\.pm//g;
@hellojukay
hellojukay / progress.ml
Created June 27, 2021 07:04
progress bar write in Ocaml
;;
#load "unix.cma"
let rec repeat str n =
match n with 0 -> str | 1 -> str | n -> str ^ repeat str (n - 1)
let () =
let sum = ref 1 in
while true do
Printf.printf "[%d%%]%s" !sum (repeat "#" !sum);
@hellojukay
hellojukay / ocaml_color.ml
Last active August 14, 2021 03:57
OCaml print with color
module Log = struct
type color = Black | Red | Green | Yellow | Blue | Magenta | Cyan | White
let log_with_color c text =
match c with
| Black -> Printf.printf "\027[38;5;%dm%s\027[0m" 0 text
| Red -> Printf.printf "\027[38;5;%dm%s\027[0m" 1 text
| Green -> Printf.printf "\027[38;5;%dm%s\027[0m" 2 text
| Yellow -> Printf.printf "\027[38;5;%dm%s\027[0m" 3 text
| Blue -> Printf.printf "\027[38;5;%dm%s\027[0m" 4 text
@hellojukay
hellojukay / list.go
Created August 14, 2021 03:56
Use golang to implement linked list in functional style
package main
type Node struct {
Val int
Next interface{}
}
func create() interface{} {
return nil
}