Skip to content

Instantly share code, notes, and snippets.

View krasun's full-sized avatar
😉
I may be slow to respond.

Dmytro Krasun krasun

😉
I may be slow to respond.
View GitHub Profile
@krasun
krasun / custom.css
Last active June 24, 2022 15:14
custom.css
h1 {
color: red !important;
}
@krasun
krasun / main.go
Created June 1, 2022 15:48
Selenium WebDriver client example for Go
package main
import (
"fmt"
"os"
"github.com/tebeka/selenium"
)
func main() {
@krasun
krasun / main.go
Created June 1, 2022 15:46
chromedp screenshot example
func main() {
ctx, cancel := chromedp.NewContext(context.Background())
defer cancel()
var buf []byte
if err := chromedp.Run(ctx,
chromedp.Navigate(`https://example.com`),
chromedp.FullScreenshot(&buf, 95),
); err != nil {
log.Fatal(err)
@krasun
krasun / main.go
Created June 1, 2022 15:42
Playwright screenshot example
package main
import (
"log"
"github.com/playwright-community/playwright-go"
)
func main() {
pw, err := playwright.Run()
@krasun
krasun / main.go
Created June 1, 2022 15:39
ScreenshotOne API example
client, err := screenshots.NewClient("IVmt2ghj9TG_jQ", "Sxt94yAj9aQSgg")
if err != nil {
// ...
}
options := screenshots.NewTakeOptions("https://example.com").
Format("png").
FullPage(true).
DeviceScaleFactor(2).
BlockAds(true).
@krasun
krasun / example_from_linux_kernel_coding_style.c
Created September 17, 2021 08:28
Example from linux kernel coding style
// https://www.kernel.org/doc/html/v5.9/process/coding-style.html#centralized-exiting-of-functions
int fun(int a)
{
int result = 0;
char *buffer;
buffer = kmalloc(SIZE, GFP_KERNEL);
if (!buffer)
return -ENOMEM;
@krasun
krasun / trie_benchmark_results
Created March 7, 2021 13:36
Trie benchmark results for the story on Medium.
$ go test -bench=. -benchmem -benchtime=1000x
goos: darwin
goarch: amd64
op 0 allocs/op
BenchmarkRuneTrieInsert-8 1000 7196 ns/op 6984 B/op 129 allocs/op
BenchmarkRuneTrieContains-8 1000 517 ns/op 0 B/op 0 allocs/op
BenchmarkWordHashSetInsert-8 1000 1406 ns/op 1100 B/op 4 allocs/op
BenchmarkWordHashSetContains-8 1000 178 ns/op 0 B/op 0 allocs/op
PASS
@krasun
krasun / rune_trie_test.go
Created March 7, 2021 13:34
Benchmark function for the Trie for the story on Medium. Raw
func BenchmarkRuneTrieInsert(b *testing.B) {
var r bool
for i := 0; i < b.N; i++ {
t := NewRuneTrie()
for _, w := range words {
r = t.Insert(w)
}
}
benchmarkResult = r
@krasun
krasun / rune_trie.go
Created March 7, 2021 13:33
SearchByPrefix function for the Trie for the story on Medium. Raw
// Finds and returns words by prefix.
func (t *runeTrie) SearchByPrefix(prefix string) []string {
node, r := t.nodeByPrefix(prefix)
return search(node, r, []rune(prefix[:len(prefix)-1]))
}
func (t *runeTrie) nodeByPrefix(prefix string) (*runeNode, rune) {
current := t.root
var r rune
@krasun
krasun / rune_trie.go
Created March 7, 2021 13:32
Contains function for the Trie for the story on Medium. Raw
// Contains returns true if an exact match of the word is found, otherwise false.
func (t *runeTrie) Contains(word string) bool {
n, _ := t.nodeByPrefix(word)
return n != nil && n.last
}
func (t *runeTrie) nodeByPrefix(prefix string) (*runeNode, rune) {
current := t.root
var r rune