Skip to content

Instantly share code, notes, and snippets.

View yann-yinn's full-sized avatar

Yann yann-yinn

  • Yann
  • France, Nantes
View GitHub Profile
@yann-yinn
yann-yinn / useApiRequest.ts
Created January 28, 2022 11:01
useApiRequest - a small Vue 3 composable to fetch data from a JSON API
/**
* Usage in a component:
*
* import useApiRequest from "@/composables/useApiRequest"
*
* const saveRequest = useApiRequest("https://jsonplaceholder.typicode.com/userse");
* function handleFormSubmit() {
* saveRequest.execute()
* }
*/
@yann-yinn
yann-yinn / watch-vs-watch-effect.vue
Created January 5, 2022 08:47
watch Versus watchEffect
<script setup lang="ts">
import { ref, watch, watchEffect } from "vue";
const price = ref(10);
const quantity = ref(1);
watchEffect(() => {
console.log("watchEffect()", price.value, quantity.value);
});
@yann-yinn
yann-yinn / with-axios.js
Last active April 23, 2021 20:56
codetree-test
import React, { useState, useEffect } from "react";
import ReactDOM from "react-dom";
import axios from "axios";
export default function App() {
const [users, setUsers] = useState(null);
useEffect(async () => {
const result = await axios("https://gorest.co.in/public-api/users");
setUsers(result.data.data);
@yann-yinn
yann-yinn / react.jsx
Created April 23, 2021 19:25
react router dom
import React from "react";
import {
BrowserRouter as Router,
Switch,
Route,
Link
} from "react-router-dom";
export default function App() {
return (
@yann-yinn
yann-yinn / db.js
Created March 12, 2021 08:22
connnect do mongoDB
const { MongoClient } = require("mongodb");
let db;
const client = new MongoClient(process.env.MONGO_URL, {
useNewUrlParser: true,
useUnifiedTopology: true,
});
module.exports = {
@yann-yinn
yann-yinn / graphql-with-fetch.js
Created December 27, 2020 11:27
Create GraphQL Request with fetch
async function graphql({ query, variables }) {
let response = await fetch(process.env.FIREBLOG_GRAPHQL_ENDPOINT, {
method: "POST",
headers: {
"Content-Type": "application/json",
Accept: "application/json",
},
body: JSON.stringify({
query,
variables,
const crypto = require("crypto");
const algorithm = "aes-256-cbc";
const secretKey = "SECRET_KEY_32_CHARS";
module.exports = {
encrypt,
decrypt,
};
// https://attacomsian.com/blog/nodejs-encrypt-decrypt-data
@yann-yinn
yann-yinn / tea-dropdown.erb
Last active October 22, 2020 09:02
tea dropdown
<div
class="space-y-1"
x-data="Components.select({links: [<%= all_items_links %>], value: <%= selected_index %>, selected: <%= selected_index %> %>)"
x-init="init()">
<% if hide_label %>
<label
class="sr-only"
id="<%= random_id_prefix %>-listbox-label">
<%= label %>
</label>
@yann-yinn
yann-yinn / fireblog-graphql-get-posts.gql
Last active October 21, 2020 09:49
fireblog-graphql-get-posts
{
postsCount(filter: { blog: { eq: "{{BLOG_ID}}" } })
posts(
limit: 20
skip: 0
filter: { blog: { eq: "{{BLOG_ID}}" } }
) {
slug
title
teaser
@yann-yinn
yann-yinn / App.vue
Last active October 21, 2020 08:53
Fireblog basic vue example
<template>
<div id="app">
<div v-if="loadingState === 'PENDING'">Loading ...</div>
<div
v-if="loadingState === 'FINISHED'"
style="max-width: 700px; margin: auto"
>
<header style="margin-bottom: 40px; text-align: center">
<h1>{{ blog.name }}</h1>
<em>{{ blog.description }} </em>