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')))))
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
npm install axios cheerio jsonfram-cheerio --save | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let axios = require('axios'); | |
axios.get('https://www.producthunt.com') // HTTP request to https://www.producthunt.com | |
.then((response) => { // Success case | |
if(response.status === 200) { // If HTTP Response is 200 - All good | |
let html = response.data; // Setting the reponse.data to html | |
} // to make things clear | |
}, (error) => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let axios = require('axios'); // HTTP client | |
let cheerio = require('cheerio'); // HTML parsing package | |
let jsonframe = require('jsonframe-cheerio'); // a cheerio plugin I designed | |
let fs = require('fs'); // is included in node.js - you don't need to install it | |
axios.get('https://www.producthunt.com') | |
.then((response) => { | |
if(response.status === 200) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"products": [ | |
{ | |
"name": "Truman Grade", | |
"description": "Detect harmful websites instantly", | |
"image": "https://ph-files.imgix.net/bfc7e122-b276-4907-9cad-9f9d370ad90f?auto=format&auto=compress&codec=mozjpeg&cs=strip&w=80&h=80&fit=crop", | |
"upvotes": "129", | |
"comments": "8" | |
}, | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[...] | |
functions: | |
aFunctionName: | |
runtime: nodejs8.3 | |
handler: handler.fn | |
memory: 128 | |
timeout: 30 | |
access: public | |
endpoint: | |
path: /path/fn |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// HasRole - User-Defined Function | |
CreateFunction({ | |
name: 'HasRole', | |
body: Query(Lambda(['role', 'ref'], Select(Var('role'), Call('RolesMemberships', [Var('ref')]), false))) | |
}) |
To add the snippets:
- Hit > shift + command + p and type snippets (or go look for 2.)
- Select Preferences: Open User Snippets
- Choose the language type for which you want to add the custom snippet (choosed all, for js/ts/fql files)
- Copy/Paste the snippets.json content in there
Currently covered:
- q.Lambda
- q.Let
- q.Var
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { query as q, Expr } from 'faunadb'; | |
export function TypeOf(value: Expr) { | |
return q.Let( | |
{ | |
value, | |
type: q.Let( | |
[ | |
{ t: null }, | |
{ t: q.If(q.IsString(q.Var('t')), q.Var('t'), q.If(q.IsArray(q.Var('value')), 'array', q.Var('t'))) }, |