Skip to content

Instantly share code, notes, and snippets.

Avatar

Niclas Darville ndarville

View GitHub Profile
@ndarville
ndarville / sordid-crysis2-physics
Created Mar 6, 2011
Sordid Crysis 2 variables
View sordid-crysis2-physics
variable: cc_breast_gravity
type: float
current: -9
help: Gravity for breast simulation.
variable: cc_breast_lowerDamper
type: float
current: 1
help: Lower damper for breast simulation.
@ndarville
ndarville / diff.mdown
Created Jul 23, 2012
Paul Heckel's Diff Algorithm
View diff.mdown

[Isolating Differences Between Files][paper]

Advantage over Other Algorithms

The diff output is more specific:

[I]f a whole block of text is moved, then all of it, rather than just the beginning and end, is detected as changed.

The algorithm described here avoids these difficulties. It detects differences that correspond very closely to our intuitive notion of difference.

@ndarville
ndarville / secret-key-gen.py
Created Aug 24, 2012
Generating a properly secure SECRET_KEY in Django
View secret-key-gen.py
"""
Two things are wrong with Django's default `SECRET_KEY` system:
1. It is not random but pseudo-random
2. It saves and displays the SECRET_KEY in `settings.py`
This snippet
1. uses `SystemRandom()` instead to generate a random key
2. saves a local `secret.txt`
View django-pagination.html
{% if page.has_other_pages %}
<div class="pagination">
<!-- Older page -->
{% if page.has_previous %}
<a href="?page={{ page.previous_page_number }}" title="Go to the older threads.">&lt;&nbsp;Older</a>
{% endif %}
<!-- First page -->
{% if current_page > 4 %}
<a href="?page=1">1</a>&nbsp;&#8943;
@ndarville
ndarville / settings.py
Last active Apr 13, 2020
Django on Travis CI
View settings.py
"""A basic database set-up for Travis CI.
The set-up uses the 'TRAVIS' (== True) environment variable on Travis
to detect the session, and changes the default database accordingly.
Be mindful of where you place this code, as you may accidentally
assign the default database to another configuration later in your code.
"""
import os
@ndarville
ndarville / idiomatic-d3js.mdown
Created Oct 7, 2012
Idiomatic d3.js JavaScript
View idiomatic-d3js.mdown

Assigning Variables

When assigning variables, instead of doing this:

var r = 3;
var h = 5;
var l = 10;
var padding = 15;
@ndarville
ndarville / Procfile
Created Nov 12, 2012
Django on Heroku
View Procfile
web: gunicorn myproject.wsgi -b 0.0.0.0:$PORT
# web: sh ...
View sublime_settings.js
{
"color_scheme": "Packages/Color Scheme - Default/Twilight.tmTheme",
"tab_size": 4,
"translate_tabs_to_spaces": true,
"trim_trailing_white_space_on_save": true,
"ensure_newline_at_eof_on_save": true,
"default_line_ending": "unix"
@ndarville
ndarville / sublime_bindings.js
Created Nov 24, 2012
Sublime Text 2 Key Bindings
View sublime_bindings.js
[
// Swaps the default behaviour of copy-pasting code
// to automatically indent pasted code properly
// Mac
{ "keys": ["super+v"], "command": "paste_and_indent" },
{ "keys": ["super+shift+v"], "command": "paste" },
// Windows
{ "keys": ["ctrl+v"], "command": "paste_and_indent" },
{ "keys": ["ctrl+shift+v"], "command": "paste" }
]
@ndarville
ndarville / installed_apps_order_test.py
Created Nov 30, 2012
Testing the order of your installed Django apps
View installed_apps_order_test.py
from django.conf import settings
from django_nose import FastFixtureTestCase as TestCase
def get_apps():
apps = {}
for i, app in enumerate(settings.INSTALLED_APPS):
apps[app] = i
You can’t perform that action at this time.