Skip to content

Instantly share code, notes, and snippets.

View padurean's full-sized avatar

Valentin Padurean (Ogg) padurean

View GitHub Profile
@padurean
padurean / copy.go
Created May 12, 2020 12:47 — forked from r0l1/copy.go
Copy a directory tree (preserving permissions) in Go.
/* MIT License
*
* Copyright (c) 2017 Roland Singer [[email protected]]
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
package main
import (
"fmt"
"math"
)
func makeBatches(batchSize int, size int) [][]int {
batches := [][]int{}
nbBatches := int(math.Ceil(float64(size) / float64(batchSize)))
// Example of how third-party imports and multiple files can be used in Go playground
package main
import (
"fmt"
"github.com/common-nighthawk/go-figure"
"your.universe/worlds"
)
@padurean
padurean / ExecuteJavaScriptDynamically.scala
Created June 25, 2019 14:51
Execute JavaScript dynamically in Scala
def main(args: Array[String]): Unit = {
import javax.script.ScriptEngineManager
import scala.concurrent.duration._
import scala.concurrent.ExecutionContext.Implicits.global
val engine = new ScriptEngineManager().getEngineByMimeType("text/javascript")
// val script = "-1000 * %d" format 3
val endless = "(function foo() { foo(); })()"
val result = Await.result(Future(engine.eval(endless)), 3.millis)
println(result)
@padurean
padurean / multiple_ssh_setting.md
Created May 21, 2019 09:14 — forked from jexchan/multiple_ssh_setting.md
Multiple SSH keys for different github accounts

Multiple SSH Keys settings for different github account

create different public key

create different ssh key according the article Mac Set-Up Git

$ ssh-keygen -t rsa -C "[email protected]"
@padurean
padurean / .bashrc
Created April 7, 2019 14:57 — forked from vsouza/.bashrc
Golang setup in Mac OSX with HomeBrew. Set `GOPATH` and `GOROOT` variables in zshell, fish or bash.
# Set variables in .bashrc file
# don't forget to change your path correctly!
export GOPATH=$HOME/golang
export GOROOT=/usr/local/opt/go/libexec
export PATH=$PATH:$GOPATH/bin
export PATH=$PATH:$GOROOT/bin
@padurean
padurean / oneliners.js
Created April 2, 2019 10:48 — forked from mikowl/oneliners.js
👑 Awesome one-liners you might find useful while coding.
// By @coderitual
// https://twitter.com/coderitual/status/1112297299307384833
// Remove any duplicates from an array of primitives.
const unique = [...new Set(arr)]
// Sleep in async functions. Use: await sleep(2000).
const sleep = (ms) => (new Promise(resolve => setTimeout(resolve, ms)));
// Type this in your code to break chrome debugger in that line.
var str = 'class ಠ_ಠ extends Array {constructor(j = "a", ...c) {const q = (({u: e}) => {return { [`s${c}`]: Symbol(j) };})({});super(j, q, ...c);}}' +
'new Promise((f) => {const a = function* (){return "\u{20BB7}".match(/./u)[0].length === 2 || true;};for (let vre of a()) {' +
'const [uw, as, he, re] = [new Set(), new WeakSet(), new Map(), new WeakMap()];break;}f(new Proxy({}, {get: (han, h) => h in han ? han[h] ' +
': "42".repeat(0o10)}));}).then(bi => new ಠ_ಠ(bi.rd));';
try {
eval(str);
} catch(e) {
alert('Your browser does not support ES6!')
}
@padurean
padurean / round.go
Created October 22, 2018 19:10 — forked from davidvthecoder/round.go
Arggh Golang does not include a round function in the standard math package. So I wrote a quick one.
package main
import (
"log"
"math"
)
func Round(val float64, roundOn float64, places int ) (newVal float64) {
var round float64
pow := math.Pow(10, float64(places))
@padurean
padurean / curl-websocket.sh
Created October 2, 2018 11:27 — forked from htp/curl-websocket.sh
Test a WebSocket using curl.
curl --include \
--no-buffer \
--header "Connection: Upgrade" \
--header "Upgrade: websocket" \
--header "Host: example.com:80" \
--header "Origin: http://example.com:80" \
--header "Sec-WebSocket-Key: SGVsbG8sIHdvcmxkIQ==" \
--header "Sec-WebSocket-Version: 13" \
http://example.com:80/