Skip to content

Instantly share code, notes, and snippets.

View wobsoriano's full-sized avatar
🎯
Focusing

Robert Soriano wobsoriano

🎯
Focusing
View GitHub Profile
@wobsoriano
wobsoriano / user.ts
Last active May 21, 2022 21:23
Nuxt and Zod validation
import * as z from 'zod'
import { defineEventHandler, CompatibilityEvent, useQuery } from 'h3'
const userSchema = z
.object({
name: z.string().min(4, { message: 'Must be 4 or more characters long' }),
age: z.string().transform((age) => parseInt(age, 10))
})
type UnknownKeysParam = "passthrough" | "strict" | "strip";
@wobsoriano
wobsoriano / proxy.ts
Last active December 22, 2023 02:25
Nuxt 3 http-proxy-middleware
// ~/server/middleware/proxy.ts
import { defineEventHandler } from 'h3'
import { createProxyMiddleware } from 'http-proxy-middleware'; // npm install http-proxy-middleware@beta
const apiProxyMiddleware = createProxyMiddleware({
target: 'https://jsonplaceholder.typicode.com',
changeOrigin: true,
ws: true,
pathRewrite: {
'^/api/todos': '/todos',
@wobsoriano
wobsoriano / emojis.json
Created April 17, 2022 22:05 — forked from oliveratgithub/emojis.json
Emoji-list with emojis, names, shortcodes, unicode and html entities [massive list]
{
"emojis": [
{"emoji": "👩‍👩‍👧‍👧", "name": "family: woman, woman, girl, girl", "shortname": ":woman_woman_girl_girl:", "unicode": "1F469 200D 1F469 200D 1F467 200D 1F467", "html": "👩‍👩‍👧‍👧", "category": "People & Body (family)", "order": ""},
{"emoji": "👩‍👩‍👧‍👦", "name": "family: woman, woman, girl, boy", "shortname": ":woman_woman_girl_boy:", "unicode": "1F469 200D 1F469 200D 1F467 200D 1F466", "html": "👩‍👩‍👧‍👦", "category": "People & Body (family)", "order": ""},
{"emoji": "👩‍👩‍👦‍👦", "name": "family: woman, woman, boy, boy", "shortname": ":woman_woman_boy_boy:", "unicode": "1F469 200D 1F469 200D 1F466 200D 1F466", "html": "👩‍👩‍👦‍👦", "category": "People & Body (family)", "order": ""},
{"emoji": "👨‍👩‍👧‍👧", "name": "family: man, woman, girl, girl", "shortname": ":man_woman_girl_girl:", "unicode": "1F468 200D 1F469 200D 1F467 200D 1F467", "html": "👨‍👩&z
@wobsoriano
wobsoriano / cgo.md
Created April 13, 2022 19:19 — forked from zchee/cgo.md
cgo convert list

See also, http://libraryofalexandria.io/cgo/

Using Go cgo

cgo has a lot of trap.
but Not "C" pkg also directory in $GOROOT/src. IDE's(vim) Goto command not works.

So, Here collect materials.

@wobsoriano
wobsoriano / page.vue
Created October 18, 2021 17:04
Nuxt 3 + socket.io
<script setup lang="ts">
import { io } from 'socket.io-client'
const connected = ref(false)
onMounted(() => {
const socket = io();
socket.on('connect', () => {
connected.value = socket.connected
@wobsoriano
wobsoriano / KeyboardShift.tsx
Created October 3, 2021 06:33
Keyboard Avoiding View for React Native in 2021
import React, { PropsWithChildren, useEffect, useState } from 'react';
import { Animated, Dimensions, Keyboard, KeyboardAvoidingView, StyleSheet, TextInput } from 'react-native';
import {useHeaderHeight} from '@react-navigation/elements';
import { useKeyboard } from '@react-native-community/hooks';
export default function KeyboardShift (props: PropsWithChildren<{}>) {
const [shift, setShift] = useState(new Animated.Value(0))
const keyboard = useKeyboard()
// On mount, add keyboard show and hide listeners
@wobsoriano
wobsoriano / useRefetchOnFocus.ts
Last active September 9, 2021 04:57
react-native refetch on focus only
// https://github.com/tannerlinsley/react-query/discussions/296#discussioncomment-1244793
export const useRefetchOnFocus = (refetch = () => {}, canRefetch = true) => {
const [isScreenFocused, setIsScreenFocused] = useState(false);
useFocusEffect(() => {
setIsScreenFocused(true); // when i focus the screen
return () => setIsScreenFocused(false); // when i quit the screen
});
/* the screen still always active in cache so we need to check that the screen is focused in a use effect
to dispatch the refetch only one time to avoid the infinity loop*/
@wobsoriano
wobsoriano / App.vue
Last active September 6, 2021 12:04
useInfiniteQuery example with Vue Query and Rick and Morty API
<template>
<div>
<h1>Rick and Morty Characters</h1>
<button @click="refetch()" :disabled="isFetching">{{ isFetching ? 'Refetching...' : 'Refetch' }}</button>
<div v-if="isLoading">loading...</div>
<div v-else>
<ul>
<li v-for="char in characters" :key="char.id">
{{ char.name }} - {{ char.status }}
</li>
@wobsoriano
wobsoriano / index.js
Last active August 21, 2021 10:43
Sending signed transaction with Web3
import Common, { Chain } from '@ethereumjs/common'
import { Transaction } from '@ethereumjs/tx'
import Web3 from 'web3'
const web3 = new Web3('https://ropsten.infura.io/v3/blablablabla')
const account1 = 'YOUR_ACCOUNT_1'
const privateKey1 = Buffer.from('YOUR_ACCOUNT_1_PRIVATE_KEY', 'hex')
const account2 = 'YOUR_ACCOUNT_2'
@wobsoriano
wobsoriano / auth.js
Last active February 29, 2024 07:37
nuxtServerInit like implementation for Pinia
import { defineStore } from 'pinia'
export const useAuthStore = defineStore({
id: 'auth',
state: () => ({
isAuthenticated: false,
user: null
}),
actions: {
async nuxtServerInit() {