Skip to content

Instantly share code, notes, and snippets.

@crtl
crtl / createStyledFC.tsx
Last active September 18, 2022 14:30
Function to create function component wrapped in styled component.
import {FC} from "react";
import styled from "styled-components";
/**
* Creates a function component and wraps it in styled-component to enable styling
* and generates a new displayName for returned component if provided component has one.
* Usage:
* ```
* const MyComponent = createStyledFC<MyProps>((props) => {})`
@crtl
crtl / MultiProvider.spec.tsx
Last active October 30, 2021 20:58
React MultiProvider
import {render} from "@testing-library/react";
import {MultiProvider, Provider} from "./multi-provider";
import {FC} from "react";
describe("<MultiProvider />", () => {
it("should render children with empty list of providers", () => {
const wrapper = render(<MultiProvider providers={[]}>
<h1>Child</h1>
</MultiProvider>);
@crtl
crtl / android-certificate-hash.md
Created October 28, 2020 09:50
Commands to get key file hash for android google and facebook social sign in.

Default android keystore password is android.

Facebook

keytool -exportcert -alias androiddebugkey -keystore "C:\Path\To\Keystore.keystore" | openssl sha1 -binary | openssl base64

Google:

gradlew signinReport
@crtl
crtl / media_query.js
Created July 5, 2019 09:48
Simple script to retrieve values based on mediaQueries. Can be adapted to work with any comparison conditions. Returns the first match only.
const WINDOW_HEIGHT = 1080;
const WINDOW_WIDTH = 1920;
/**
* Comparators check against WINDOW_WIDTH and WINDOW_HEIGHT vars, but can be any check you want.
* v refers to the value of the condition
**/
const comparators = {
width: (v) => WINDOW_WIDTH === v,
height: (v) => WINDOW_HEIGHT === v,
@crtl
crtl / array_path.php
Last active July 5, 2019 08:17
Function to access associative arrays by string paths
/**
* @param string $path The path of keys to access
* @param array $array The array to read from
* @param string $seperator The seperator to split the string by
* @return array|mixed|null The requested value or null
*/
function array_path(string $path, array $array, string $seperator = ".") {
$parts = explode($seperator, $path);
$current = $array;