Skip to content

Instantly share code, notes, and snippets.

View arekko's full-sized avatar
🎯
Focusing

Andrei Vasilev arekko

🎯
Focusing
  • Smartly.io
  • Helsinki, Finland
View GitHub Profile
@arekko
arekko / getObjectPath.ts
Created May 20, 2021 08:38
Get object path
import { type } from 'ramda';
const isObject = (value: unknown) => type(value) === 'Object';
export const getPath = (
obj: Record<string, any>,
key: string,
path: string[] = []
): string[] | undefined => {
if (!isObject(obj)) {
@arekko
arekko / OmitDeepBy.ts
Created May 10, 2021 12:19
Omit deep by
import { curry, type } from 'ramda';
const isObject = (obj: unknown) => type(obj) === 'Object';
const isArray = (obj: unknown) => Array.isArray(obj);
// @ts-ignore-next-line
const omitDeepBy = curry(
(pred: (key: string, value: unknown) => boolean, obj: any) => {
if (isArray(obj)) {
return obj.map(omitDeepBy(pred));
@arekko
arekko / rfc
Created March 2, 2020 12:33
Live template for WebStorm (React Functional Component typescript)
import React from 'react';
import {StyleSheet} from 'react-native';
interface $ComponentName$Props {}
const $ComponentName$:React.FC<$ComponentName$Props> = ({}) => {
return ($END$)
}
export default $ComponentName$;
@arekko
arekko / range.js
Created January 5, 2020 09:58
Range function implementation
function range(start, end) {
return [...Array(end)].keys().map(el => el + start)
}
@arekko
arekko / useLocalStorage.js
Created January 4, 2020 08:39
useLocalStorage hook implementation
export (key, initialValue) => {
const [value, setValue] = useState(() => {
return localStorage.getItem(key) || initialValue
})
useEffect(() => {
localStorage.setItem(key, value)
}, [value])
return [value, setValue]
@arekko
arekko / index.js
Last active July 24, 2019 11:39
React Native Text wrapping solution
<View style={{ flexDirection: "row" }}>
<Text numberOfLines={1} style={{ flex: 1, textAlign: "left" }}>
{title}
</Text>
<Text style={{ textAlign: "right" }}>{duration}</Text>
</View>;
@arekko
arekko / platform.js
Created July 16, 2019 19:52
React Native platform
import { Platform } from 'react-native';
const isWeb = Platform.OS === 'web';
const isNative = !isWeb;
const isIos = Platform.OS === 'ios';
const isAndroid = Platform.OS === 'android';
const isDesktop = isWeb && typeof matchMedia !== 'undefined' && matchMedia('(min-width: 768px)').matches;
const isMobile = !isDesktop;
@arekko
arekko / reverse.ts
Created March 5, 2019 14:57
Angular array reverse pipe
<div *ngFor="let item of listObservable | async | reverse">
{{item?.whatever}}
</div>
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'reverse'
})
export class ReversePipe implements PipeTransform {
// Async/Await requirements: Latest Chrome/FF browser or Babel: https://babeljs.io/docs/plugins/transform-async-to-generator/
// Fetch requirements: Latest Chrome/FF browser or Github fetch polyfill: https://github.com/github/fetch
// async function
async function fetchAsync () {
// await response of fetch call
let response = await fetch('https://api.github.com');
// only proceed once promise is resolved
let data = await response.json();
// only proceed once second promise is resolved
@arekko
arekko / gist:a914825bfe07bd6c7e2d89193e49285b
Created June 26, 2017 18:12
To install Royal-Gtk theme in Ubuntu
sudo add-apt-repository ppa:noobslab/themes
sudo apt-get update
sudo apt-get install royal-gtk-theme