Skip to content

Instantly share code, notes, and snippets.

View csrutil's full-sized avatar

TSAO csrutil

View GitHub Profile
@csrutil
csrutil / hurt.markdown
Last active December 2, 2015 07:40
牢记历史,受伤了才知道痛

牢记历史,受伤了,才知道痛: (

has_many :combinations, -> { order "activity_combinations.score desc" }, class_name: 'ActivityCombination'
has_many :inspiration_activities, -> { where('inspiration_activities.ignored = false') }, through: :combinations
@csrutil
csrutil / systemd-nginx.md
Created December 6, 2015 07:46
The NGINX HTTP and reverse proxy server
/lib/systemd/system/nginx.service

[Unit]
Description=The NGINX HTTP and reverse proxy server
After=syslog.target network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
PIDFile=/run/nginx.pid
@csrutil
csrutil / paginate_from_sql.markdown
Created December 25, 2015 07:18
paginate_from_sql
def paginate_from_sql(model, sql, total, per_page)
  @object_pages = Paginator.new self, total, per_page, @params['page']
  @objects = model.find_by_sql(sql + " LIMIT #{per_page} " +
                               "OFFSET #{@object_pages.current.to_sql[1]}")
end
整合了可以搜索到的列表,有广告过滤等,自行添加Proxy信息即可使用。
目前使用无恙。
不定期更新。
感谢各位分享者。
$ rails s -b 0.0.0.0 -p 3000
$ ls
pf.conf
$ cat pf.conf
# pf "rules file"
# by Chris Van Patten
#
# This example redirects port 80 to 3000.
# Replace 3000 with your desired port.
@csrutil
csrutil / database-backup.md
Last active March 17, 2016 09:08
database backup
#!/bin/bash

HOSTNAME="localhost"
USERNAME="username"
PASSWORD='PASSWORD`'
DATABASE="DATABASE"

# mysql or postgresql
SERVER_TYPE="postgresql"
text = "abc"
Client = Elasticsearch::Client.new host: 'localhost:9200'

body = Client.perform_request("GET", "/_analyze", {}, {analyzer: "ik_smart", text: text}).body

cs = body["tokens"].map{|token| token["token"] if (token["type"] == "CN_WORD" && token["token"].size > 1)}.reject(&:nil?)
cs = body["tokens"].map{|token| token["token"] if token["type"] == "CN_WORD"}.reject(&:nil?)

cs.group_by{|x| x}.sort_by{|k, v| - v.count}
#!/usr/bin/ruby
# Create display override file to force Mac OS X to use RGB mode for Display
# see http://embdev.net/topic/284710
require 'base64'
data=`ioreg -l -d0 -w 0 -r -c AppleDisplay`
edids=data.scan(/IODisplayEDID.*?<([a-z0-9]+)>/i).flatten
vendorids=data.scan(/DisplayVendorID.*?([0-9]+)/i).flatten
mysqldump -u USER -p --single-transaction --quick --lock-tables=false DATABASE | gzip > OUTPUT.gz

Creating a redis Module in 15 lines of code!

A quick guide to write a very very simple "ECHO" style module to redis and load it. It's not really useful of course, but the idea is to illustrate how little boilerplate it takes.

Step 1: open your favorite editor and write/paste the following code in a file called module.c

#include "redismodule.h"
/* ECHO <string> - Echo back a string sent from the client */
int EchoCommand(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) {