Skip to content

Instantly share code, notes, and snippets.

View paulonteri's full-sized avatar
💻
Building

Paul Onteri paulonteri

💻
Building
View GitHub Profile
@paulonteri
paulonteri / deploy.yml
Last active May 20, 2020 14:22
CI/CD - Deploy a Dockerised app to Google Cloud Run automatically with GitHub Actions
name: Deploy a dockerised application to Google Cloud Run
on:
push:
branches:
- master
pull_request:
branches:
- master
jobs:
@paulonteri
paulonteri / nginx.conf
Created June 15, 2020 20:27
React Nginx config
server {
listen 80;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
@paulonteri
paulonteri / volley.java
Last active June 18, 2020 13:14
Volley GET request with parameters
RequestQueue queue = Volley.newRequestQueue(context);
//for POST requests, only the following line should be changed to
StringRequest sr = new StringRequest(Request.Method.GET, "http://headers.jsontest.com/",
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.e("HttpClient", "success! response: " + response.toString());
}
},
@paulonteri
paulonteri / Request.java
Last active June 23, 2020 14:06
Android Volley Request Queue
RequestQueue requestQueue;
// Instantiate the cache
Cache cache = new DiskBasedCache(getCacheDir(), 1024 * 1024); // 1MB cap
// Set up the network to use HttpURLConnection as the HTTP client.
Network network = new BasicNetwork(new HurlStack());
// Instantiate the RequestQueue with the cache and network.
requestQueue = new RequestQueue(cache, network);
@paulonteri
paulonteri / linked_list.py
Created June 24, 2020 07:16
Linked List - Python
"""
A linked list is a collection of 'nodes'.
The first node is called the head, and it’s used as the starting point for any iteration through the list.
The last node must have its next reference pointing to None to determine the end of the list.
"""
class Node(object):
def __init__(self,value):
self.value = value
self.next = None
@paulonteri
paulonteri / Volley.java
Created June 24, 2020 19:09
Android Volley - Making Post request
// Tag used to cancel the request
String tag_json_object = "json_obj_request";
String url = "http://velmm.com/apis/volley_array.json";
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Method.POST,
url, null,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
@paulonteri
paulonteri / localStorage.js
Created August 3, 2020 06:59
Detect Addition to localStorage/sessionStorage
sessionStorage.setItem = function (key, value) {
var event = new Event("itemInserted");
event.value = value; // Optional..
event.key = key; // Optional..
document.dispatchEvent(event);
originalSetItem.apply(this, arguments);
};
var sessionStorageSetHandler = function (e) {
console.log(e.key);
console.log(e.value);
@paulonteri
paulonteri / model_viewset.py
Created August 24, 2020 13:13
Override list method in DRF ModelViewSet
# Students View
class StudentViewSet(viewsets.ModelViewSet):
queryset = Student.objects.all()
serializer_class = StudentSerializer
permission_classes = perms
def list(self, request, *args, **kwargs):
queryset = Student.objects.all().only("student_id", "first_name", "surname", "gender", "class_ns", "dormitory")
serializer = StudentLessDataSerializer(queryset, many=True)
return Response(serializer.data)
@paulonteri
paulonteri / config-overrides.js
Last active August 24, 2020 13:17
Auto Import Antd css
const {
override,
fixBabelImports,
addWebpackPlugin
} = require("customize-cra");
const FilterWarningsPlugin = require("webpack-filter-warnings-plugin");
module.exports = override(
fixBabelImports("antd", {
libraryDirectory: "es",
@paulonteri
paulonteri / create_db.py
Created September 13, 2020 12:49
Create Azure PosgreSQL Database script
#!/usr/bin/env python3
import os
import subprocess
import urllib.request
# Required environment variables
REQUIRED_ENV_VARS = (
'AZ_GROUP',
'AZ_LOCATION',