Skip to content

Instantly share code, notes, and snippets.

View srugano's full-sized avatar
😀
I may be slow to respond.

Allan Stockman RUGANO srugano

😀
I may be slow to respond.
View GitHub Profile
@davemerwin
davemerwin / DJANGO-HTMX Class Based View Request Grab to Change Templates
Last active May 23, 2023 15:34
An example of a Class Based View using django-htmx to determine what template to return
class AddImage(LoginRequiredMixin, CreateView):
"""
adds a image
"""
form_class = ImageForm
model = Image
def get_template_names(self):
if self.request.htmx:
@srugano
srugano / playbook.yml
Created January 13, 2019 15:19 — forked from marklit/playbook.yml
Setup a load-balanced, two-node Django cluster
---
- name: SSH tightening
hosts: all
sudo: True
tasks:
- name: Disable root's ssh account
action: >
lineinfile
dest=/etc/ssh/sshd_config
@tanaikech
tanaikech / submit.md
Last active October 29, 2023 01:46
Uploading Multiple Files From Local To Google Drive using Google Apps Script

Uploading Multiple Files From Local To Google Drive using Google Apps Script

This is a sample script for uploading multiple files from local PC to Google Drive using Google Apps Script. The dialog, sidebar and Web Apps can be used as the GUI interface.

Sample 1

In this sample, the following flow is run.

  1. Select files at browser.
  2. Upload the files every file.
  3. Save each file in Google Drive.
@hakib
hakib / custom_django_checks.py
Last active April 10, 2024 13:01
Custom django checks using Django check framework, inspect and ast.
"""
Custom django checks.
H001: Field has no verbose name.
H002: Verbose name should use gettext.
H003: Words in verbose name must be all upper case or all lower case.
H004: Help text should use gettext.
H005: Model must define class Meta.
H006: Model has no verbose name.
H007: Model has no verbose name plural.
@raphaelm
raphaelm / storage.py
Created March 20, 2018 21:08
NanoCDN Storage driver
import hashlib
import urllib.parse
import os
from io import BytesIO, StringIO
import requests
from django.conf import settings
from django.core.exceptions import SuspiciousFileOperation
from django.core.files import File
@victorono
victorono / remove_duplicates.py
Last active April 26, 2024 17:57
Django - remove duplicate objects where there is more than one field to compare
from django.db.models import Count, Max
unique_fields = ['field_1', 'field_2']
duplicates = (
MyModel.objects.values(*unique_fields)
.order_by()
.annotate(max_id=Max('id'), count_id=Count('id'))
.filter(count_id__gt=1)
)
@kyle-eshares
kyle-eshares / models.py
Created October 15, 2016 18:01
Strict ForeignKeys
from __future__ import unicode_literals
from django.db import models
from django.db.models.fields.related_descriptors import ForwardManyToOneDescriptor # noqa
class RelationNotLoaded(Exception):
pass
@brock
brock / psql-with-gzip-cheatsheet.sh
Last active April 10, 2024 10:53
Exporting and Importing Postgres Databases using gzip
# This is just a cheat sheet:
# On production
sudo -u postgres pg_dump database | gzip -9 > database.sql.gz
# On local
scp -C production:~/database.sql.gz
dropdb database && createdb database
gunzip < database.sql.gz | psql database
@renestalder
renestalder / README.md
Last active May 3, 2024 14:08
Unfollow all on Facebook

Facebook: Unfollow people and pages

See comments section for more up-to-date versions of the script. The original script is from 2014 and will not work as is.

  1. Open news feed preferences on your Facebook menu (browser)
  2. Click people or pages
  3. Scroll down (or click see more) until your full list is loaded
  4. Run the script in your browser console

Facebook will block this feature for you while you use it, depending on how much entities you try to unfollow. It automatically unblocks in a couple of hours and you will be able to continue.

Build a scalable Twitter clone with Django and GetStream.io

In this tutorial we are going to build a Twitter clone using Django and GetStream.io, a hosted API for newsfeed development.

We will show you how easy is to power your newsfeeds with GetStream.io. For brevity we leave out some basic Django-specific code and recommend you refer you to the Github project for the complete runnable source code. At the end of this tutorial we will have a Django app with a profile feed, a timeline feed, support for following users, hashtags and mentions.

I assume that you are familiar with Django. If you're new to Django the [official tutorial] (https://docs.djangoproject.com/en/2.0/intro/) explains it very well.