Skip to content

Instantly share code, notes, and snippets.

View paulonteri's full-sized avatar
💻
Building

Paul Onteri paulonteri

💻
Building
View GitHub Profile
#!/bin/bash -i
# using shebang with -i to enable interactive mode (auto load .bashrc)
set -e #stop immediately if any error happens
# Install Open SDK
sudo apt-get update
sudo apt-get install openjdk-8-jdk -y
sudo update-java-alternatives --set java-1.8.0-openjdk-amd64
java -version
@paulonteri
paulonteri / docker_prune.sh
Created March 27, 2021 18:35
schedule a nightly reboot
0 4 * * * root reboot
# 0 4 * * * root reboot
# https://askubuntu.com/a/655387
@paulonteri
paulonteri / Breadcrumbs.js
Created April 4, 2021 17:48
Next.js Breadcrumbs
import React, { useEffect, useState } from "react";
import { useRouter } from "next/router";
import Link from "next/link";
const convertBreadcrumb = (string) => {
return string
.replace(/-/g, " ")
.replace(/oe/g, "ö")
.replace(/ae/g, "ä")
.replace(/ue/g, "ü")
@paulonteri
paulonteri / drf_utils.py
Created April 20, 2021 19:44 — forked from twidi/drf_utils.py
Make Django Rest Framework correctly handle Django ValidationError raised in the save method of a model
"""
Sometimes in your Django model you want to raise a ``ValidationError`` in the ``save`` method, for
some reason.
This exception is not managed by Django Rest Framework because it occurs after its validation
process. So at the end, you'll have a 500.
Correcting this is as simple as overriding the exception handler, by converting the Django
``ValidationError`` to a DRF one.
"""
from django.core.exceptions import ValidationError as DjangoValidationError
#!/bin/bash
# Originally written by Ralf Kistner <[email protected]>, but placed in the public domain
set +e
bootanim=""
failcounter=0
timeout_in_sec=900
@paulonteri
paulonteri / .gitlab-ci.yml
Created May 22, 2021 07:52 — forked from illuzor/.gitlab-ci.yml
Config for gitlab ci android with unit tests and instrumented tests
image: openjdk:8-jdk
variables:
ANDROID_COMPILE_SDK: "29"
ANDROID_BUILD_TOOLS: "29.0.3"
SDK_TOOLS: "6200805" # from https://developer.android.com/studio/#command-tools
EMULATOR_VERSION: "24"
before_script:
- wget --quiet --output-document=android-sdk.zip https://dl.google.com/android/repository/commandlinetools-linux-${SDK_TOOLS}_latest.zip
@paulonteri
paulonteri / reverse_linked_list_two.py
Created July 19, 2021 19:21
Reverse Linked List II: Given the head of a singly linked list and two integers left and right where left <= right, reverse the nodes of the list from position left to position right, and return the reversed list.
"""
Reverse Linked List II:
Given the head of a singly linked list and two integers left and right where left <= right,
reverse the nodes of the list from position left to position right, and return the reversed list.
Follow up: Could you do it in one pass?
Example 1:
Input: head = [1,2,3,4,5], left = 2, right = 4
Output: [1,4,3,2,5]
const jsonObj = {"doorsWindows":[{'ID':"A","style":"apple"},{'ID':"B","style":"apple"},{'ID':"C","style":"apple"}]}
const doorsWindowsIds = []
for (var i = 0; i < jsonObj.doorsWindows.length; i++) {
let doorWindow = jsonObj.doorsWindows[i];
doorsWindowsIds.push(doorWindow.ID)
}
console.log(doorsWindowsIds)
"""
Node Depths:
The distance between a node in a Binary Tree and the tree's root is called the node's depth.
Write a function that takes in a Binary Tree and returns the sum of its nodes' depths.
Each BinaryTree node has an integer value, a left child node, and a right child node.
Children nodes can either be BinaryTree nodes themselves or None / null.
https://www.algoexpert.io/questions/Node%20Depths
"""
@paulonteri
paulonteri / 1.cron_handler.py
Last active October 21, 2021 14:07
Google Cloud Tasks in Django
import datetime
import json
import logging
import pickle
import sys
import timeit
from time import sleep
from django.conf import settings
from django.core.serializers.json import DjangoJSONEncoder