This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
latest_comments = Comments.objects.order_by('date')[:10] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<ul> | |
{% for comment in latest_comments %} | |
<li><a href="{{ comment.get_absolute_url }}">{{ comment.title }}</a></li> | |
{% endfor %} | |
</ul> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# run this in a test directory using a regular bash prompt to get an idea of how virtual environments would work, roughly | |
alias npm-env-init="mkdir ./env; mkdir ./env/packages; echo 'root = ./env/packages' > ./env/.npmrc; echo 'Created a new virtual environment for node packages in ./env'" | |
alias npm-env-workon="export npm_config_userconfig=./env/.npmrc; export NODE_PATH=./env/packages;" | |
alias npm-env-ls="nvp workon; nvm ls active;" | |
# we make a virtual environment | |
npm-env-init | |
# we switch to that virtual environment | |
npm-env-workon | |
# we install a package | |
npm install underscore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sandbox import models | |
from tastypie import fields | |
from apibase.resources import CamayakModelResource | |
from django.conf.urls.defaults import url | |
class ModelResource(CamayakModelResource): | |
def override_urls(self): | |
urls = [] | |
for name, field in self.fields.items(): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
stylus = require 'stylus' | |
module.exports = (app) -> | |
app.get /^(.*\.styl)$/, (req, res) -> | |
stylus(req.file.content).render (err, css) -> | |
if err | |
res.send err | |
else | |
res.contentType 'text/css' | |
res.send css |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fs = require 'fs' | |
routing = require './utils' | |
postDir = 'posts' | |
shortlinksFile = 'shortlinks.conf' | |
stream = fs.createWriteStream shortlinksFile, {flags: 'a'} | |
shortlinks = (fs.readFileSync shortlinksFile, 'utf8').replace(/\s+$/).split '\n' | |
tail = shortlinks.slice(-1)[0] | |
counter = parseInt (tail.match /(\d+)\s/)?[1] or 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
page = require('webpage').create() | |
page.onConsoleMessage = (msg) -> | |
console.log 'CONSOLE:' + msg | |
page.onResourceRequested = (params, request) -> | |
isJavaScript = params['url'].slice(-3) is '.js' | |
isJQuery = (params['url'].indexOf 'jquery') isnt -1 | |
if isJavaScript and not isJQuery |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encoding: utf-8 | |
""" | |
First, run `authenticate.py` which will launch a new browser window that | |
will let you give this app permission to access your Google Analytics | |
data. The OAuth2 token will work for one hour and will be in | |
`ga-oauth2-token.json`. | |
Then, just run this file using `python analytics.py`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### An interesting thing about news website homepages is that, while they | |
change all the time, the media on them doesn't change quite that fast: both | |
actual images but also stylesheets, javascript, logos and so on. Therefore, | |
when archiving these pages, it is possible to achieve significant space | |
savings by modifying the links to every image or other resource in the HTML to | |
instead refer to a file path that's a hash of the file's content: a type of | |
content-addressable storage. | |
The storage size can be further reduced by storing e.g. a day's worth of HTML | |
for one page (e.g. one fetch every hour) into a single lzip file, as LZMA can |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# encoding: utf-8 | |
""" | |
This on the command line | |
echo '{"d": 44}' | ./input.py --a 33 --b 44 --c | |
turns into this argument passed to your function | |
OlderNewer