Skip to content

Instantly share code, notes, and snippets.

View yakuter's full-sized avatar
💭
Working #golang @binalyze

Erhan Yakut yakuter

💭
Working #golang @binalyze
View GitHub Profile
@yakuter
yakuter / args.go
Last active February 7, 2022 06:18
A nice args (arguments) interface for golang projects
type Args interface {
// Get returns the nth argument, or else a blank string
Get(n int) string
// First returns the first argument, or else a blank string
First() string
// Tail returns the rest of the arguments (not the first one)
// or else an empty string slice
Tail() []string
// Len returns the length of the wrapped slice
Len() int
@yakuter
yakuter / cancel-io-copy.go
Created April 25, 2021 19:25
IO Copy cancellation
// Source: https://ixday.github.io/post/golang-cancel-copy/
import (
"io"
"context"
)
// here is some syntaxic sugar inspired by the Tomas Senart's video,
// it allows me to inline the Reader interface
type readerFunc func(p []byte) (n int, err error)
@yakuter
yakuter / geekday.go
Created April 4, 2021 13:21
Go parametreleri dosyaya yazan uygulama
package main
import (
"log"
"os"
)
func main() {
file, err := os.OpenFile("geekday.txt", os.O_CREATE|os.O_APPEND|os.O_RDWR, 0644)
if err != nil {
@yakuter
yakuter / convert.go
Created July 28, 2020 00:07
String Byte Conversion Without Memory Allocation
// b2s converts byte slice to a string without memory allocation.
// See https://groups.google.com/forum/#!msg/Golang-Nuts/ENgbUzYvCuU/90yGx7GUAgAJ .
//
// Note it may break if string and/or slice header will change
// in the future go versions.
func b2s(b []byte) string {
/* #nosec G103 */
return *(*string)(unsafe.Pointer(&b))
}
@yakuter
yakuter / CryptoJS.js
Last active April 14, 2024 20:51
CryptoJS AES Example
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.2/components/core-min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.2/components/sha256.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.2/components/enc-base64.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.2/rollups/aes.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.2/rollups/pbkdf2.js"></script>
@yakuter
yakuter / PBKDF2-js-golang.go
Created June 7, 2020 21:04
PBKDF2 JS and Golang
import CryptoJS from 'crypto-js'
export default {
pbkdf2Encrypt(value) {
var salt = 'asdfghjkl'
const cipher = CryptoJS.PBKDF2(value, salt, {
keySize: 256 / 8,
iterations: 10000,
hasher: CryptoJS.algo.SHA256
@yakuter
yakuter / postgres.md
Last active August 19, 2020 05:08
Usefull Postgresql Commands

Usefull Postgresql Commands

Show databases \l

Choose database \c passwall

List tables \dt

@yakuter
yakuter / chrome.js
Created April 21, 2020 15:39
chrome tab
document.addEventListener('DOMContentLoaded', function() {
var copyTextareaBtn = document.querySelector('#kopyala');
copyTextareaBtn.addEventListener('click', function(event) {
var copyTextarea = document.querySelector('#veri');
copyTextarea.focus();
copyTextarea.select();
try {
@yakuter
yakuter / fluentd.md
Created April 16, 2020 22:29
Fluentd

sudo launchctl load /Library/LaunchDaemons/td-agent.plist sudo launchctl unload /Library/LaunchDaemons/td-agent.plist

@yakuter
yakuter / useful-docker-commands.go
Last active February 26, 2021 08:46
Useful Docker Commands
//GENERAL
docker ps
docker ps -a
docker image list
docker stop <containerid>
docker rm <containerid>
docker rmi <imageid>
// LIST AND DELETE ALL CONTAINERS
docker container ls