Skip to content

Instantly share code, notes, and snippets.

Avatar

Pier Bover PierBover

View GitHub Profile
@PierBover
PierBover / index.js
Last active Sep 22, 2020
FaunaDB client aggregation example
View index.js
const faunadb = require('faunadb');
const q = faunadb.query;
const client = new faunadb.Client({
secret: 'YOUR_FAUNA_SECRET'
});
async function countDocs () {
const refs = [];
let after, page;
@PierBover
PierBover / rename_layer.jsx
Created Sep 17, 2020
Rename Photoshop Layers
View rename_layer.jsx
var activeLayerRef = app.activeDocument.activeLayer;
if (activeLayerRef.artLayers) {
var layers = activeLayerRef.artLayers;
for (var i = 0; i < layers.length; i++) {
layers[i].name = activeLayerRef.name + '_' + (i+1);
}
}
@PierBover
PierBover / fql.js
Created Aug 14, 2020
All FQL commands for JS
View fql.js
// All FQL commands
const {
Abort, Abs, Acos, Add, All, And, Any, Append, Asin, At, Atan, BitAnd, BitNot, BitOr, BitXor, Call, Casefold, Ceil, Collection, Collections, Concat, Contains, ContainsStr, ContainsStrRegex, Cos, Cosh, Count, Create, CreateCollection, CreateDatabase, CreateFunction, CreateIndex, CreateKey, CreateRole, Database, Databases, Date, DayOfMonth, DayOfWeek, DayOfYear, Degrees, Delete, Difference, Distinct, Divide, Do, Documents, Drop, EndsWith, Epoch, Equals, Events, Exists, Exp, Filter, FindStr, FindStrRegex, Floor, Foreach, Format, Function, Functions, GT, GTE, Get, HasIdentity, Hour, Hypot, Identify, Identity, If, Index, Indexes, Insert, Intersection, IsArray, IsBoolean, IsBytes, IsCollection, IsCredentials, IsDatabase, IsDate, IsDoc, IsDouble, IsEmpty, IsFunction, IsIndex, IsInteger, IsKey, IsLambda, IsNonEmpty, IsNull, IsNumber, IsObject, IsRef, IsRole, IsSet, IsString, IsTimestamp, IsToken, Join, KeyFromSecret, Keys, LT, LTE, LTrim, Lambda, Length, Let, Ln, Log, Login, Logout, Lower
@PierBover
PierBover / cloudflare-countries.json
Created Jun 1, 2020
Cloudflare countries with regions
View cloudflare-countries.json
[
{"code":"A1", "name":"Anonymous Proxy", "region":"NO_REGION"},
{"code":"A2", "name":"Satellite Provider", "region":"NO_REGION"},
{"code":"O1", "name":"Other Country", "region":"NO_REGION"},
{"code":"AD", "name":"Andorra", "region":"EUROPE"},
{"code":"AE", "name":"United Arab Emirates", "region":"MIDDLE_EAST"},
{"code":"AF", "name":"Afghanistan", "region":"MIDDLE_EAST"},
{"code":"AG", "name":"Antigua and Barbuda", "region":"CARIBBEAN"},
{"code":"AI", "name":"Anguilla", "region":"CARIBBEAN"},
{"code":"AL", "name":"Albania", "region":"EUROPE"},
View fastify.js
// init
const fastify = require('fastify')({
ignoreTrailingSlash: true,
logger: true
});
fastify.route({
method: 'GET',
url: '/',
handler: (request, reply) => {
@PierBover
PierBover / website_performance.md
Last active Jun 24, 2020
Tools to test the performance of your website worldwide
View rollup-plugin.js
const routesFilesPlugin = {
name: 'route-files',
buildStart: async (options) => {
console.log('Generating routeModules.js');
const routesDir = path.resolve(__dirname, 'src/components/routes');
const routeFiles = fs.readdirSync(routesDir);
const routesString = routeFiles.map((filename) => {
@PierBover
PierBover / explanation.md
Created May 8, 2020
FQL recursive function to get nested documents
View explanation.md

This is how you'd call the function:

Call(Function("GetNestedDocument"), [Ref(Collection("SomeCollection"), "264260207986606612"), 0, 3])

Parameters:

  • A Ref of a document.
  • Current depth. Since AFAIK we cannot have default values in Lambda we need to pass 0 for the first level.
  • Max depth. The max number of levels the recursive function will go.
@PierBover
PierBover / index.js
Last active Aug 22, 2020
Micro router for Cloudflare Workers
View index.js
const router = require('./router');
router.setRoutes([
{
path: '/ping',
method: 'GET',
handler: ping
},
{
path: '/hello/:name',
@PierBover
PierBover / AppDelegate.swift
Last active Sep 2, 2019
Receive custom URL schema in macOS
View AppDelegate.swift
class AppDelegate: NSObject, NSApplicationDelegate {
func applicationDidFinishLaunching(_ aNotification: Notification) {
NSAppleEventManager.shared().setEventHandler(self, andSelector: #selector(self.handleGetURLEvent(event:replyEvent:)), forEventClass: AEEventClass(kInternetEventClass), andEventID: AEEventID(kAEGetURL))
}
@objc func handleGetURLEvent(event: NSAppleEventDescriptor, replyEvent: NSAppleEventDescriptor) {
let urlString = event.paramDescriptor(forKeyword: AEKeyword(keyDirectObject))?.stringValue!
let url = URL(string: urlString!)!
debugPrint(url);
}
You can’t perform that action at this time.