Skip to content

Instantly share code, notes, and snippets.

View mykhailokrainik's full-sized avatar

Mykhailo Krainik mykhailokrainik

View GitHub Profile
@mykhailokrainik
mykhailokrainik / gdbinit
Created July 21, 2019 07:33
.gdbinit - A user-friendly gdb configuration file
# INSTALL INSTRUCTIONS: save as ~/.gdbinit
#
# DESCRIPTION: A user-friendly gdb configuration file.
#
# REVISION : 7.3 (16/04/2010)
#
# CONTRIBUTORS: mammon_, elaine, pusillus, mong, zhang le, l0kit,
# truthix the cyberpunk, fG!, gln
#
# FEEDBACK: https://www.reverse-engineering.net
@mykhailokrainik
mykhailokrainik / rocket_basic_auth.rs
Created May 1, 2019 14:44
Rust Rocket Basic Authorization
#[macro_use]
extern crate rocket;
use rocket::{Request, Outcome};
pub struct BasicAuth {
pub username: Option<String>,
pub password: Option<String>,
}
impl<'a, 'r> FromRequest<'a, 'r> for BasicAuth {
@mykhailokrainik
mykhailokrainik / playground.rs
Created April 10, 2019 09:32 — forked from rust-play/playground.rs
Code shared from the Rust Playground
#![feature(try_trait)]
enum InnerError {
NoneError,
}
trait CustomError: std::error::Error {
fn description(&self) -> &str;
fn cause(&self) -> Option<&std::error::Error> {
None
}
@mykhailokrainik
mykhailokrainik / state_machine.rs
Last active October 2, 2019 14:26
State Machine in Rust implementation
//# [EN] https://hoverbear.org/2016/10/12/rust-state-machine-pattern/
//# [RU] https://habr.com/ru/post/324382/
fn main() {
// The `<StateA>` is implied here. We don't need to add type annotations!
let in_state_a = StateMachine::new("Blah blah blah".into());
// This is okay here. But later once we've changed state it won't work anymore.
in_state_a.some_unrelated_value;
println!("Starting Value: {}", in_state_a.state.start_value);
@mykhailokrainik
mykhailokrainik / default_params.rs
Created January 9, 2019 21:52
Rust Default::default()
use std::fmt;
struct ApiUrl<'a> {
host: &'a str,
port: &'a str,
path: &'a str,
}
impl Default for ApiUrl<'_> {
fn default() -> Self {
# Crystal cfib.cr
def fib(n)
if n <= 2
1
else
fib(n - 1) + fib(n - 2)
end
end
puts fib(42)
$ crystal build cfib.cr --release
extern crate hyper;
extern crate futures;
extern crate unicase;
use hyper::Post;
use hyper::header::{Headers, AccessControlAllowOrigin, AccessControlAllowHeaders};
use hyper::server::{Http, Request, Response, Service};
use futures::Stream;
use futures::future::*;
use unicase::Ascii;
@mykhailokrainik
mykhailokrainik / https_multipart_upload.rs
Created November 1, 2018 15:04 — forked from veer66/https_multipart_upload.rs
Upload file as multipart via https in Rust
extern crate hyper;
extern crate multipart;
extern crate hyper_native_tls;
use hyper::Client;
use hyper::net::HttpsConnector;
use hyper_native_tls::NativeTlsClient;
use multipart::client::lazy::Multipart;
use std::io::Read;
@mykhailokrainik
mykhailokrainik / generators.rs
Last active November 1, 2018 12:33 — forked from rust-play/playground.rs
Rust Generators
#![allow(unused)]
#![feature(generators, generator_trait)]
use std::ops::{Generator, GeneratorState};
fn main() {
let mut generator = || {
yield 1;
return "foo"
};
@mykhailokrainik
mykhailokrainik / add_column_as_array.sql
Created October 23, 2018 13:42
PG add not null values column with array type
ALTER TABLE users
ADD COLUMN positions INTEGER[] NULL;
UPDATE users SET positions = '{}';
ALTER TABLE users
ALTER COLUMN positions SET NOT NULL;
-- +-----------------+--------------------------+----------------------------------------------------------+
-- | Column | Type | Modifiers |