Skip to content

Instantly share code, notes, and snippets.

@swsalim
swsalim / 2-parse-apify-data
Last active April 29, 2024 02:55
2-parse-apify-data
import fs from 'fs';
import * as path from 'path';
import { AxiosResponse } from 'axios';
import dotenv from 'dotenv';
import { Configuration, CreateChatCompletionResponse, OpenAIApi } from 'openai';
// configure dotenv
dotenv.config();
@swsalim
swsalim / 1-clean-apify-data
Last active April 29, 2024 02:55
Clean APIFY Data
import * as fs from 'fs';
import * as path from 'path';
// Define a type alias for the days of the week
type Days = {
monday: string;
tuesday: string;
wednesday: string;
thursday: string;
friday: string;
@swsalim
swsalim / slugify
Last active April 29, 2024 02:20
A function to slugify string
// Typescript
const slugify = (str: string) => {
// remove accents, swap ñ for n, etc
const from = 'àáãäâèéëêìíïîòóöôùúüûñç·/_,:;';
const to = 'aaaaaeeeeiiiioooouuuunc------';
const slug = str.split('').map((letter, i) => {
return letter.replace(new RegExp(from.charAt(i), 'g'), to.charAt(i));
});
@swsalim
swsalim / About.vue
Last active May 31, 2021 08:59
Nuxt - Prismic - About Page sample
<template>
<div>
<div class="prose prose-lg">
<prismic-rich-text :field="page.content" />
</div>
</div>
</template>
<script>
export default {
@swsalim
swsalim / link-resolver.js
Created May 31, 2021 08:05
Prismic Link Resolver
@swsalim
swsalim / nuxt.config.js
Last active May 31, 2021 08:04
Nuxt.js with Prismic module
{
buildModules: [
'@nuxtjs/prismic'
],
prismic: {
endpoint: 'https://<REPOSITORY>.cdn.prismic.io/api/v2',
modern: true
/* see configuration for more */
}
}
import * as React from "react";
import { useMousePosition } from "~/hooks/useMousePosition";
/** Component to cover the area between the mouse cursor and the sub-menu, to allow moving cursor to lower parts of sub-menu without the sub-menu disappearing. */
export function MouseSafeArea(props: { parentRef: React.RefObject<HTMLDivElement> }) {
const { x = 0, y = 0, height: h = 0, width: w = 0 } = props.parentRef.current?.getBoundingClientRect() || {};
const [mouseX, mouseY] = useMousePosition();
const positions = { x, y, h, w, mouseX, mouseY };
return (
<div
@swsalim
swsalim / nuxt-mapbox-gl.vue
Created August 16, 2020 16:13
Real-word example of using the Mapbox GL library in a Nuxt static app
<template>
<div id="map" class="mt-4 sm:mt-8 sm:mx-5 sm:mb-5"></div>
</template>
<script>
export default {
name: 'DepotsMap',
data() {
return {
selectedMarker: null,
@swsalim
swsalim / example.com
Created August 8, 2020 01:58 — forked from 1hakr/example.com
Supercharge your NGIX config
proxy_cache_path /tmp/cacheapi levels=1:2 keys_zone=microcacheapi:100m max_size=1g inactive=1d use_temp_path=off;
server {
listen 443 ssl http2 default_server;
listen [::]:443 ssl http2 default_server;
server_name example.com;
location /api/ {
# Rate Limiting
limit_req zone=reqlimit burst=20; # Max burst of request