Skip to content

Instantly share code, notes, and snippets.

Artem ArtemGr

  • Bizlink
Block or report user

Report or block ArtemGr

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@ArtemGr
ArtemGr / Cargo.toml
Last active Jan 28, 2018
Inline hex escape
View Cargo.toml
[package]
name = "hex"
version = "0.1.0"
[dependencies]
fomat-macros = "*"
@ArtemGr
ArtemGr / map_bench.rs
Last active Apr 3, 2017
small strings map benchmark
View map_bench.rs
// [build] cd .. && cargo bench
#![feature(asm, test)]
extern crate inlinable_string;
extern crate ordermap;
extern crate seahash;
extern crate test;
use inlinable_string::{InlinableString, StringExt};
@ArtemGr
ArtemGr / verify.rs
Created Feb 25, 2017
Using OpenSSL to verify the JWT RS256 signature in Rust.
View verify.rs
use openssl::sign::Verifier;
use openssl::rsa::Rsa;
use openssl::pkey::PKey;
use openssl::hash::MessageDigest;
use serde_json::{self as json, Value as Json};
pub fn firebase_id_token (headers: BTreeMap<&str, &str>, mut stream: &mut BufStream<TcpStream>) -> Result<(), String> {
#[derive(Deserialize, Debug)]
struct Post {firebase_id_token: String}
@ArtemGr
ArtemGr / cmake.rs
Last active Oct 7, 2016
cmake.rs - Use a proper generator under CLion
View cmake.rs
// [build] rustc -O cmake.rs
// cf. https://youtrack.jetbrains.com/issue/CPP-188#comment=27-899992
use std::env::args;
use std::fs::OpenOptions;
use std::io::Write;
use std::path::Path;
use std::process::Command;
fn main() {
View libpg_and_libevent.cpp
// Asynchronous PostgreSQL INSERT.
glim::NsecTimer timer;
std::unique_ptr<PGconn, void(*)(PGconn*)> pg (PQconnectStart (pcs.c_str()), PQfinish);
if (pg.get() == nullptr || PQstatus (pg.get()) == CONNECTION_BAD) GTHROW ("!PQconnectStart");
int sock = PQsocket (pg.get());
auto evBase = EvServ::instance()->evbase();
event_callback_fn cbcoroInvokeFromCallback = [](evutil_socket_t, short, void* cbcoro) {((CBCoro*) cbcoro)->invokeFromCallback();};
std::unique_ptr<struct event, void(*)(struct event*)> evRead (event_new (evBase.get(), sock, EV_READ, cbcoroInvokeFromCallback, cbcoro), event_free);
@ArtemGr
ArtemGr / take_until_parse_s.rs
Last active Aug 24, 2016
Nom tag that implements the /(?x) (.*?) (remainder)/ pattern.
View take_until_parse_s.rs
/// Implements the /(?x) (.*?) (remainder)/ pattern:
/// looks for remainder first, then returns a tuple with the prefix and the remainder.
/// Discussion: https://www.reddit.com/r/rust/comments/4yokxd/crash_course_into_nom_kind_of_question/
macro_rules! take_until_parse_s (
($i: expr, $submac: ident! ($($args:tt)*)) => ({
let input = $i as &str;
let mut ret = IResult::Error (nom::Err::Position (nom::ErrorKind::Custom (0), input));
for (pos, _) in $i.char_indices() {
match $submac! (&input[pos..], $($args)*) {
IResult::Done (i,o) => {ret = IResult::Done (i, (&input[0..pos], o)); break}, // Found the remainder!
@ArtemGr
ArtemGr / simple-create-process.rs
Created Aug 12, 2016
BashOnWindows issue 861 - workaround
View simple-create-process.rs
extern crate kernel32;
extern crate winapi;
use kernel32::{CreateProcessA, WaitForSingleObject, CloseHandle};
use winapi::{LPCSTR, LPSTR, LPSECURITY_ATTRIBUTES, BOOL, DWORD, LPVOID, LPSTARTUPINFOA,
LPPROCESS_INFORMATION, PROCESS_INFORMATION, STARTUPINFOA};
use winapi::winbase::INFINITE;
use std::ptr::null_mut;
use std::mem::size_of;
fn main() {
@ArtemGr
ArtemGr / output.txt
Created Aug 12, 2016
BashOnWindows issue 861
View output.txt
C:\Users\Artemciy\Downloads>test_bash_bat.exe
Output {
status: ExitStatus(ExitStatus(0)),
stdout: "\r\nC:\\Users\\Artemciy\\Downloads>echo foo \r\nfoo\r\n\r\nC:\\Users\\Artemciy\\Downloads>bash --help \r\n\u{1e}\u{4}H\u{4}8\u{4}1\u{4}:\u{4}0\u{4}:\u{0} \u{0}0\u{0}x\u{0}8\u{0}0\u{0}0\u{0}7\u{0}0\u{0}0\u{0}0\u{0}6\u{0}\r\u{0}\r\u{0}\n\u{0}\r\nC:\\Users\\Artemciy\\Downloads>echo bar \r\nbar\r\n",
stderr: "" }
View bench_iterators.rs
// [build] rustc -O bench_iterators.rs --test
// [build] ./bench_iterators.exe --bench
#![feature(test)]
extern crate test;
use test::{Bencher, black_box};
#[bench]
fn construction_only(b: &mut Bencher) {
let foo = String::from("foo");
@ArtemGr
ArtemGr / Keys.java
Last active Feb 9, 2016
Merge experiments
View Keys.java
package test;
import java.util.ArrayList;
import java.util.Random;
public class Keys implements Comparable<Keys> {
private final int[] keys;
public Keys(final int[] keys) {
this.keys = keys;
You can’t perform that action at this time.