Skip to content

Instantly share code, notes, and snippets.

@khajer
khajer / recursive-show -file-folder.py
Created January 4, 2024 05:06
recursive-show -file-folder.py
import os
def listfilepath(space, path):
lst = os.listdir(path)
for f in lst:
if os.path.isdir(path+"/"+f):
print(space, "[folder]:", f)
listfilepath(space+" ", path+"/"+f)
else:
print(space, "file:", f)
@khajer
khajer / reduce_alpha_image.py
Created February 18, 2019 04:28
reduce alpha image
from PIL import Image
arImg = [
"android_128_px.png",
"apache_128_px.png",
"coupon_128_px.png",
"graphs_128_px.png",
"lab_128_px.png",
@khajer
khajer / json2struct_go.go
Last active September 28, 2018 09:29
json string 2 struct golang
/*
final output
type Simple struct {
Status string `json:"status"`
Message string `json:"message"`
Test float64 `json:"test"`
Test1 float64 `json:"test1"`
Ar []string `json:"ar"`
type Result struct {
Eligible float64 `json:"eligible"`
package main
import (
"fmt"
"time"
"math/rand"
)
func main() {
fmt.Println("generate time in/out")
from datetime import datetime, timedelta
import random
def main():
print "generate time attendant"
for i in range(30):
t = random.randrange(45)
dStart = datetime(2009, 1, 6, 9, t+15, 24, 78915)
@khajer
khajer / main.go
Created June 5, 2018 10:01
gen star
/*
*
***
*****
*******
*********
***********
*********
*******
*****
/*
*
***
*****
*******
*********
***********
*********
*******
*****
@khajer
khajer / json2ts_v1.go
Created May 17, 2018 09:41
json to typescript with golang
{{range .GetArrayProperties}}{{$d := SplitText . ":" }}{{$t := index $d 1}}{{$t := Replace (Replace $t "[" "" 2) "]" "" 2}} {{if or (eq $t "any") (or (eq $t "string") (eq $t "number") ) }}{{else}}
import { {{$t}} } from './{{ToLower $t}}'{{end}}{{end}}
export class {{.ClassName}} {
{{range .GetArrayProperties }} {{.}};
{{end}}
constructor(obj?: any){ {{range .GetArrayProperties }}{{$d := SplitText . ":" }}
this.{{index $d 0}} = obj && obj.{{index $d 0}} || null;{{end}}
}
}
package main
import (
"fmt"
"encoding/json"
"io/ioutil"
"strings"
"reflect"
"os"
"bytes"
@khajer
khajer / json2ts.py
Last active May 10, 2018 09:07
json to type script file
import json
from pprint import pprint
import datetime
import os
classCol = []
def writefile(filepath, txt):
print '[write file]: '+filepath