Skip to content

Instantly share code, notes, and snippets.

@mstepniowski
mstepniowski / letterpress.py
Created October 28, 2012 10:34
Python helps you play Letterpress
"""
Python helps you play `Letterpress <http://www.atebits.com/letterpress/>`_.
Requires `NLTK library <http://nltk.org/>`_ and cmudict corpus.
You can install the latter by executing the following two lines in Python shell:
>>> import nltk
>>> nltk.download()
I'd consider it cheating, though!
@mstepniowski
mstepniowski / getReversed.js
Created July 30, 2011 13:05
getReversed - A solution to one of the problems on meet.js Warsaw
function getReversed (str) {
var i, idx, result = [];
for (i = 0; i < str.length; ++i) {
idx = (i % 2) ? (str.length - Math.ceil((i + 1) / 2)) : Math.ceil(i / 2);
result.push(str[idx]);
}
return result.join('');
}
@mstepniowski
mstepniowski / fullscreen-lion.diff
Created July 20, 2011 22:19
Add Lion-based fullscreen mode to Emacs 24
diff --git a/lisp/term/ns-win.el b/lisp/term/ns-win.el
index 447d7fd..27bba4a 100644
--- a/lisp/term/ns-win.el
+++ b/lisp/term/ns-win.el
@@ -929,6 +929,11 @@ See the documentation of `create-fontset-from-fontset-spec' for the format.")
(add-to-list 'window-system-initialization-alist '(ns . ns-initialize-window-system))
+(declare-function ns-toggle-fullscreen-internal "nsfns.m" ())
+(defun ns-toggle-fullscreen ()
@mstepniowski
mstepniowski / javascript.el
Created June 17, 2011 13:30
node-jslint configuration for flymake
(require 'flymake)
(defun flymake-jslint-init ()
(let* ((temp-file (flymake-init-create-temp-buffer-copy
'flymake-create-temp-inplace))
(local-file (file-relative-name
temp-file
(file-name-directory buffer-file-name))))
;; Change it to path of the jslint.js executable file on your system
(list "/Users/zuber/node_modules/jslint/bin/jslint.js" (list local-file))))
@mstepniowski
mstepniowski / wyprawy.pro
Last active September 25, 2015 22:48
Trip planner in Prolog
%#!/usr/bin/env swipl -q -g main -s
%
% ^ Uncomment the line above and make this file executable
% to turn it into a valid SWI Prolog script
%
% (c) Marek Stepniowski, 222149 <marek@stepniowski.com>
:- dynamic edge/5.
% -----------------------
% Application entry point
# Required libraries:
#
# * vobject <http://vobject.skyhouseconsulting.com/>
#
# Copyright (C) 2011 Marek Stepniowski <marek@stepniowski.com>
#
# This program is free software. It comes without any warranty, to
# the extent permitted by applicable law. You can redistribute it
# and/or modify it under the terms of the Do What The Fuck You Want
# To Public License, Version 2, as published by Sam Hocevar. See
# -*- coding: utf-8 -*-
# Works on the `output.xml` generated by running `pdf2txt.py -o output.xml FILE`,
# where FILE is the programme of Science Festival in Warsaw in PDF.
#
# Required libraries:
#
# * vobject <http://vobject.skyhouseconsulting.com/>
# * lxml <http://codespeak.net/lxml/>
#
# Script `pdf2txt.py` is part of package PDFMiner <http://www.unixuser.org/~euske/python/pdfminer/index.html>.
from annoying.decorators import render_to
@render_to('template.html')
def foo(request):
bar = Bar.object.all()
return {'bar': bar}
# equals to
from django.views.generic.simple import direct_to_template
# Create your views here.
from django.shortcuts import render_to_response
from gallery.models import Gallery
def gallery_list(request):
galleries = Gallery.objects.all()
return render_to_response('gallery/gallery_list.html', {'galleries': galleries})
from django.db import models
from django.contrib.auth.models import User
class Gallery(models.Model):
title = models.CharField( max_length=80)
owner = models.ForeignKey(User)
created_at = models.DateTimeField(auto_now_add=True)
class Meta:
ordering = ['title', 'created_at']