Skip to content

Instantly share code, notes, and snippets.

Hey

testGistEditor(‘How is it doing?)
@Nachasic
Nachasic / react-serialize.spec.tsx
Last active February 1, 2024 16:34
Serialize react to JSON and de-serialize it back with TypeScript
import * as React from 'react';
import { mount } from 'enzyme';
import { serialize, deserialize } from './react-seritalize';
class CustomComponent extends React.Component<any, any> {
render () {
return <div className="CustomComponent" >{this.props.children}</div>
}
}
@Nachasic
Nachasic / Decorator.tsx
Created October 19, 2018 13:54
DraftJS — get decorator's own selection range
/**
* This is a workaround for the following issue:
* https://github.com/facebook/draft-js/issues/1394
**/
type DecoratorProps = {
// draft-js provides decorators with detoratedText property
decoratedText: string;
}
@Nachasic
Nachasic / generics.ts
Last active February 10, 2019 18:36
Exemplary explanation of interfaces and generics
interface BarkAndWiggle {
bark: () => void;
wiggle: () => void;
};
class Pitbull implements BarkAndWiggle {
public bark() {
console.log('bark');
}
@Nachasic
Nachasic / frac.spec.ts
Created July 18, 2019 16:07
Alternative to `Math.frac()` in Javascript
// testing using Jest
import { frac } from './frac';
describe('Math frac tests', () => {
it('should be defined', () => {
expect(frac).toBeDefined();
});
it('should accurately calculate fraction of a number', () => {
expect( frac(-3.1234) ).toEqual( -0.1234 );
@Nachasic
Nachasic / macro.rs
Created January 24, 2020 14:39
Color macro for raylib in Rust
use raylib::prelude::*;
#[allow(unused_macros)]
macro_rules! color {
(# $color_hex:expr) => {{
let color = i32::from_str_radix(stringify!($color_hex), 16).unwrap();
let b = color % 0x100;
let g = (color - b) / 0x100 % 0x100;
let r = (color - g) / 0x10000;
@Nachasic
Nachasic / tough.kt
Created April 14, 2020 19:33
Zhavoronok tough problems
fun <T> assert (exerciseName: String, fnResult: T, expectedResult: T) {
if (fnResult == expectedResult) {
println(exerciseName + "| checks out, GOOD JOB\n\n");
} else {
println(exerciseName + "| something's wrong: result \n (" + fnResult + ") is not equal to expected result \n (" + expectedResult + ")\n\n" )
};
};
/** Problem #1 - List Basics
* 1) Function is provided with a list of numbers;
@Nachasic
Nachasic / init.vim
Created August 5, 2020 16:42
Neovim configuratiob
call plug#begin(stdpath('data') . './plugged')
" Plugin Section
Plug 'dracula/vim'
Plug 'kristijanhusak/vim-hybrid-material'
Plug 'preservim/nerdtree'
Plug 'ryanoasis/vim-devicons'
Plug 'neoclide/coc.nvim', {'branch': 'release'}
Plug 'junegunn/fzf', {'dir': '~/.fzf','do': './install --all'}
Plug 'junegunn/fzf.vim' " needed for previews