Skip to content

Instantly share code, notes, and snippets.

View huacnlee's full-sized avatar

Jason Lee huacnlee

View GitHub Profile
@huacnlee
huacnlee / gist:25731547eb72c25e44988f76504d1434
Created August 23, 2023 08:21
Go 代码 Aho-Corasick 算法从文本中匹配关键词
package main
import (
"fmt"
"time"
)
type Node struct {
children map[rune]*Node
fail *Node
@huacnlee
huacnlee / import_file_to_gridfs.rake
Created February 25, 2011 09:26
将 File System 的上传文件导入到 Mongodb 的 GridFS 里面
# coding: UTF-8
#
# 以下为 Rake 任务,功能是将普通文件系统里面的东西转移到 MongoDB GridFS 里面
# 此代码片段来自于 Homeland 项目: https://github.com/huacnlee/homeland/tree/mysql
# 场景:
# 老架构 Linux File Store, Paperclip, hash 目录:"https://github.com/huacnlee/homeland/blob/ca0bdd8ab26da7b780e2dae7eba12b79f41e6d65/config/initializers/paperclip_hashpath.rb"
# 新架构 Mongodb GridFS, Garrierwave, 继续沿用 Paperclip 目录兼容: https://github.com/huacnlee/homeland/tree/7100ce4c506cc2c4387f25e50c533e5bbcac6cc2/app/uploaders
# 整个过程不会修改任何原始数据库和上传文件
#
require 'mongo'
require('parser')
input = "function foo() {}"
buf = Parser::Source::Buffer.new("test", 1, source: input)
tr = Parser::Source::TreeRewriter::new(buf)
def range(buf, start_pos, end_pos)
Parser::Source::Range::new(buf, start_pos, end_pos)
end
@huacnlee
huacnlee / input.txt
Created October 25, 2022 06:52
Pest grammar example for match nested parn
(hello(world) 你好 (var))
(hello2(world))
{
"recommendations": [
"aeschli.vscode-css-formatter",
"ahmadalli.vscode-nginx-conf",
"aliariff.vscode-erb-beautify",
"be5invis.toml",
"bierner.markdown-preview-github-styles",
"bradlc.vscode-tailwindcss",
"bradymholt.pgformatter",
"crystal-lang-tools.crystal-lang",
@huacnlee
huacnlee / dingtalk-qrcode-login.rb
Last active August 1, 2021 10:12
实现钉钉扫描登录 Ruby
# 实现钉钉扫描登录
#
# 从钉钉 “移动应用接入 - 扫码登录” 开通,并获得 app_id 和 app_secret
# 开通:https://open-dev.dingtalk.com/#/loginMan
#
# 这个流程只能实现简单登录,拿到用户 nick,dingId, openid, unionid
# 文档:https://ding-doc.dingtalk.com/doc#/serverapi2/etaarr
require "openssl"
require "base64"
require "faraday"
@huacnlee
huacnlee / nginx.conf
Created September 14, 2011 13:50
Nginx http proxy cache to mirror of Rubygems.org
# 在本地服务器建立 rubygems.org 的镜像缓存,以提高 gem 的安装速度
# 此配置设置缓存过期为1天,也就是说,新上的 gem 无法马上安装
# 做这个起什么作用?
# rubygems 的很多资源文件是存放到 Amazon S3 上面的,由于 GFW 对某些 S3 服务器又连接重置或丢包,导致 gem 安装异常缓慢或有时候根本无法连接安装。
# 而通过这种跳板的方式可以很好的解决这个问题,当然前提是 Nginx反向代理 服务器需要在国外
proxy_cache_path /var/cache/rubygems levels=1:2 keys_zone=RUBYGEMS:10m
inactive=24h max_size=1g;
server {
listen 80;
<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg style="border-radius: 0;" width="324" height="120" viewBox="0 0 324 120" version="1.1" xmlns="http://www.w3.org/2000/svg">
<g>
<defs>
<linearGradient id="avatar" x1="0" y1="0" x2="1" y2="1">
<stop offset="0%" stop-color="#ff6a00"/>
<stop offset="100%" stop-color="#ff6a00"/>
</linearGradient>
</defs>
-- 创建名称为readonly的只读用户:
create user social with password '123456';
-- 然后把在public这个schema下现有的所有表的select权限赋给readobly,并执行下面的SQL命令:
grant select on select tables in schema public to social;
-- 上面的命令只是把现有的表的权限给了readonly用户,如果此时创建了表,readonly用户还是不能读,需要使用下面的SQL把所建表的select权限也给用户readonly:
alter default privileges in schema public grant select on tables to social;
@huacnlee
huacnlee / config.yml
Created December 6, 2018 06:07
CircleCI with Ruby 2.5, Rails 5.2, Yarn, Webpacker, Sass, PostgreSQL, Redis, ElasticSearch full example.
version: 2
jobs:
build:
docker:
- image: circleci/ruby:2.5.3-node-browsers
environment:
RAILS_ENV: test
DATABASE_URL: postgres://postgres@127.0.0.1:5432/rails-test
- image: circleci/postgres:9.6
environment: