( Source: the mongoid cheatsheet )
class User
include Mongoid::Document
# coding: utf-8 | |
# | |
# OS X 11 (macOS ) 之后不再支持 PPTP VPN. 但 Cisco IPSec VPN 不支持像 PPTP 的 | |
# /etc/ppp/ip-up 和 /etc/ppp/ip-down 一样方便j的机制来更新 chnroute 路由表。 | |
# 这个脚本尝试在 Cisco IPSec VPN 下自动处理 chnroute, 做的主要工作是监听 syslog, | |
# 发现 IPSec VPN 连接建立或断开后去修改路由表。 | |
# | |
# NOTE: 使用前可能需要修改 CUSTOMED_ROUTE_DATA, 建议将其设为 | |
# 排除VPN子网后的 rfc1918 定义的内网IP段 | |
# |
( Source: the mongoid cheatsheet )
class User
include Mongoid::Document
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
# This script helps removing Git branches. | |
# Run it from a git repo dir. It will open the Git branches list | |
# in your favorite editor. Delete some branches from the list. | |
# Save and close the file. The script applies the changes to the repo. | |
from subprocess import call, Popen, PIPE | |
from os import getenv |
on run | |
# TODAY - Returns today's date! | |
# Create your own Service, to avoid 3rd Party software (WordService, etc.) | |
# In Automator: | |
# > Service receives 'no input' in 'any application' | |
# > Output replaces selected text | |
# Add Shortcut (e.g. Ctrl+Cmd+T - it's hard to find a free shortcut!): | |
# > Preferences > Keyboard > Keyboard Shortcuts > Services | |
# When setting up Keyboard Shortcut, *exit* the target app before testing. (It seems shortcuts are only refreshed when app is launched) | |
# Adjust 'Short' Date format |
.DS_Store |
-- http://stackoverflow.com/questions/1124603/grouped-limit-in-postgresql-show-the-first-n-rows-for-each-group | |
-- http://www.postgresql.jp/document/9.2/html/tutorial-window.html | |
CREATE TABLE empsalary ( | |
depname varchar(10) not null | |
, empno integer not null | |
, salary integer not null | |
); | |
INSERT INTO empsalary (depname, empno, salary) VALUES ('develop', 11, 5200); |
javascript:(function(window, document, undefined) {try {var selectedText = document.getSelection().toString(); if (selectedText === ''){selectedText = window.location.href;} if(selectedText !== ''){var baseQRUrl = 'http://chart.apis.google.com/chart?cht=qr&chs=300x300&chl=' + encodeURIComponent(selectedText); window.open(baseQRUrl, '_blank', 'width=400,height=400');}} catch (e) {}})(window, document); |
In tests that use a database, it's necessary to clean out the tables before each run (we don't use after so we can debug a failed test's db).
Sometimes we forget the syntax though so here's what we do:
before(function truncateDatabase (done) {
// http://docs.sequelizejs.com/en/v3/docs/raw-queries/
// https://www.postgresql.org/docs/9.3/static/sql-truncate.html
// DEV: PostgreSQL doesn't support truncating all tables via a `*`
// DEV: Our query is vulnerable to SQL injection but we can't use bind and trust our table names more/less
# lib/custom_logger.rb | |
class CustomLogger < Logger | |
def format_message(severity, timestamp, progname, msg) | |
"#{timestamp.to_formatted_s(:db)} #{severity} #{msg}\n" | |
end | |
end | |
logfile = File.open("#{Rails.root}/log/custom.log", 'a') # create log file | |
logfile.sync = true # automatically flushes data to file | |
CUSTOM_LOGGER = CustomLogger.new(logfile) # constant accessible anywhere |