Skip to content

Instantly share code, notes, and snippets.

View SergioJuniorCE's full-sized avatar

Sergio Junior Castro Egurrola SergioJuniorCE

View GitHub Profile
@SergioJuniorCE
SergioJuniorCE / remove_item_from_array.js
Last active November 19, 2021 16:34
How to remove an specific item from arrat
let array = [0, 1, 3, 4, 5];
let item = 3;
console.log(array);
const index = array.indexOf(item);
if (index > -1) {
array.splice(index, 1);
}
console.log(array);
@SergioJuniorCE
SergioJuniorCE / NavbarItem.svelte
Created November 29, 2021 07:57
goto function svelte
<script>
import { goto } from '$app/navigation';
import { page } from '$app/stores';
export let title;
export let href;
function goTo() {
goto(href, {
replaceState: true
@SergioJuniorCE
SergioJuniorCE / load.svelte
Last active January 30, 2022 21:25
load function sveltekit
<script context="module">
export async function load({ page, params, fetch, session, stuff }) {
const slug = page.params.slug;
const url = `http://localhost:1337/categories/${slug}`;
const res = await fetch(url);
const category = await res.json();
return {
props: {
category
}
@SergioJuniorCE
SergioJuniorCE / slugStrapi.md
Last active November 30, 2021 21:07
Add slug to strapi param
  • Go to api folder
  • Select the collection you want to add the slug to
  • Go to config folder
  • Open routes.json
  • Add this code to routes array:
      {
        "method": "GET",
        "path": "/collection/:slug",
        "handler": "collection.findOne",
@SergioJuniorCE
SergioJuniorCE / __error.svelte
Created December 1, 2021 06:04
error page animation
<script context="module">
/** @type {import('@sveltejs/kit').ErrorLoad} */
export function load({ error, status }) {
return {
props: {
status: status,
message: error.message
}
};
}
@SergioJuniorCE
SergioJuniorCE / different_to_list.py
Last active December 27, 2021 04:24
add every different thing until run out
indexes = [] # 0, 6, 9 | 20
for i, item in enumerate(items):
if i == 0:
indexes.append(i)
continue
if i+1 == len(items):
break
if item[1] != items[i+1][1]:
indexes.append(i+1)
@SergioJuniorCE
SergioJuniorCE / supabase.ts
Last active January 4, 2022 06:13
supabase client
import { createClient } from '@supabase/supabase-js';
const supabase = createClient(
import.meta.env.VITE_SUPABASE_URL.toString(),
import.meta.env.VITE_SUPABASE_KEY.toString()
);
export default supabase;
@SergioJuniorCE
SergioJuniorCE / Posts.svelte
Created January 30, 2022 21:23
realtime supabase data
<script>
import { supabase } from '$lib/database';
import { readable, get } from 'svelte/store';
const posts = readable(null, (set) => {
supabase
.from('posts')
.select('*')
.then(({ data }) => set(data));
const subscriptions = supabase
.from('posts')