Skip to content

Instantly share code, notes, and snippets.

View rbngzlv's full-sized avatar

Rubén González rbngzlv

  • Fanatik Coders
  • Barcelona
View GitHub Profile
@rbngzlv
rbngzlv / url_patterns.py
Created September 18, 2021 23:05 — forked from c4urself/url_patterns.py
URL Patterns with Optional Arguments
(r'^articles/(?P<year>\d{4}/?$, 'main.views.year'),
# When a use case comes up that a month needs to be involved as
# well, you add an argument in your regex:
(r'^articles/(?P<year>\d{4}/(?P<month>\d{2})/?$, 'main.views.year_month'),
# That works fine, unless of course you want to show something
# different for just the year, in which case the following case can be
# used, making separate views based on the arguments as djangoproject
@rbngzlv
rbngzlv / rclone-cron.sh
Created January 19, 2020 17:40 — forked from jaredmales/rclone-cron.sh
An rclone backup script for cron
#!/bin/bash
##############################################################################
# An rclone backup script by Jared Males (jaredmales@gmail.com)
#
# Copyright (C) 2018 Jared Males <jaredmales@gmail.com>
#
# This script is licensed under the terms of the MIT license.
# https://opensource.org/licenses/MIT
#
@rbngzlv
rbngzlv / rclone_sync.txt
Created January 19, 2020 17:40 — forked from muety/rclone_sync.txt
Automated Google Drive sync for Linux using rclone
Script that will trigger a local to remote sync when any changes below your local Google Drive folder occur - but at max. every 10 minutes - and a remote to local sync every x (e.g. 30 minutes) via a cron job.
0. Install rclone and configure it for Google Drive
1. Create files listed below
2. Configure rclone_watch_local.sh to be run on startup (e.g. using a systemd service unit)
3. Add a cron job that runs rclone_remote2local.sh every x (e.g. 30) minutes
----------------------
rclone_local2remote.sh
----------------------
@rbngzlv
rbngzlv / semaphore.yml
Created October 16, 2019 17:20 — forked from cblavier/semaphore.yml
SemaphoreCI pipeline
version: v1.0
agent:
machine:
type: e1-standard-2
os_image: ubuntu1804
fail_fast:
stop:
when: "true"
@rbngzlv
rbngzlv / README.md
Created October 14, 2019 06:56 — forked from donaldpipowitch/README.md
Handle server errors in Formik

Whenever the server returns validation errors and we would set them with setFieldError they would be lost if any field would get a change or blur event. But we want to keep these kind of errors until the specific field changes. Additional we want to handle generic server errors (which are not specific to a field, but the whole form).

With these hooks field specific server side errors should be added like this:

const { setStatus } = useFormikContext();

const errors = {};
// adjust serverErrors to your own responses
// in this case they look like this: Array<{ name: string, error: string }>
@rbngzlv
rbngzlv / ExampleComponent.vue
Created October 7, 2019 21:42 — forked from innocenzi/ExampleComponent.vue
Inertia route guards
<template>
<!-- ... -->
</template>
<script>
export default {
// ...
beforeRouteLeave (vm, options, event) {
// vm will now refer to this component instead of the link
return window.confirm(vm.$trans('ticket.confirm_leave_creation'));
@rbngzlv
rbngzlv / Pretender.php
Created October 4, 2019 16:19 — forked from iksaku/Pretender.php
Pretender Middleware for Laravel apps that rely heavily on JS frameworks
<?php
namespace App\Http\Middleware;
use Cache;
use Closure;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\RequestOptions;
use Illuminate\Http\Request;
@rbngzlv
rbngzlv / gapless_sequence.sql
Created August 27, 2019 10:37 — forked from fabriziomello/gapless_sequence.sql
Gapless sequence example in PostgreSQL
CREATE TABLE public.gapless_sequence (
sequence_schema TEXT,
sequence_name TEXT,
last_value BIGINT DEFAULT 0,
step INTEGER DEFAULT 1
);
ALTER TABLE public.gapless_sequence
ADD CONSTRAINT gapless_sequence_pk PRIMARY KEY (sequence_schema, sequence_name);
@rbngzlv
rbngzlv / webpack.config.js
Created June 26, 2019 17:16 — forked from Sudheer-Reddy/webpack.config.js
Copy static assets in Webpack
const CopyWebpackPlugin = require('copy-webpack-plugin');
const path = require('path');
const PATHS = {
src: path.join(__dirname, 'src'), //absolute path to RepoDir/src
dist: path.join(__dirname, 'dist') //absolute path to RepoDir/dist
}
module.exports = {
entry: {
//Webpack will automatically resolve it to RepoDir/src/js/index.js (if file name is not specified)
@rbngzlv
rbngzlv / gcrgc.sh
Last active January 17, 2019 12:22 — forked from ahmetb/gcrgc.sh
Script to clean up Google Container Registry images pushed before a particular date
#!/bin/bash
# Copyright © 2017 Google Inc.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software