Skip to content

Instantly share code, notes, and snippets.

View Copser's full-sized avatar
:octocat:
Something need doing?

p_pilipovic Copser

:octocat:
Something need doing?
View GitHub Profile
@mattseymour
mattseymour / django-secret-keygen.py
Last active September 8, 2022 23:47
Django secret key generator
"""
Pseudo-random django secret key generator.
- Does print SECRET key to terminal which can be seen as unsafe.
"""
import string
import random
from __future__ import print_function
@freakboy3742
freakboy3742 / beyond-web-2.0.rst
Last active January 1, 2016 05:51
Beyond Web 2.0 - Django and Python in the modern web ecosystem

Beyond Web 2.0 - Django and Python in the modern web ecosystem

Django is over 10 years old; but the web that it was built for doesn't really exist any more. Yes, we still need to rapidly develop database-backed websites, and we still need those sites to use AJAX, but the modern web is faced with new problems, and new challenges. Many of those challenges involve interacting with devices that aren't desktop machines, and platforms that aren't a traditional browser - places where Python isn't a first-class citizen.

Does this mean we have to abandon Django and Python for other frameworks and languages? Can we keep using Python and Django on the server side and interact with independent client side frameworks? Or can we push Python and Django into these new environments?

In this talk, Dr Russell Keith-Magee will explore the problems, and some potential solutions, to these problems.

Objectives

@bearfrieze
bearfrieze / comprehensions.md
Last active December 23, 2023 22:49
Comprehensions in Python the Jedi way

Comprehensions in Python the Jedi way

by Bjørn Friese

Beautiful is better than ugly. Explicit is better than implicit.

-- The Zen of Python

I frequently deal with collections of things in the programs I write. Collections of droids, jedis, planets, lightsabers, starfighters, etc. When programming in Python, these collections of things are usually represented as lists, sets and dictionaries. Oftentimes, what I want to do with collections is to transform them in various ways. Comprehensions is a powerful syntax for doing just that. I use them extensively, and it's one of the things that keep me coming back to Python. Let me show you a few examples of the incredible usefulness of comprehensions.

@tomysmile
tomysmile / mac-setup-redis.md
Last active June 27, 2024 00:23
Brew install Redis on Mac

type below:

brew update
brew install redis

To have launchd start redis now and restart at login:

brew services start redis
@DmytroLitvinov
DmytroLitvinov / messages.html
Last active September 13, 2021 22:18
[Django middleware for AJAX messages] Middleware for JSON responses. It adds to each JSON response array with messages from django.contrib.messages framework. It allows handle messages on a page with javascript. Django 1.10. #tags: django, python, ajax
<div id="messages">
{% for message in messages %}
<div {% if message.tags %}class="alert alert-dismissable alert-{{ message.tags }}"{% endif %}>
<a class="close" data-dismiss="alert" href="#">&times;</a>
{{ message }}
</div>
{% endfor %}
</div>
@archatas
archatas / example.html
Last active July 11, 2017 18:42
Avoid listing HTML attribute values within translatable string in Django template
{% blocktrans with username=request.user.username link=request.user.get_url_path css_class="btn btn-link" %}
Hello <a href="{{ link }}" class="{{ css_class }}">{{ username }}</a>!
{% endblocktrans %}
@ibraheem4
ibraheem4 / postgres-brew.md
Last active July 5, 2024 17:29 — forked from sgnl/postgres-brew.md
Installing Postgres via Brew (OSX)

Installing Postgres via Brew

Pre-Reqs

Brew Package Manager

In your command-line run the following commands:

  1. brew doctor
  2. brew update
@gbaman
gbaman / graphql_example.py
Created November 1, 2017 00:18
An example on using the Github GraphQL API with Python 3
# An example to get the remaining rate limit using the Github GraphQL API.
import requests
headers = {"Authorization": "Bearer YOUR API KEY"}
def run_query(query): # A simple function to use requests.post to make the API call. Note the json= section.
request = requests.post('https://api.github.com/graphql', json={'query': query}, headers=headers)
if request.status_code == 200:
@posilva
posilva / context.ex
Created March 31, 2018 23:07 — forked from ericstumper/context.ex
Guardian Authentication with Absinthe GraphQL in Elixir
defmodule Languafy.Web.Context do
@behaviour Plug
import Plug.Conn
alias Languafy.User
def init(opts), do: opts
def call(conn, _) do
case build_context(conn) do
{:ok, context} ->
"""
Django ORM Optimization Tips
Caveats:
* Only use optimizations that obfuscate the code if you need to.
* Not all of these tips are hard and fast rules.
* Use your judgement to determine what improvements are appropriate for your code.
"""
# ---------------------------------------------------------------------------