Skip to content

Instantly share code, notes, and snippets.

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'
https://github.com/final-form/react-final-form
https://github.com/airbnb/react-dates
@cjlaborde
cjlaborde / gist:76b29dd66ed21889a2b0937c4998c77e
Last active May 7, 2020 19:40
How to interact with Libraries

How to interact with Libraries

Use querySelector

this.$refs.datepicker.$el.querySelector('.datepicker__input').click();
https://github.com/JedWatson/classnames
@cjlaborde
cjlaborde / JavascriptSnippets.md
Last active June 16, 2020 21:00
Javascript Snippets
@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

maxymajzr Advice about making app concurrency-safe

https://www.informit.com/articles/article.aspx?p=22681&seqNum=3

right now, i can tell you that your code is not concurrency-safe (meaning multiple-inserts at once):

  1. there's only 1 proper way to do it, and sadly - you will never find it anywhere in any laravel or php tutorials and it's because this issue is related to data modelling and databasesthat's how it works

  2. It takes time() and adds config('session.lifetime') to it

  3. Then you get a cookie that expires at time() + config('session.lifetime')

  4. There's very little point in making the user extend the session, it's something you make user think about and users know fuck all about techy shit

  5. Instead, you can use what google does and does it really good set a cookie for 2 years

@cjlaborde
cjlaborde / UsefulLinks.md
Last active December 4, 2020 02:18
Links of services useful for web development
We couldn’t find that file to show.