Skip to content

Instantly share code, notes, and snippets.

View pramendra's full-sized avatar
💭
🤓

Pramendra Gupta pramendra

💭
🤓
View GitHub Profile
const premLeague = R.equals("Prem League");
const premLeagueInArray = R.any(premLeague);
const categories = R.path(["categories"]);
const isPremLeagueInArray = R.pipe(categories, premLeagueInArray);
const teams = [
{ name: "Liverpool", id: "1", categories: ["Prem League"] },
{ name: "Man Utd", id: "2", categories: ["Blue Square"] },
{ name: "Sheff Utd", id: "2", categories: ["Prem League"] },
];
@pramendra
pramendra / getFirstThreeFromArray
Created June 19, 2020 10:26
getFirstThreeFromArray using Ramda
// const { compose, defaultTo, equals, map, slice } = R;
const slice2DArray = (slice) => compose(defaultTo([]), map(slice));
const getFirstThreeFromArray = slice2DArray(slice(0, 3));
const input_data = [
["a", "b", "c", "d"],
["a", "b", "c", "d"],
["a", "b", "c", "d"],
["a", "b"],
["x", "y", "z", "z1"],

Styled component use case

Styled component as standard react component

avoid creating middleware react component

before

const StyledIcon = styled(Icon)``; export const HomeIcon = () => ;

after

export const CameraIcon = styled(Icon)``;

Props and cons of using create element

Overview:

  • parent has multiple items and able to sent call back to parent
  • Parent should be able to accept any type of component

with render props

https://jsbin.com/xamoyuxabi/3/edit?js,output

Disadvantages

  • get children and map it as children may have array (which may break)
  • accordion is tightly couple with renderItem making it almost impossible to reuse
[
{
"id": 1517441231,
"price": 31,
"image_src":
"https://static-mercariapp-com.akamaized.net/thumb/photos/m62013065965_1.jpg?1517441231",
"name": "BH Cosmetics- Wild & Alluring Palette"
},
{
"id": 1517540022,
[
{
"id": 1517441231,
"price": 31,
"image_src":
"https://static-mercariapp-com.akamaized.net/thumb/photos/m62013065965_1.jpg?1517441231",
"name": "BH Cosmetics- Wild & Alluring Palette"
},
{
"id": 1517540022,
<?php
$picker = function ($item) {
return $item;
};
function arrayImplodeIntoString(array $list, $picker, string $separator = ',') :string
{
$first_element = $list[0]??null;
if ($first_element) {
$remaining_list = array_slice($list, 1);
@pramendra
pramendra / Array To Chunks
Created June 7, 2017 09:03
Convert Array to Array chunks - ES6
const arrayToChunks = (arrayData, length = 2) => {
const ImmutateArrayData = [...arrayData];
let chunks = [];
while(([...data] = ImmutateArrayData.splice(0, length)).length !== 0){
chunks.push(data);
}
return chunks;
}
const ab = [1, 2, 3, 4, 5, 6, 7];
import React, { PropTypes } from 'react';
import { View } from 'react-native';
const Renderer = (props) => {
if (props.isRefreshed === false) return props.loadingComponent;
return (
<View style={{ flex: 1 }}>
{(props.isRefreshed && props.isZeroState === true)
? props.zeroStateComponent : props.children}
</View>
@pramendra
pramendra / gist:567b894a2ee0fa42487d
Created October 8, 2014 06:06
Client side Javascript Error Tracking using GTM (google analytics)
/**
* Track JS error details in Universal Analytics
*/
function trackJavaScriptError(e) {
var errMsg = e.message;
var errSrc = e.filename + ': ' + e.lineno;
ga('send', 'event', 'JavaScript Error', errMsg, errSrc, { 'nonInteraction': 1 });
}