Skip to content

Instantly share code, notes, and snippets.

@btoo
btoo / usePrevious.ts
Last active September 11, 2022 15:30
typescript type-safe version of usePrevious taken directly from the react docs https://reactjs.org/docs/hooks-faq.html#how-to-get-the-previous-props-or-state
import { useRef, useEffect } from 'react';
/**
* a type-safe version of the `usePrevious` hook described here:
* @see {@link https://reactjs.org/docs/hooks-faq.html#how-to-get-the-previous-props-or-state}
*/
export function usePrevious<T>(
value: T,
): ReturnType<typeof useRef<T>>['current'] {
const ref = useRef<T>();
@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>
}
}
@karol-majewski
karol-majewski / flatMap.ts
Last active February 2, 2023 13:48
The simplest flatMap implementation in TypeScript
export function flatMap<T, U>(array: T[], callbackfn: (value: T, index: number, array: T[]) => U[]): U[] {
return Array.prototype.concat(...array.map(callbackfn));
}
@d1i1m1o1n
d1i1m1o1n / text
Created October 6, 2016 12:16
How to disable auto-save in phpstorm
How to disable auto-save:
Go to File > Settings (Ctrl+Alt+S).
Go to Appearance & Behavior > System Settings.
Make sure the two are unchecked:
Save files on frame deactivation
Save files automatically if application is idle for x sec.
Go to Editor > General > Editor Tabs
Put a checkmark on "Mark modified files with asterisk"
(Optional but recommended) Under "Tab Closing Policy", select "Close non-modified files first". You may also want to increase the number of allowed tabs.
Click Apply > OK.
@lolzballs
lolzballs / HelloWorld.java
Created March 22, 2015 00:21
Hello World Enterprise Edition
import java.io.FileDescriptor;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
public class HelloWorld{
private static HelloWorld instance;
public static void main(String[] args){
instantiateHelloWorldMainClassAndRun();