Skip to content

Instantly share code, notes, and snippets.



View GitHub Profile

maxymajzr Advice about making app concurrency-safe

right now, i can tell you that your code is not concurrency-safe (meaning multiple-inserts at once)
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 databases
instead of doing this check in PHP, you'd make your database allow or disallow inserts. it's done by placing unique keys to start, end and active columns in your table.

if an active tour exists for a combination of start and end, database will throw an error saying that it can't write because unique key constraint fails. this is concurrency-safe and no record can exist with the same combination of data

what i'm typing heavily depends on your table schema, i didn't include all keys you'd have to add to unique constraint, however that's the way you do it, you'd have to think a bit before applying the solution
View disposable-email-provider-domains
cjlaborde /
Last active Jun 16, 2020
Javascript Snippets
cjlaborde / gist:76b29dd66ed21889a2b0937c4998c77e
Last active May 7, 2020
How to interact with Libraries
View gist:76b29dd66ed21889a2b0937c4998c77e

How to interact with Libraries

Use querySelector

View React Best packages
cjlaborde / srid_units.sql
Created Apr 27, 2020 — forked from rustprooflabs/srid_units.sql
Creates view in PostGIS enabled database to make it easier to find what units each SRID is in.
View srid_units.sql
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 / gist:cdf7f951303a30c58a955fd391f47360
Created Apr 23, 2020 — forked from LuenCC/gist:e8dcf4a38096617799f3002644012af6
Laravel find nearest location in km from lat, long database
View gist:cdf7f951303a30c58a955fd391f47360
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',
->having('distance', '<', 50)
->orderBy('distance', 'asc')
View async await vs then

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 () {
    const promise = makePromise()
View Server Setup
### File Limit
#### Set in http block which affects all server blocks (virtual hosts).
http {
client_max_body_size 100M;
You can’t perform that action at this time.