Skip to content

Instantly share code, notes, and snippets.

CreateIndex({
  name: 'ngram_on_users',
  source: {
    collection: Collection('users'),
    fields: {
      search: Query(Lambda('instance', 
          Union(
            Union(Map([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], Lambda('min', NGram(LowerCase(Select(['data', 'first_name'], Var('instance'))), Var('min'), Var('min'))))),
 Union(Map([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], Lambda('min', NGram(LowerCase(Select(['data', 'last_name'], Var('instance'))), Var('min'), Var('min')))))
@ptpaterson
ptpaterson / nested-fql-manual.js
Last active December 26, 2021 15:09
Template for building deeply nested FQL queries for FaunaDB
const baseQuery = q.Paginate(q.Match(q.Index(indexName), terms));
// or
// const baseQuery = q.Paginate(q.Collection(collectionName))
const expandedQuery = q.Map(baseQuery, (ref) =>
q.Let(
{
instance: q.Get(q.Var('ref'))
},
{
@aprilmintacpineda
aprilmintacpineda / NodeJS require local modules resolver.md
Last active May 13, 2022 10:38
NodeJS require concept for local modules

NodeJS require concept for local modules

The problem

As your NodeJS app grows bigger, the file structure tends to go 3 to even 5 layers deep. The problem now is as you require local modules you created, you'll have to write them in this way:

const myModule = require('../../../my/module');
@blopa
blopa / Matrix.jsx
Last active August 17, 2023 14:06
Matrix Rain effect with a React functional hooks component
import React, { useEffect, useRef } from 'react';
function MatrixBackground({ timeout = 50 }) {
const canvas = useRef();
useEffect(() => {
const context = canvas.current.getContext('2d');
const width = document.body.offsetWidth;
const height = document.body.offsetHeight;
@wybiral
wybiral / noscript-tracking.go
Last active September 11, 2023 08:53
Tracking cursor position in real-time with remote monitoring (without JavaScript)
// Tracking cursor position in real-time without JavaScript
// Demo: https://twitter.com/davywtf/status/1124146339259002881
package main
import (
"fmt"
"net/http"
"strings"
)
@DavidWells
DavidWells / aws-lambda-redirect.js
Created June 28, 2018 20:48
How to do a 301 redirect from an AWS lambda function
exports.handler = (event, context, callback) => {
const response = {
statusCode: 301,
headers: {
Location: 'https://google.com',
}
};
return callback(null, response);
}
@DavidWells
DavidWells / serverless.yml
Created September 15, 2017 05:39
DynamoDB custom index serverless.yml example
service: service-name
provider:
name: aws
runtime: nodejs6.10
functions:
myfunc:
handler: handler.myfunc
@HyperBrain
HyperBrain / lifecycle-cheat-sheet.md
Last active March 20, 2024 00:17
Serverless Lifecycle Cheat Sheet

Serverless plugin author's cheat sheet

This cheat sheet provides a detailed overview of the exposed lifecycle events and available commands (and entrypoints) of the Serverless framework, that can be hooked by plugins (internal and external ones). The document is structured by the commands invoked by the user.

Lifecycle events are shown as the globally available outer events (all providers) and sub lifecycle events that are provider specific in the called order. Currently only the AWS provider is shown. If you have information about the other provider,

@Lwdthe1
Lwdthe1 / usaCities.js
Last active April 13, 2024 14:18
JSON of 5,950+ USA Cities and Their States - Presented by https://www.ManyStories.com
[
{'city': 'Abbeville', 'state': 'Louisiana'},
{'city': 'Aberdeen', 'state': 'Maryland'},
{'city': 'Aberdeen', 'state': 'Mississippi'},
{'city': 'Aberdeen', 'state': 'South Dakota'},
{'city': 'Aberdeen', 'state': 'Washington'},
{'city': 'Abilene', 'state': 'Texas'},
{'city': 'Abilene', 'state': 'Kansas'},
@graydon
graydon / country-bounding-boxes.py
Created April 23, 2014 00:03
country bounding boxes
# extracted from http//www.naturalearthdata.com/download/110m/cultural/ne_110m_admin_0_countries.zip
# under public domain terms
country_bounding_boxes = {
'AF': ('Afghanistan', (60.5284298033, 29.318572496, 75.1580277851, 38.4862816432)),
'AO': ('Angola', (11.6400960629, -17.9306364885, 24.0799052263, -4.43802336998)),
'AL': ('Albania', (19.3044861183, 39.624997667, 21.0200403175, 42.6882473822)),
'AE': ('United Arab Emirates', (51.5795186705, 22.4969475367, 56.3968473651, 26.055464179)),
'AR': ('Argentina', (-73.4154357571, -55.25, -53.628348965, -21.8323104794)),
'AM': ('Armenia', (43.5827458026, 38.7412014837, 46.5057198423, 41.2481285671)),