Skip to content

Instantly share code, notes, and snippets.

View jottenlips's full-sized avatar
:octocat:

John Ottenlips Franke jottenlips

:octocat:
View GitHub Profile
@jottenlips
jottenlips / makeStylesMUI5React18.ts
Last active March 22, 2024 15:03
easier replacement for the deprecated mui-styles library
// this code is to make it easier to replace the deprecated mui-styles library, almost drop in
import { SxProps } from '@mui/material'
import { useMemo } from 'react'
type TStylesFunction = (
props?: any,
) => Record<string, React.CSSProperties | SxProps>
type TStyles = Record<string, React.CSSProperties | SxProps>
export const makeStylesHook = (styles: TStylesFunction | TStyles) => {
export const parseSignedFacebookRequest = (signed_request) => {
const [encoded_sig, payload] = signed_request.split(".");
const secret = 'appsecret'; // Use your app secret here
// decode the data
const sig = base64Decode(encoded_sig);
const data = JSON.parse(base64Decode(payload));
// confirm the signature
@jottenlips
jottenlips / functional_helpers.ts
Created January 27, 2023 17:07
Compose and pipe functions
export const compose = (...functions: Array<Function>) => (initial: any) => functions.reduce((acc, cur) => cur(acc), initial)
export const pipe = (...functions: Array<Function>) => (initial: any) => functions.reverse().reduce((acc, cur) => cur(acc), initial)
@jottenlips
jottenlips / configgit.sh
Created August 17, 2022 18:21
Default git push behavior so you don't have to git push --set-upstream origin feature/your-branch
git config --global push.default current
@jottenlips
jottenlips / xssharing_middleware.py
Last active April 14, 2022 01:44
Allow django templates to receive data from a popup that calls window.opener.postMessage
from django.conf import settings
XS_SHARING_ALLOWED_ORIGINS = getattr(settings, "XS_SHARING_ALLOWED_ORIGINS", '')
XS_SHARING_ALLOWED_METHODS = getattr(settings, "XS_SHARING_ALLOWED_METHODS",
['POST', 'GET', 'OPTIONS', 'PUT'])
def xssharing_middleware(get_response):
def middleware(request):
response = get_response(request)
if response.has_header('Access-Control-Allow-Origin'):
@jottenlips
jottenlips / Haul With Expo React Native CRNA
Last active February 10, 2021 16:54
haul with expo react native crna
https://github.com/callstack/haul/issues/463#issuecomment-408922287
@jottenlips
jottenlips / dna_cleaning_script.sh
Last active January 20, 2021 00:08
Script for Michael
#!/bin/bash
lowercase_remove_dash () {
sed -e 's/-//g' $1 | tr '[:upper:]' '[:lower:]'
}
find . -maxdepth 1 -regex '\./.*\.fsa' | while read file; do printf "%s\n" $(lowercase_remove_dash $file) > $file; done
@jottenlips
jottenlips / useDisableBodyScroll.js
Created January 6, 2021 15:46
react use-disable-body-scroll
import { useEffect } from 'react';
export const useDisableBodyScroll = (open) => {
useEffect(() => {
if (open) {
document.body.style.overflow = 'hidden';
} else {
document.body.style.overflow = 'unset';
}
}, [open]);
@jottenlips
jottenlips / react-pixel-vscode-find-replace.md
Created October 13, 2020 13:47
Replace all occurrences of px with ints for react projects to be fully compatible with react native

Find

'(\d.)px'

Replace

$1
@jottenlips
jottenlips / gitupstream.sh
Created October 2, 2020 21:59
Push to the upstream of your branch even if it does not exist remote.
alias branch='git symbolic-ref --short HEAD'
alias upstream='git push --set-upstream origin $(echo $(branch))'
# use
# cd some_project
# upstream