Skip to content

Instantly share code, notes, and snippets.

View mhaagens's full-sized avatar

Martin mhaagens

  • AmmaCreative
  • Oslo, Norway
View GitHub Profile
@marlosirapuan
marlosirapuan / app-context.ts
Created August 31, 2023 18:09
Context App Provider with zustand in Typescript
import { createContext, useContext } from 'react'
import { createStore, StoreApi } from 'zustand'
import { immer } from 'zustand/middleware/immer'
import { useStoreWithEqualityFn } from 'zustand/traditional'
type State = {
total: number
increase: () => void
decrease: () => void
@jdthorpe
jdthorpe / login.tsx
Created March 16, 2023 22:48
expo-auth-session example
/* An example app that uses expo-auth-session to connect to Azure AD (or hopefully most providers)
Features:
- secure cache with refresh on load
- securely stored refresh token using expo-secure-store
- uses zustand for global access to the token / logout
Based on [this gist](https://gist.github.com/thedewpoint/181281f8cbec10378ecd4bb65c0ae131)
*/
@r0b0t3d
r0b0t3d / useCallback.md
Created July 10, 2021 09:06
Use of useCallback and useMemo

1. Use

1.1. in callback

const handlePress = useCallback(() => {
	// handle press
}, [])

Good 👍

<Button onPress={handlePress} />
@enisdenjo
enisdenjo / graphiql-over-ws.html
Last active December 20, 2023 05:32
GraphiQL ❤️ graphql-ws
<!--
* Copyright (c) 2021 GraphQL Contributors
* All rights reserved.
*
* This code is licensed under the MIT license.
* Use it however you wish.
-->
<!DOCTYPE html>
<html>
<head>
@goofansu
goofansu / app.js
Last active August 5, 2023 04:05
LiveView upload directly to AWS China S3
let Uploaders = {}
Uploaders.S3 = function (entries, onViewError) {
entries.forEach(entry => {
let xhr = new XMLHttpRequest()
onViewError(() => xhr.abort())
xhr.onload = () => (xhr.status === 200 ? entry.done() : entry.error())
xhr.onerror = () => entry.error()
xhr.upload.addEventListener("progress", event => {
if (event.lengthComputable) {
@gorhom
gorhom / BottomSheetModal.tsx
Created September 21, 2020 18:34
Bottom Sheet Modal
import React, {
useCallback,
useEffect,
useMemo,
useRef,
useState,
} from 'react';
import { SafeAreaView, StyleSheet, Text, View } from 'react-native';
import BottomSheet from '@gorhom/bottom-sheet';
import { SafeAreaProvider } from 'react-native-safe-area-context';
@retendo
retendo / index.js
Created May 31, 2020 12:14
Supabase node.js proxy server
const { Socket } = require('@supabase/realtime-js');
const WebSocket = require('ws');
const wss = new WebSocket.Server({ port: 3000 });
wss.on('connection', function connection(ws) {
ws.send('Connection established.');
});
const socket = new Socket(process.env.REALTIME_URL || 'http://localhost:4000/socket')
@eusonlito
eusonlito / updated-at.sql
Last active April 21, 2024 21:47
Use trigger to change `updated_at` on all PostgreSQL tables
#
# Delete previous function definition (if exists)
#
DROP FUNCTION IF EXISTS before_update_updated_at() CASCADE;
#
# Create function to update updated_at timestamp if changed values on update
#
CREATE OR REPLACE FUNCTION before_update_updated_at() RETURNS trigger AS
$BODY$
@kmelve
kmelve / department.js
Created April 15, 2020 07:35
Example of listing documents in Sanity Studio‘s desk structure with real-time listener
export default {
name: 'department',
type: 'document',
title: 'Department',
fields: [
{
name: 'title',
type: 'string',
title: 'Title',
},
@GiselaMD
GiselaMD / client.ts
Last active September 23, 2021 11:22
ApolloClient with token authentication and refresh token
import { HttpLink } from 'apollo-link-http';
import { ApolloClient, DefaultOptions } from 'apollo-client';
import { InMemoryCache, NormalizedCacheObject } from 'apollo-cache-inmemory';
import { ApolloLink } from 'apollo-link';
import { resolvers } from './resolvers';
import { typeDefs } from './schema/typeDefs';
import { errorLink } from './error';
import { requestLink } from './requestLink';
import customFetch from './customFetch';