Skip to content

Instantly share code, notes, and snippets.

View 0xc0d's full-sized avatar

Ali Josie 0xc0d

View GitHub Profile
@0xc0d
0xc0d / elastic_should.py
Created April 8, 2019 09:21
implementation of Elasticsearch should query in Python 3
def should(sample, conditions, min_should):
return True if len([item for item in conditions if item in sample]) >= min_should else False
@0xc0d
0xc0d / wordpress-api-media-upload.py
Created April 26, 2020 19:55
upload files using wordpress api and pplication-passwords plugin
#!/usr/bin/env python3
import requests
import json
import base64
user = 'USERNAME'
token = 'WWWW WWWW WWWW WWWW WWWW WWWW' # auth. token from application-passwords plugin
apiVer = 'v2'
@0xc0d
0xc0d / disable-gnome-tracker.sh
Created April 26, 2020 19:58
GNOME's tracker is a CPU and privacy hog.
#!/usr/bin/bash
echo -e "\nHidden=true\n" | sudo tee --append /etc/xdg/autostart/tracker-extract.desktop /etc/xdg/autostart/tracker-miner-apps.desktop /etc/xdg/autostart/tracker-miner-fs.desktop /etc/xdg/autostart/tracker-miner-user-guides.desktop /etc/xdg/autostart/tracker-store.desktop > /dev/null
gsettings set org.freedesktop.Tracker.Miner.Files crawling-interval -2 # Default: -1
gsettings set org.freedesktop.Tracker.Miner.Files enable-monitors false # Default: true
tracker reset --hard
@0xc0d
0xc0d / poolExample.go
Last active October 25, 2020 01:20
sync.Pool example
// A dummy struct
type Person struct {
Name string
}
// Initializing pool
var personPool = sync.Pool{
// New optionally specifies a function to generate
// a value when Get would otherwise return nil.
New: func() interface{} { return new(Person) },
@0xc0d
0xc0d / poolBench_test.go
Created October 24, 2020 17:29
Benchmark: sync.Pool vs simple allocation
func BenchmarkPool(b *testing.B) {
var p sync.Pool
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
p.Put(1)
p.Get()
}
})
}
@0xc0d
0xc0d / poolBench_test.go
Created October 24, 2020 18:40
sync.Pool Benchmark test
type Person struct {
Age int
}
var personPool = sync.Pool{
New: func() interface{} { return new(Person) },
}
func BenchmarkWithoutPool(b *testing.B) {
var p *Person
@0xc0d
0xc0d / Loop1.go
Last active October 25, 2020 03:25
Using reference to loop iterator variable
in := []int{1, 2, 3}
var out []*int
for _, v := range in {
out = append(out, &v)
}
fmt.Println("Values:", *out[0], *out[1], *out[2])
fmt.Println("Addresses:", out[0], out[1], out[2])
@0xc0d
0xc0d / Loop1_fix.go
Last active October 25, 2020 03:26
Using reference to loop iterator variable
in := []int{1, 2, 3}
var out []*int
for _, v := range in {
v := v
out = append(out, &v)
}
fmt.Println("Values:", *out[0], *out[1], *out[2])
fmt.Println("Addresses:", out[0], out[1], out[2])
@0xc0d
0xc0d / Loop2.go
Created October 25, 2020 03:28
Using goroutines on loop iterator variables
list := []int{1, 2, 3}
for _, v := range list {
go func() {
fmt.Printf("%d ", v)
}()
}
@0xc0d
0xc0d / Loop3.go
Created October 25, 2020 03:36
Call WaitGroup.Wait in loop
var wg sync.WaitGroup
wg.Add(len(tasks))
for _, t := range tasks {
go func(t *task) {
defer group.Done()
}(t)
// group.Wait()
}
group.Wait()