Skip to content

Instantly share code, notes, and snippets.

View gbaldera's full-sized avatar
🏠
Working from home

Gustavo Rodriguez Baldera gbaldera

🏠
Working from home
View GitHub Profile
@mikesparr
mikesparr / gcp-nextjs-vercel-gcp-migrate.sh
Last active September 25, 2025 13:13
Experiment migrating Vercel hosted NextJS app to Google Cloud Platform atop Cloud Run
#!/usr/bin/env bash
#####################################################################
# REFERENCES
# - https://nextjs.org/learn/dashboard-app/getting-started
# - https://github.com/vercel/next.js/tree/canary/examples/with-docker
# - https://cloud.google.com/run/docs/quickstarts/build-and-deploy/deploy-nodejs-service
# - https://cloud.google.com/run/docs/configuring/services/environment-variables
# - https://cloud.google.com/run/docs/securing/service-identity
# - https://cloud.google.com/sdk/gcloud/reference/run/deploy
@dzerrenner
dzerrenner / fields.py
Last active December 30, 2022 15:21 — forked from danni/fields.py
Multi Choice Django Array Field with Checkbox Widget
from django import forms
from django.contrib.postgres.fields import ArrayField
class ChoiceArrayField(ArrayField):
"""
A field that allows us to store an array of choices.
Uses Django 1.9's postgres ArrayField
and a MultipleChoiceField for its formfield.
@bokwoon95
bokwoon95 / schemaspy-docker-postgres.sh
Last active September 5, 2025 14:03
How to run Docker SchemaSpy on a locally running Postgres
docker run -v "$PWD/schemaspy_output:/output" schemaspy/schemaspy:latest \
-t pgsql \
-host host.docker.internal \
-port 5432 \
-db my_database \
-u my_username \
-p my_password \
-vizjs
# -host needs to be host.docker.internal to refer to your local machine's localhost,
# not the schemaspy container's localhost. Schemaspy's docker documentation for this is horrible.
@niuware
niuware / django_stream_queryset_to_csv.md
Created October 18, 2019 03:41
How to stream a CSV file from a large QuerySet using Django's StreamingHttpResponse

Stream a CSV file from a QuerySet using StreamingHttpResponse

This is a sample on how to stream the results of a large QuerySet into a CSV file using Django StreamingHttpResponse class.

  1. Add the CSVStream class in your project, for example a writers.py file:
import csv
from django.http import StreamingHttpResponse
@Antaris
Antaris / ServiceProviderJobFactory.cs
Created May 21, 2019 19:57
A Quartz.NET job factory using Microsoft.Extensions.DependencyInjection and scoped services
using System;
using System.Collections.Generic;
using Microsoft.Extensions.DependencyInjection;
using Quartz;
using Quartz.Spi;
public class ServiceProviderJobFactory : IJobFactory
{
private readonly IServiceProvider _rootServiceProvider;
@davidfowl
davidfowl / FormReaderExtensions.cs
Last active March 15, 2019 00:35
FormReader prototype
public static class FormReaderExtensions
{
public static async ValueTask<IFormCollection> ReadFormAsync2(this HttpRequest request)
{
var reader = request.BodyPipe;
KeyValueAccumulator accumulator = default;
while (true)
{
var result = await reader.ReadAsync();
@davidfowl
davidfowl / HostedService.cs
Created July 17, 2017 09:31
A base class that allows writing a long running background task in ASP.NET Core 2.0
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Hosting;
namespace WebApplication24
{
public abstract class HostedService : IHostedService
@javilobo8
javilobo8 / download-file.js
Last active May 13, 2025 05:55
Download files with AJAX (axios)
axios({
url: 'http://localhost:5000/static/example.pdf',
method: 'GET',
responseType: 'blob', // important
}).then((response) => {
const url = window.URL.createObjectURL(new Blob([response.data]));
const link = document.createElement('a');
link.href = url;
link.setAttribute('download', 'file.pdf');
document.body.appendChild(link);
anonymous
anonymous / Program.cs
Created February 21, 2017 22:18
public class Program
{
public static void Main(string[] args)
{
var builder = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.AddEnvironmentVariables();
IConfigurationRoot configuration = builder.Build();
@robvolk
robvolk / n_grams_code_challenge.md
Last active March 30, 2022 01:18
N-Grams Code Challenge

Foxbox Digital N-Grams Code Challenge

This is a small programming problem to test your technical ability and coding style.

Instructions

Write a simple script to generate a set of n-grams from a string of text. N-grams are a contiguous sequence of n words from a string of text, and have many applications from full-text search indexes to machine learning.

You'll generate a set of every permutation of contiguous n-grams from a string of text, from 1-gram to n-grams where n is the number of words in the string

Example