Skip to content

Instantly share code, notes, and snippets.

View mannyanebi's full-sized avatar
🔥
Stay Awesome!

Emmanuel Anebi mannyanebi

🔥
Stay Awesome!
View GitHub Profile
@mannyanebi
mannyanebi / object_to_dict_recursive.py
Created August 24, 2023 23:25 — forked from sairamkrish/object_to_dict_recursive.py
Python object to dictionary - recursively convert
'''
Generic object to dict converter. Recursively convert.
Useful for testing and asserting objects with expectation.
'''
def todict(obj, classkey=None):
if isinstance(obj, dict):
data = {}
for (k, v) in obj.items():
data[k] = todict(v, classkey)
@mannyanebi
mannyanebi / prod_pipeline.yaml
Created June 30, 2023 15:14
Sample Prod CI Pipeline
name: Prod Headless-Typescript
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
build-test-job:
@mannyanebi
mannyanebi / dev_pipeline.yaml
Created June 30, 2023 15:13
Dev CI Pipeline Yaml
name: Dev Headless-Typescript
on:
push:
branches: [dev]
pull_request:
branches: [dev]
jobs:
build-test-job:
@mannyanebi
mannyanebi / deep_transform.py
Created December 17, 2022 20:35 — forked from martin056/deep_transform.py
Deep snake_case and camelCase transformations
import re
from typing import Dict, Callable, Optional
def to_camel_case(snake_case_str: str) -> str:
"""
Transforms snake_case to camelCase
"""
components = snake_case_str.split('_')
titled_components = ''.join(x.title() for x in components[1:])
@mannyanebi
mannyanebi / type-extract-from-array.ts
Last active May 12, 2022 18:22
How to extract a type from an array
// This is possible with Typescript 2.8+. You can declare an Unpacked<T> type as follows:
type Unpacked<T> = T extends (infer U)[] ? U : T;
type InnerCacheType = Unpacked<CacheType>; // Event | User
// This is a condensed definition of the Unpacked type given in the documentation.
// https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.html
type Unpacked<T> = T extends Array<infer U> ? U : T extends ReadonlyArray<infer U> ? U : T;
@mannyanebi
mannyanebi / react-cloneElement-children.tsx
Last active April 29, 2022 16:56
How to use React.cloneElement and specify types for children prop
{React.cloneElement(children as React.ReactElement<any>, {toggleOpenSidebar})}
{React.Children.map(children, (child => React.cloneElement(child as React.ReactElement<any>, {toggleOpenSidebar})))}
@mannyanebi
mannyanebi / nvmCommands.js
Created April 23, 2022 20:18 — forked from chranderson/nvmCommands.js
Useful NVM commands
// check version
node -v || node --version
// list installed versions of node (via nvm)
nvm ls
// install specific version of node
nvm install 6.9.2
// set default version of node
@mannyanebi
mannyanebi / graphene-connection.py
Created March 17, 2022 12:36
A sample of how to create your own custom graphene connection
class Member(DjangoObjectType):
class Meta:
model = models.Member
filter_fields = []
interfaces = (graphene.Node, )
contacts = graphene.ConnectionField('api.graphql.Contact')
def resolve_contacts(instance, info):
info.context.root = instance
@mannyanebi
mannyanebi / get_object_generic_class_based_view.py
Created February 9, 2022 17:43
You can access the URL kwargs with self.kwargs, so for example
# You can access the URL kwargs with self.kwargs, so for example:
def get_object(self, queryset=None):
return Employee.objects.get(
user=self.request.user,
pk=self.kwargs['id']
)
Browserslist: caniuse-lite is outdated. Please run:
npx browserslist@latest --update-db
Why you should do it regularly:
https://github.com/browserslist/browserslist#browsers-data-updating