Skip to content

Instantly share code, notes, and snippets.

View PetrGlad's full-sized avatar
🚶‍♂️
.

Petr Gladkikh PetrGlad

🚶‍♂️
.
  • 17:24 (UTC +04:00)
View GitHub Profile
aws kms encrypt \
--key-id 'arn:aws:kms:eu-............' \
--plaintext fileb://input-filename \
--output text \
--query CiphertextBlob \
| base64 --decode > encrypted_filename
aws kms decrypt \
--ciphertext-blob fileb://encrypted_filename \
--query Plaintext \
fn art_slice(ln: &str, step: usize, idx: usize) -> &str {
let ofs = step * idx;
&ln[ofs..(ofs + step)]
}
fn ch_index(ch: char) -> usize {
let lookup_ch = if 'A' <= ch && ch <= 'Z' { ch } else { '?' };
"ABCDEFGHIJKLMNOPQRSTUVWXYZ?".chars().position(|x| x == lookup_ch).unwrap()
}
@PetrGlad
PetrGlad / trim-eol.sh
Created September 28, 2017 10:22
Trim line ends
#!/bin/bash
set -e -x
FILE=$1
BAK=$FILE.eol.bak
cp $FILE $BAK
cat $BAK | sed -r "s/[ \t]+$//" > $FILE
@PetrGlad
PetrGlad / base64.clj
Last active September 18, 2017 10:52
(require '[clojure.data.codec.base64 :as base64])
(defn str->base64 [^String in]
(-> in
(.getBytes UTF-8)
base64/encode
(String. UTF-8)))
(defn base64->str [^String in]
{:pre [in]}
(defn page-offset
"Return [next-group, next-offset] in sequence
given offset of first item in required range.
group-fn should not return nil."
[group-fn offset items]
{:pre [(<= 0 offset)]}
;; (Do not force too much items from source sequence here)
(let [split-pos offset]
(when (seq (drop split-pos items))
(->> (take (inc split-pos) items)
@PetrGlad
PetrGlad / Cargo.toml
Last active September 5, 2017 10:07
Rust lab
[package]
name = "rustlab"
version = "0.1.0"
authors = ["Petr Gladkikh <[email protected]>"]
[dependencies]
hyper = "0.9.11"
json = "*"
@PetrGlad
PetrGlad / netty-lab.clj
Last active May 12, 2017 17:00
netty lab clojure
(ns netty-lab.core
(require [clojure.data.json :as json])
(:import (io.netty.bootstrap Bootstrap)
(io.netty.channel.socket.nio NioSocketChannel)
(io.netty.channel.socket SocketChannel)
(java.net URL URI)
(io.netty.channel.nio NioEventLoopGroup)
(io.netty.channel ChannelOption ChannelInitializer ChannelPipeline SimpleChannelInboundHandler ChannelHandlerContext ChannelHandler Channel)
(io.netty.handler.ssl SslContextBuilder SslContext)
(io.netty.handler.ssl.util InsecureTrustManagerFactory)
@PetrGlad
PetrGlad / sock-conn-params.clj
Last active April 25, 2017 15:16
Socket and connection parameters in clj-http
(require '[clj-http.client :as client]
'[clojure.java.io :as java.io]
'[clj-http.conn-mgr :as conn-mgr]
'[clojure.java.shell :as shell])
(import org.apache.http.config.SocketConfig)
(import org.apache.http.config.ConnectionConfig)
(import java.io.InputStreamReader)
(import java.io.BufferedReader)
(def events-url "https://github.com")
(ns client.nakadi.lab
(require [manifold.deferred :as d]
[manifold.stream :as s]
[aleph.http :as http]
[clojure.core.async :as a]
[byte-streams :as bs]
[clojure.java.shell :as shell])
(:import (de.undercouch.actson JsonParser JsonEvent JsonFeeder)
(java.nio.charset StandardCharsets)))
@PetrGlad
PetrGlad / Cargo.toml
Created December 21, 2016 22:59
Rust prompt
[package]
name = "my-prompt"
version = "0.1.0"
authors = ["Petr Gladkikh <[email protected]>"]
[dependencies]
nix = "0.7.0"