Skip to content

Instantly share code, notes, and snippets.

View nulltier's full-sized avatar
💭
on my way

Alexander Zonov nulltier

💭
on my way
  • Yandex
View GitHub Profile
@nulltier
nulltier / test-case-template.rs
Last active August 27, 2022 23:20
Rust template for the HackerRank tasks
// Enter your code here
use std::io;
#[derive(Debug)]
enum Case {
TwoLines(String, String)
}
fn readStdin() -> Vec<String> {
let mut result: Vec<String> = Vec::new();
@nulltier
nulltier / memoization.rs
Created February 8, 2022 22:35
Rust function with memoization
struct Memoize<'a, A, R> {
cache: std::collections::HashMap<A, R>,
func: &'a dyn Fn(A) -> R
}
impl<'a, A, R> Memoize<'a, A, R> where
A: Eq + std::hash::Hash + Copy + Clone,
R: Copy + Clone
{
fn from_func(func: &'a dyn Fn(A) -> R) -> Self {
@nulltier
nulltier / bash.md
Last active January 25, 2021 13:34
bash hints

Read CLI params from file

let say there is a file file origins.txt

main
secondary
backup

It can be used as shown below

@nulltier
nulltier / gits.md
Created January 19, 2021 06:42
git tricks

One-side diff

To show the changes in current branch which a not yet merged into target branch

> git diff target...HEAD

One-side log

@nulltier
nulltier / cli-ts-params.md
Created December 20, 2019 08:58
How to pass params to tsc from the text file

In console

$ tsc @cli-ts-params.txt ./path-to-file

OR

$ npx tsc @cli-ts-params.txt ./path-to-file

in cli-ts-params.txt

@nulltier
nulltier / create-union-type-from-array.ts
Last active July 20, 2019 22:17
TypeScript snippets
/*
The source of the solution
https://stackoverflow.com/questions/45251664/typescript-derive-union-type-from-tuple-array-values
*/
const listOfLetters = ['a', 'b', 'c'] as const;
type Letter = typeof list[number]; // 'a'|'b'|'c';
let itIsOk: Letter = 'a';
let itIsNot: Letter = 'd';
// how to run
// $ node ./detect-root-foders.js --root ../../../.. --ext jsp --until folderName
const glob = require('glob');
const ROOT = 'root';
const EXT = 'ext';
const UNTIL = 'until';
function getSettings (argv) {
return argv.reduce((params, arg, i, all) => {
@nulltier
nulltier / syncTimeMeasure.js
Created March 15, 2018 09:23
check performance for a sync code
function measureTime (fn) {
var start = performance.now();
fn();
return performance.now() - start;
}
@nulltier
nulltier / runFunctionIfSafe.js
Created February 7, 2017 21:48
a way to call something as function withput potential runtime exception if you don't sure that thing is the function
/**
*
* @param {Function} fn - Function that should be run
* @param {Object} thisLink - This link should be set if fucntion should be call in the context of some object
* @param {...*} args - Any amount of arguments to be passed to the called function
*
* @comment args presented in the definition only for readability, there is no any other reason since it redefined right after the call
*/
runFunctionIfSafe: function(fn, thisLink, args) {