Skip to content

Instantly share code, notes, and snippets.

@xd547
xd547 / .vimrc
Created April 8, 2019 01:42
.vimrc whith powerline
set background=dark
colors solarized
let g:airline_theme='solarized'
let g:airline_powerline_fonts = 1
let g:airline_left_sep = ''
let g:airline_left_alt_sep = ''
let g:airline_right_sep = ''
let g:airline_right_alt_sep = ''
let g:airline_symbols.branch = ''
@xd547
xd547 / .vimrc
Created April 8, 2019 01:38
.vimrc
" encoding
set encoding=utf-8
set fileencoding=utf-8
" preference
syntax on
set ai
set shiftwidth=2
set tabstop=2
set softtabstop=2
@xd547
xd547 / delete_time_machine_localsnapshot.sh
Last active November 27, 2018 11:22
Delete all localsnapshots expect last one.
#!/bin/sh
echo 'Delete all local snapshots expect last one.'
for date in $(tmutil listlocalsnapshots / | cut -d. -f4 | sed '$d')
do
tmutil deletelocalsnapshots $date
done
echo 'Thinlocalsnapshots'
tmutil thinlocalsnapshots /
@xd547
xd547 / temp.sh
Created November 6, 2018 17:08
Get Raspberry Pi temperature
#!/bin/sh
GetCPUTemp() {
value=`cat /sys/class/thermal/thermal_zone0/temp | tr -d '\n'`
cpu_temp=`awk "BEGIN {print $value/1000.0}"`
echo "$cpu_temp"
}
GetGPUTemp() {
gpu_temp=`vcgencmd measure_temp |sed -e "s/temp=//g" | sed -e "s/'C//g"`
# https://github.com/gpakosz/.tmux
# (‑●‑●)> dual licensed under the WTFPL v2 license and the MIT license,
# without any warranty.
# Copyright 2012— Gregory Pakosz (@gpakosz).
# -- navigation ----------------------------------------------------------------
# if you're running tmux within iTerm2
# - and tmux is 1.9 or 1.9a
@xd547
xd547 / downloads.js
Created November 11, 2016 06:43 — forked from anonymous/downloads.js
ASUS DownloadMaster batch downloads
// 1. open DownloadMaster in chrome
// 2. use the code in chrome console
urls = ["", ""] //urls array
addDownload = function(url) {
showPanel();
document.getElementById("HTTP_usb_dm_url").value = url;
dm_add_status();
}
@xd547
xd547 / jquery_object_compare.js
Created March 4, 2014 02:43
jQuery Object compare
// from http://stackoverflow.com/questions/2436966/how-would-you-compare-jquery-objects
// You need to compare the raw DOM elements, e.g.:
if ($(this).parent().get(0) === $('body').get(0))
// or
if ($(this).parent()[0] === $('body')[0])
@xd547
xd547 / validates.rb
Created January 10, 2014 10:15
Rails model 验证唯一,但不包含相应属性为空的情况
validates :domain, uniqueness: { unless: Proc.new { |shop| shop.domain == '' or shop.domain == nil } }
# This is an example of how to use database_cleaner gem and
# RSpec tags to make `after_commit` hook play nice with
# `use_transactional_fixtures`.
# Simply mark the specs that use after_commit with
# `:uses_after_commit` tag.
# ...
require 'database_cleaner'

Routes

小心地使用 Match(Rails 3 已实现)

Rails 3 提供了 match 方法供我们自定义 routes,然而我们要小心使用它以避免“跨站脚本攻击”(XSS Attack)。比如像这样的 routes:

注:(r3 代表 Rails 3,r4 代表 Rails 4)

# routes.rb