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 / app.css
Created August 14, 2017 11:19
Page transitions slide effect example with Nuxt.js and Vue.js
// only for desktop for now,
@media screen and (min-width: 1008px) {
/* during entering and leaving : */
.page-enter-active, .page-leave-active {
position:absolute;
max-width:725.328px; /*make sur our content keep it's original width*/
transition: all .2s ease;
}
@yann-yinn
yann-yinn / ApolloQuery.vue
Last active March 21, 2024 09:28
Use "apollo-client" package with Vue.js, without "vue-apollo"
<!--
If you really like to use apolloClient declaratively, here is a naive implementation
of a custom 'ApolloQuery' component
-->
<template>
<div>
<slot name="result" :result="this.result" />
</div>
</template>
@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 / api.js
Created August 23, 2017 13:01
Using cachios with Nuxt.js and express
/**
* Get content from wordpress via REST Api
*/
const config = require('../nuxt.config.js')
const axios = require('axios')
// always call the proxy here :
const endpoint = config.env.proxyApiBaseUrl
/**
* @param {int} perPage : number of post to return per page