A "Best of the Best Practices" (BOBP) guide to developing in Python.
- "Build tools for others that you want to be built for you." - Kenneth Reitz
- "Simplicity is alway better than functionality." - Pieter Hintjens
| from myapp.utils import set_current_user | |
| class CurrentUserMiddleware: | |
| def process_request(self, request): | |
| set_current_user(getattr(request, 'user', None)) | |
| #!/bin/sh | |
| # UFW blocks for China, Korea, Malaysia, Phillipines, Singapore, Thailand and Vietnam netblocks | |
| # Based on http://www.wizcrafts.net/chinese-iptables-blocklist.html | |
| # Cambodia (KH) | |
| ufw deny from 114.134.184.0/21 to any port 22 | |
| # Chinese (CN) IP addresses follow: | |
| ufw deny from 1.192.0.0/13 to any port 22 | |
| ufw deny from 1.202.0.0/15 to any port 22 |
| def get_count(q): | |
| count_q = q.statement.with_only_columns([func.count()]).order_by(None) | |
| count = q.session.execute(count_q).scalar() | |
| return count | |
| q = session.query(TestModel).filter(...).order_by(...) | |
| # Slow: SELECT COUNT(*) FROM (SELECT ... FROM TestModel WHERE ...) ... | |
| print q.count() |
Python syntax here : 2.7 - online REPL
Javascript ES6 via Babel transpilation - online REPL
import mathwhile true; do
./adb shell input swipe 100 400 4000 400 400;
done| image: node:latest | |
| cache: | |
| paths: | |
| - node_modules/ | |
| before_script: | |
| - npm install | |
| stages: |
As websites become more JavaScript heavy, it's harder to automate things like screenshotting for archival purposes. I've seen examples and suggestions to use PhantomJS for visual testing/archiving of websites, but have run into issues such as the non-rendering of webfonts. I've never tried out Selenium until today...and while I'm not thinking about performance implications yet, Selenium seems far more accurate than PhantomJS...which makes sense since it actually opens a real browser. And it's not too hard to script to do complex interactions: here's an [example of how to log in to Twitter, write a tweet, upload an image, and send a tweet via Selenium and DOM element selection](https://gist.github.com/dannguyen/8a6fa49253c1d6a0eb92
Since Twitter doesn't have an edit button, it's a suitable host for JavaScript modules.
Source tweet: https://twitter.com/rauchg/status/712799807073419264
const leftPad = await requireFromTwitter('712799807073419264');| package main | |
| import ( | |
| "log" | |
| "syscall" | |
| "unsafe" | |
| ) | |
| var ( | |
| kernel32 = syscall.NewLazyDLL("kernel32.dll") |