Skip to content

Instantly share code, notes, and snippets.

@Mefistophell
Mefistophell / password.rs
Last active November 16, 2022 11:58
Password regexp
// PCI DSS standard password requirement
fn main() {
let regexp = "/^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$%^&*-]).{8,20}$/";
}
@Mefistophell
Mefistophell / lib.rs
Created October 3, 2020 16:37
Node.js + Rust
extern crate libc;
use libc::c_char;
use std::ffi::CString;
use std::ffi::CStr;
#[no_mangle]
#[allow(clippy::not_unsafe_ptr_arg_deref)]
// Concatenates an input string with an existing string literal
pub extern "C" fn hello(input: *const c_char) -> *const c_char {
@Mefistophell
Mefistophell / index.js
Last active October 19, 2023 15:33
Node.js + Rust
const ffi = require('ffi-napi')
const ref = require('ref-napi')
const StructType = require('ref-struct-napi')
const ArrayType = require('ref-array-napi')
// Initialize the C-like array
const OutputArrayType = ArrayType(ref.types.int64, 2)
// Initialize the C-like data struct
const OutputType = StructType({
@Mefistophell
Mefistophell / Cargo.toml
Created August 13, 2020 11:29
[Rust ⭤ Node.js cloud function] communication via strings
[package]
name = "embed"
version = "0.1.0"
authors = ["Yevhen Blotskyi <yebl@boozt.com>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
libc = "*"
@Mefistophell
Mefistophell / Cargo.toml
Last active July 28, 2020 10:43
Rust "Find exam" project configuration
[package]
name = "find_exam"
version = "0.1.0"
authors = ["Ewen Blotskyi <lovecraft.crowley@gmail.com>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
serde = { version = "1.0", features = ["derive"] }
@Mefistophell
Mefistophell / README.MD
Last active January 30, 2020 15:01
Read a large file without blocking the event loop

To test:

Set the path to a large file in worker.js

Run: node index.js

Then you can run this bash: while true; do date && curl -m 5 http://localhost:3000/ && echo; sleep 1; done

and open a browser http://127.0.0.1:3000/read

@Mefistophell
Mefistophell / RUST.MD
Last active April 16, 2024 17:32
How to Compile a Rust Program on Mac for Windows

Question: I want to compile my Rust source code for the Windows platform but I use macOS.

Solution:

  1. Install target mingw-w64: brew install mingw-w64
  2. Add target to rustup: rustup target add x86_64-pc-windows-gnu
  3. Create .cargo/config
  4. Add the instructions below to .cargo/config
[target.x86_64-pc-windows-gnu]
@Mefistophell
Mefistophell / index.js
Created November 4, 2018 13:27
Apollo-GraphQL-Books
const { ApolloServer, gql } = require('apollo-server');
// Type definitions define the "shape" of your data and specify
// which ways the data can be fetched from the GraphQL server.
const typeDefs = gql`
# Comments in GraphQL are defined with the hash (#) symbol.
# This "Book" type can be used in other type declarations.
type Book {
title: String!
author: String
@Mefistophell
Mefistophell / tokens.md
Created October 8, 2018 13:14
Про токены, JSON Web Tokens (JWT), аутентификацию и авторизацию. Token-Based Authentication

Про токены, JSON Web Tokens (JWT), аутентификацию и авторизацию. Token-Based Authentication

Preconditions:

В данной заметке рассматривается работа JWT с симметичным алгоритмом шифрования (HS256/HS384/HS512)

Основы:

Аутентификация - это процесс проверки учётных данных пользователя (логин/пароль). Проверка подлинности пользователя путём сравнения введённого им логина/пароля с логином/паролем, сохранённым в базе данных пользователей.

Авторизация - это проверка прав пользователя на доступ к определенным ресурсам.

@Mefistophell
Mefistophell / tokens.md
Created October 8, 2018 13:13 — forked from zmts/tokens.md
Про токены, JSON Web Tokens (JWT), аутентификацию и авторизацию. Token-Based Authentication

Про токены, JSON Web Tokens (JWT), аутентификацию и авторизацию. Token-Based Authentication

Preconditions:

В данной заметке рассматривается работа JWT с симметичным алгоритмом шифрования (HS256/HS384/HS512)

Основы:

Аутентификация(authentication, от греч. αὐθεντικός [authentikos] – реальный, подлинный; от αὐθέντης [authentes] – автор) - это процесс проверки учётных данных пользователя (логин/пароль). Проверка подлинности пользователя путём сравнения введённого им логина/пароля с логином/паролем, сохранённым в базе данных пользователей.

Авторизация(authorization — разрешение, уполномочивание) - это проверка прав пользователя на доступ к определенным ресурсам.