Skip to content

Instantly share code, notes, and snippets.

View gahabeen's full-sized avatar

Gabin Desserprit gahabeen

View GitHub Profile
npm install axios cheerio jsonfram-cheerio --save
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) => {
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) {
{
"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"
},
{
@gahabeen
gahabeen / serverless.yml
Created September 3, 2018 11:31
Where am I wrong? CORS with Serverless with Spotinst
[...]
functions:
aFunctionName:
runtime: nodejs8.3
handler: handler.fn
memory: 128
timeout: 30
access: public
endpoint:
path: /path/fn
@gahabeen
gahabeen / HasRoleUDF.js
Last active January 21, 2022 16:36
Managing Roles Memberships in Fauna (DB)
// HasRole - User-Defined Function
CreateFunction({
name: 'HasRole',
body: Query(Lambda(['role', 'ref'], Select(Var('role'), Call('RolesMemberships', [Var('ref')]), false)))
})
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')))))

To add the snippets:

  1. Hit > shift + command + p and type snippets (or go look for 2.)
  2. Select Preferences: Open User Snippets
  3. Choose the language type for which you want to add the custom snippet (choosed all, for js/ts/fql files)
  4. Copy/Paste the snippets.json content in there

Currently covered:

  • q.Lambda
  • q.Let
  • q.Var
@gahabeen
gahabeen / TypeOf.ts
Last active May 1, 2020 08:17
Example of a TypeOf FQL method based on composition with Let(<array>)
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'))) },
@gahabeen
gahabeen / ducky keyboard remapping.md
Last active January 7, 2023 18:58
AutoHotKeys Remapping Arrows for Ducky One 2 Mini (DKON2061ST)

AutoHotKeys Remapping Arrows for Ducky One 2 Mini (DKON2061ST)

  • Press Fn + Alt + k for 5 seconds.
  • Set up the keys on the right of your space bar as: AltGr > Windows > Ctrl > Fn
  • Press Escape to quit