Skip to content

Instantly share code, notes, and snippets.

View pavermakov's full-sized avatar
🏠
Working from home

Pavel Ermakov pavermakov

🏠
Working from home
View GitHub Profile
@pavermakov
pavermakov / Conditionals.js
Created June 29, 2023 11:11
Conditional rendering in React
import React from "react";
import PropTypes from "prop-types";
const Then = ({ children }) => children;
Then.propTypes = {
children: PropTypes.node.isRequired
};
const If = ({ condition, children }) => {
@pavermakov
pavermakov / SnakeCase.swift
Last active May 6, 2021 09:20 — forked from dmsl1805/SnakeCase.swift
Camel case to snake case in Swift
extension String {
func camelCaseToSnakeCase() -> String {
let acronymPattern = "([A-Z]+)([A-Z][a-z]|[0-9])"
let normalPattern = "([a-z0-9])([A-Z])"
return self.processCamalCaseRegex(pattern: acronymPattern)?
.processCamalCaseRegex(pattern: normalPattern)?.lowercased() ?? self.lowercased()
}
fileprivate func processCamalCaseRegex(pattern: String) -> String? {
let regex = try? NSRegularExpression(pattern: pattern, options: [])
// Calling .blur() in the test renderer environment is not supported. Instead, mock out your
// components that use findNodeHandle with replacements that don't rely on the native environment.
jest.mock("TextInput", () => {
const RealComponent = require.requireActual("TextInput");
const React = require("react");
// eslint-disable-next-line react/prefer-stateless-function
class TextInput extends React.Component {
render() {
return React.createElement("TextInput", this.props, this.props.children);
import { Alert } from "react-native";
export default function() {
require("promise/setimmediate/rejection-tracking").enable({
allRejections: true,
onUnhandled: (id, error = {}) => {
let message;
let stack;
const stringValue = Object.prototype.toString.call(error);
import { useEffect } from "react";
function useDebouncedEffect(fn, deps, time) {
const dependencies = [...deps, fn, time]
useEffect(() => {
const timeout = setTimeout(fn, time);
return () => {
clearTimeout(timeout);
}
}, dependencies);
import { useCallback, useEffect, useRef } from 'react';
export function useMounted() {
const refMounted = useRef(false);
useEffect(() => {
refMounted.current = true;
return () => {
refMounted.current = false;
import React, { useEffect, useState } from "react";
import { Keyboard } from "react-native";
import { c } from "~/helpers/rootHelper";
const useKeyboard = () => {
const [indent, setIndent] = useState(0);
const isVisible = indent > 0;
const dismiss = () => {
Keyboard.dismiss();
import React, { useState, useEffect, memo } from "react";
import { View, TouchableOpacity, TouchableWithoutFeedback, Animated, StyleSheet } from "react-native";
import { IoniconsIcon } from "~/components/Icons/Ionicons";
import { c, t } from "~/helpers/rootHelper";
import { useKeyboard } from "~/hooks";
const END_HEIGHT = 120;
const START_HEIGHT = 160;
const START_WIDTH = c.DEVICE_WIDTH * 0.7;
@pavermakov
pavermakov / generateIcons.js
Created December 5, 2019 09:34
Generate icomoon icons
/* eslint-disable no-console */
const fs = require("fs");
const path = require("path");
const pipeline = require("icomoon-cli");
const ICONS_FOLDER = path.join(__dirname, "../icons");
const SELECTION_PATH = path.join(__dirname, "../../configs/humanforce-font-selection.json");
function getIcons() {
return fs.readdirSync(ICONS_FOLDER);
@pavermakov
pavermakov / SliderScreen.js
Created September 13, 2019 20:56
React native slider screen
import React from "react";
import { View, Animated, Text, StyleSheet, Button, Dimensions } from "react-native";
const DEVICE_WIDTH = Dimensions.get("window").width;
const SliderScreen = () => {
const animateRight = new Animated.Value(0);
const moveOver = () => {
Animated.timing(animateRight, {