Skip to content

Instantly share code, notes, and snippets.

@devStepsize
devStepsize / progress_bar.py
Created February 7, 2016 17:49 — forked from matthieualouis/progress_bar.py
Progress bar template for python
import progressbar
pbar = progressbar.ProgressBar(maxval=PLACEHOLDER)
pbar.start()
for i in range(PLACEHOLDER):
pbar.update(i)
pbar.finish()
@devStepsize
devStepsize / pg_dump_table.sql
Last active March 28, 2019 09:13
PostgreSQL pg_dump syntax for a single table
pg_dump -Fc -v -U user_name -d db_name -t table_name > /path/to/file.bak
@devStepsize
devStepsize / new file
Created February 23, 2016 13:33
file
dfs
@devStepsize
devStepsize / 0_reuse_code.js
Created February 25, 2016 13:26
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@devStepsize
devStepsize / create_project.sh
Created April 12, 2016 15:26
Create a template Django project from the command line. This will create the following structure: mysite/ manage.py mysite/ __init__.py settings.py urls.py wsgi.py
django-admin startproject mysite
@devStepsize
devStepsize / run_django_server.py
Created April 12, 2016 15:28
Launches the server, make sure you are in the right directory. You should see the following output if done correctly: Performing system checks... System check identified no issues (0 silenced). You have unapplied migrations; your app may not work properly until they are applied. Run 'python manage.py migrate' to apply them. April 10, 2016 - 15:5…
python manage.py runserver
@devStepsize
devStepsize / simple_views.py
Last active April 12, 2016 17:04
Example view in Django
from django.http import HttpResponse
from django.views.generic import View
class MyView(View):
def get(self, request, *args, **kwargs):
return HttpResponse('Hello, World!')
@devStepsize
devStepsize / django_models.py
Created April 12, 2016 15:52
Example Django models class
from django.db import models
class Question(models.Model):
question_text = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published')
class Choice(models.Model):
question = models.ForeignKey(Question, on_delete=models.CASCADE)
@devStepsize
devStepsize / django_template_debug
Created April 12, 2016 16:23
Useful template to show which queries are running to load a page. This requires the following steps first: 1.Have 'django.core.context_processors.debug' in your TEMPLATE_CONTEXT_PROCESSORS setting (it was there in the default settings, last time I checked). 2. Have your current IP in your INTERNAL_IPS setting. 3. Use RequestContext when renderin…
{% if debug %}
<div id="debug">
<h2>Queries</h2>
<p>
{{ sql_queries|length }} Quer{{ sql_queries|pluralize:"y,ies" }}
{% ifnotequal sql_queries|length 0 %}
(<span style="cursor: pointer;" onclick="var s=document.getElementById('debugQueryTable').style;s.display=s.display=='none'?'':'none';this.innerHTML=this.innerHTML=='Show'?'Hide':'Show';">Show</span>)
{% endifnotequal %}
</p>
<table id="debugQueryTable" style="display: none;">
@devStepsize
devStepsize / django_forms.py
Created April 12, 2016 16:31
Simple form handling with Django
from django import forms
class BandContactForm(forms.Form):
subject = forms.CharField(max_length=100)
message = forms.CharField()
sender = forms.EmailField()
cc_myself = forms.BooleanField(required=False)