Skip to content

Instantly share code, notes, and snippets.

View Voronar's full-sized avatar
💭
Let functions be functions!

Kirill Alexander Khalitov Voronar

💭
Let functions be functions!
View GitHub Profile
@Voronar
Voronar / lru_o1_safe.rs
Last active October 27, 2022 11:17
LRU O1
use std::{
cell::{Ref, RefCell},
collections::HashMap,
fmt::Debug,
rc::Rc,
};
/// LRU cache
struct LRU {
cache: HashMap<String, Rc<RefCell<ListNode>>>,
@Voronar
Voronar / plugins.lua
Last active February 27, 2022 19:26
nvim
-- Install packer
local install_path = vim.fn.stdpath 'data' .. '/site/pack/packer/start/packer.nvim'
if vim.fn.empty(vim.fn.glob(install_path)) > 0 then
vim.fn.execute('!git clone https://github.com/wbthomason/packer.nvim ' .. install_path)
end
vim.cmd [[
augroup Packer
autocmd!
#include <stdio.h>
#define TRY(a) ({ \
void* retval = NULL; \
if (a != NULL) { retval = a; } else { return retval; } \
retval; \
})
int sum(int _a, int _b) {
int a = TRY(_a);
@Voronar
Voronar / iter-lazy.js
Last active May 31, 2022 17:56
Java scripts
const gen_map = (f, g) => function* (arg) {
for (const x of g(arg))
yield f(x)
};
const gen_filter = (f, g) => function* (arg) {
for (const x of g(arg))
if (f(x))
yield x
};
@Voronar
Voronar / serde_custom.rs
Last active October 19, 2021 18:14
Rust notes
#[derive(Debug)]
pub struct Ar(Enum);
impl Serialize for Ar {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
serializer.serialize_newtype_struct("Ar", &self.0)
@Voronar
Voronar / withProps.tsx
Last active August 20, 2018 08:29
React + TypeScript = ❤️
type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
export function withProps<InjectingProps extends {}>(injectingProps: InjectingProps) {
return function <ExtendedProps extends InjectingProps>(SourceComponent: React.ComponentType<ExtendedProps>) {
type WithPropsHocProps = Omit<ExtendedProps, keyof InjectingProps>;
class WithPropsHoc extends React.PureComponent<WithPropsHocProps> {
render() {
return (
<SourceComponent {...this.props} {...injectingProps}>