Skip to content

Instantly share code, notes, and snippets.

@rlander
rlander / renderer.py
Created February 23, 2012 19:59
renderer
map = {
'title': 'h1'
'body' : 'p'
}
node = extract(d, map)
node['title'] = entry.title
node['body'] = entry.body
@rlander
rlander / gist:1941157
Created February 29, 2012 14:17
Sublime Text 2 - Useful Shortcuts

Sublime Text 2 – Useful Shortcuts (Mac)

Loosely ordered with the commands I use most towards the top. Sublime also offer full documentation.

Editing

Cmd+C copy current line (if no selection)
Cmd+X cut current line (if no selection)
Ctrl+⇧+K delete line
Cmd+↩ insert line after
@rlander
rlander / hiccup-demo.clj
Created April 17, 2012 19:45
Old hiccup demo
(ns hiccup-demo
(:use hiccup))
(def core-examples
["Simple tags" [:br]
"Tags with content" [:span "baz"]
"Tag with attributes" [:span {:id "foo" :class "bar"} "baz"]
"Attribute shortcuts" [:span#foo.bar "baz"]
"Encode HTML character entities" '(escape-html "<\"foo\"&\"bar\">")
"Shortcut for escape-html" '(h "<\"foo\"&\"bar\">")])
@rlander
rlander / gist:2564857
Created May 1, 2012 04:00 — forked from travist/gist:2562314
Warning: remote port forwarding failed for listen port 9000
Do the following to fix this error.
ttidwell@a:~:->$ sudo lsof|grep 9000
sshd 31533 ttidwell 9u IPv6 506614 0t0 TCP [::1]:9000 (LISTEN)
sshd 31533 ttidwell 10u IPv4 506615 0t0 TCP localhost:9000 (LISTEN)
ttidwell@a:~:->$ kill 31533
@rlander
rlander / gist:2952567
Created June 19, 2012 06:16 — forked from osiloke/gist:1138798
Generating URLs to crawl from outside a Scrapy spider
from scrapy import log
from scrapy.item import Item
from scrapy.http import Request
from scrapy.contrib.spiders import XMLFeedSpider
def NextURL():
"""
Generate a list of URLs to crawl. You can query a database or come up with some other means
Note that if you generate URLs to crawl from a scraped URL then you're better of using a
@rlander
rlander / scrapy.py
Created July 14, 2012 02:04 — forked from samliu/scrapy.py
manage command for django to call scrapy
# Enable us to call scrapy from manage.py
from __future__ import absolute_import
from django.core.management.base import BaseCommand
class Command(BaseCommand):
def run_from_argv(self, argv):
self._argv = argv
self.execute()
{
{I have|I've} been {surfing|browsing} online more than {three|3|2|4} hours today, yet I never found any interesting article like yours. {It's|It
is} pretty worth enough for me. {In my opinion|Personally|In my view}, if all {webmasters|site owners|website owners|web owners} and bloggers made good content as
you did, the {internet|net|web} will be {much more|a lot more}
useful than ever before.|
I {couldn't|could not} {resist|refrain from} commenting. {Very well|Perfectly|Well|Exceptionally well} written!|
{I will|I'll} {right away|immediately} {take hold of|grab|clutch|grasp|seize|snatch}
your {rss|rss feed} as I {can not|can't} {in finding|find|to find} your {email|e-mail} subscription {link|hyperlink} or {newsletter|e-newsletter} service. Do {you have|you've} any?
{Please|Kindly} {allow|permit|let} me {realize|recognize|understand|recognise|know} {so that|in order that} I {may just|may|could} subscribe.
Thanks.|
  1. Add Heroku to your Gemfile and bundle install.
  2. Create your Heroku app. This will only work with their (currently-beta) 'cedar' stack, so you have to heroku create --stack=cedar.
  3. Create a Procfile for your bot. This tells Heroku how to run your worker. In our case, the bot is bot.rb, so the only line in the Procfile is cinch: bundle exec ./bot.rb
  4. Commit and push to Heroku.
  5. You do not want a Web worker running, so heroku scale web=0 cinch=1. This also sets up your deployments to restart the bot.
@rlander
rlander / reencode.py
Created April 3, 2014 20:51
Script to reencode iso-8859-1subtitles to UTF-8r
import sys, getopt
import codecs
BLOCKSIZE = 1048576
def main(argv):
inputfile = ''
outputfile = ''
try:
opts, args = getopt.getopt(argv,"hi:o:",["ifile=","ofile="])
except getopt.GetoptError:
@rlander
rlander / gist:9987644
Created April 5, 2014 04:50
model query from jinja macros
env.globals['m'] = sys.modules['application.models']
Assuming your application is already fully imported if you render a
template, your macro can do something like this::
{% macro recent_news(num) %}
{% set news = m.NewsModel.select(...).limit(num) %}
...
{% endmacro %}