Skip to content

Instantly share code, notes, and snippets.

@cjlaborde
cjlaborde / postgres-cheatsheet.md
Created November 16, 2018 07:56 — forked from Kartones/postgres-cheatsheet.md
PostgreSQL command line cheatsheet

PSQL

Magic words:

psql -U postgres

Some interesting flags (to see all, use -h or --help depending on your psql version):

  • -E: will describe the underlaying queries of the \ commands (cool for learning!)
  • -l: psql will list all databases and then exit (useful if the user you connect with doesn't has a default database, like at AWS RDS)
@cjlaborde
cjlaborde / gist:794b5d475eeb2689b36de9009646933e
Last active March 22, 2020 05:26 — forked from yesvods/gist:51af798dd1e7058625f4
Merge Arrays in one with ES6 Array spread
const arr1 = [1,2,3]
const arr2 = [4,5,6]
const arr3 = [...arr1, ...arr2] //arr3 ==> [1,2,3,4,5,6]
Short Version
const mergedarray = [].concat(...yourArrays);

Async calls

<template>
<p v-if="isLoading">
  Loading...
  {{ myData.if.you.try.to.access.properties.here.it.will.error }}
</p>
<p v-else>
  {{ myData.you.can.access.properties.now.that.myData.is.loaded }}

Async calls

<template>
<p v-if="isLoading">
  Loading...
  {{ myData.if.you.try.to.access.properties.here.it.will.error }}
</p>
<p v-else>
  {{ myData.you.can.access.properties.now.that.myData.is.loaded }}

In real code, you would call makePromise().then() or await makePromise(). I assigned the promise to an intermediate variable to illustrate the difference. Which style do you prefer?

const cl = console.log

function thenCatch () {
    cl('start')
    
    const promise = makePromise()
@cjlaborde
cjlaborde / gist:cdf7f951303a30c58a955fd391f47360
Created April 23, 2020 09:11 — forked from LuenCC/gist:e8dcf4a38096617799f3002644012af6
Laravel find nearest location in km from lat, long database
private function findNearestLocation(Request $request)
{
$location = DB::table('locations')
->select('name', 'latitude', 'longitude', 'region', DB::raw(sprintf(
'(6371 * acos(cos(radians(%1$.7f)) * cos(radians(latitude)) * cos(radians(longitude) - radians(%2$.7f)) + sin(radians(%1$.7f)) * sin(radians(latitude)))) AS distance',
$request->input('latitude'),
$request->input('longitude')
)))
->having('distance', '<', 50)
->orderBy('distance', 'asc')
@cjlaborde
cjlaborde / srid_units.sql
Created April 27, 2020 16:05 — forked from rustprooflabs/srid_units.sql
Creates view in PostGIS enabled database to make it easier to find what units each SRID is in.
CREATE OR REPLACE VIEW public.srid_units AS
SELECT srid, CASE WHEN proj4text LIKE '%+units=%' THEN True
ELSE False
END AS units_set,
CASE WHEN proj4text LIKE '%+units=m%' THEN 'Meters'
WHEN proj4text LIKE '%+units=ft%' THEN 'Feet'
WHEN proj4text LIKE '%+units=us-ft%' THEN 'Feet'
WHEN proj4text LIKE '%+units=link%' THEN 'Link (Dunno)'
WHEN proj4text LIKE '%+units=%' THEN 'Set, not caught properly'
ELSE 'Decimal Degrees'
@cjlaborde
cjlaborde / disposable-email-provider-domains
Created June 9, 2020 19:00
List of disposable email provider domains
0815.ru
0wnd.net
0wnd.org
10minutemail.co.za
10minutemail.com
123-m.com
1fsdfdsfsdf.tk
1pad.de
20minutemail.com
21cn.com
@cjlaborde
cjlaborde / head.js
Created February 15, 2021 18:32 — forked from garethredfern/head.js
The full head tag for a Nuxt website, including social media and SEO tags. Put this in your nuxt.config.js file.
head: {
htmlAttrs: {
lang: "en-GB",
},
title: "Articles focused on learning Laravel and VueJS",
meta: [
{ charset: "utf-8" },
{ name: "HandheldFriendly", content: "True" },
{ name: "viewport", content: "width=device-width, initial-scale=1" },
{
@cjlaborde
cjlaborde / getSiteMeta.js
Created February 15, 2021 19:06 — forked from garethredfern/getSiteMeta.js
The full getSiteMeta function for a Nuxt website, including social media and SEO tags.
const type = "website";
const url = "https://bobross.com";
const title = "My Amazing Blog on The Joy of Painting";
const description = "Articles focused on the beautiful art of landscape painting.";
const mainImage = "/a-lovely-image.png";
export default (meta) => {
return [
{
hid: "description",