Skip to content

Instantly share code, notes, and snippets.

@Mefistophell
Mefistophell / fileTransferLocation.ts
Created November 25, 2024 14:22
SFMC: Create/Update/Get FileTransferLocation GCP
import * as dotenv from 'dotenv'
dotenv.config()
const baseUrl = process.env.SFMC_BASE_URL as string
const tokenUrl = process.env.SFMC_TOKEN_URL_V2 as string
const clientId = process.env.SFMC_CLIENT_ID as string
const clientSecret = process.env.SFMC_CLIENT_SECRET as string
const credentials = {
@Mefistophell
Mefistophell / tasks_log.js
Created October 26, 2024 15:56
What will the log look like?
const promise = new Promise((resolve, reject) => {
console.log(1);
setTimeout(() => {
console.log("timerStart");
resolve("success");
console.log("timerEnd");
}, 0);
console.log(2);
});
@Mefistophell
Mefistophell / decorator-metadata.ts
Created July 24, 2024 11:32
ts-decorator-metadata
// Another way is to use const serializables = Symbol();
const serializables = new WeakMap<object, string[]>();
type Context =
| ClassAccessorDecoratorContext
| ClassGetterDecoratorContext
| ClassFieldDecoratorContext
;
function serialize(_target: any, context: Context): void {
@Mefistophell
Mefistophell / ts_useful_features.ts
Last active July 24, 2024 11:38
Typescript useful features
/**
NoInfer type
*/
function createStreetLight<C extends string>(
colors: C[],
defaultColor?: NoInfer<C>,
) {
// ...
}
createStreetLight(["red", "yellow", "green"], "red"); // OK
@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 <[email protected]>"]
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 <[email protected]>"]
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