Skip to content

Instantly share code, notes, and snippets.

@dnozay
dnozay / screen-resolution.sh
Created October 5, 2014 00:17
use xrandr to properly fit Sceptre 40" display over HDMI output.
#!/bin/bash
# fix display for Sceptre 40" X405BV-FHD3 on Fedora 20.
# this is done by turning on the underscan feature with xrandr.
# usage: call this script from within /etc/gdm/Init/Default.
xrandr --output HDMI-1 \
--set "underscan" on \
--set "underscan hborder" 50 \
--set "underscan vborder" 30
@dnozay
dnozay / grab.c
Created October 8, 2014 21:15
grab: move a process from one tty to another (source: http://www.ucc.asn.au/~dagobah/things/grab.c)
/*
* grab: move a process from one tty to another.
* Version 0.0.1
*
* Written by Bernard Blackham. This code is in the public domain.
*
* This is a very quick hack and quite a mess. Needs a lot of polish. It is
* also nowhere near perfect.
*
* Usage:
@dnozay
dnozay / tests.rb
Last active August 29, 2015 14:08
Jekyll filters to help with hashes.
@context = { 'myhash' => { 'b' => 'B', 'a' => 'A', 'c' => 'C' } }
@template = Liquid::Template.parse("{{ myhash | keys | to_ul }}")
@template.render(@context) # => "<ul><li>b</li><li>a</li><li>c</li></ul>"
@template = Liquid::Template.parse("{{ myhash | keys | sort | to_ul }}")
@template.render(@context) # => "<ul><li>a</li><li>b</li><li>c</li></ul>"
@dnozay
dnozay / .travis.yml
Created October 25, 2014 23:28
Travis config file for simple project using tox.
language: python
python:
- "2.7"
install:
- pip install tox
script:
- tox
[tox]
envlist = py{26,27,33}
[testenv]
commands = python setup.py test
@dnozay
dnozay / triggers.sql
Created November 18, 2014 21:16
mirror bugzilla milesones into a custom field cf_support_milestone.
-- mirror the bugzilla milestones in another picklist
-- developers have their own target milestones (the default picklist for milestones)
-- support engineers have their own support milestones which is a custom field.
-- milestones -> cf_support_milestone
delimiter //
CREATE TRIGGER cf_milestones_insert
AFTER INSERT ON milestones
FOR EACH ROW
@dnozay
dnozay / autoreload.py
Last active August 29, 2015 14:10
Autoreload features (code snippets)
# code snippet from django.utils.autoreload (BSD license)
# https://github.com/django/django/blob/master/django/utils/autoreload.py
def code_changed():
global _mtimes, _win
for filename in gen_filenames():
stat = os.stat(filename)
mtime = stat.st_mtime
if _win:
mtime -= stat.st_ctime
@dnozay
dnozay / angular-moment.md
Last active August 29, 2015 14:11
angular momentjs directive.

If we detect angular is present, we can expose a directive:

<ANY moment date="scope.myDate" format="'lll'"></ANY>
'use strict';

/**
@dnozay
dnozay / mixins.py
Created January 8, 2015 08:21
django-rest-framework mixin that caches serialization output with cache key based on DateTimeField(auto_now=True)
# License: MIT
# django-rest-framework mixin
class CachedReprMixin(serializers.ModelSerializer):
'''
mixin for ModelSerializer subclass whose model has a 'modified' field.
assuming the model has a 'modified' field:
modified = models.DateTimeField(auto_now=True)
@dnozay
dnozay / creation.py
Created January 9, 2015 07:16
django 1.6, add unique_together constraint name.
class CustomDatabaseCreation(BaseDatabaseCreation):
def sql_create_model(self, model, style, known_models=set()):
final_output, pending_references = super(CustomDatabaseCreation, self).sql_create_model(model, style, known_models)
# get output generated by parent class for unique_together.
for field_constraints in opts.unique_together:
line = (' ' + style.SQL_KEYWORD('UNIQUE') + ' (%s)' %
", ".join(
[style.SQL_FIELD(qn(opts.get_field(f).column))
for f in field_constraints]))