Skip to content

Instantly share code, notes, and snippets.

@holin
holin / postgresql.md
Created April 18, 2017 08:41
postgresql server

adduser houseuser passwd houseuser su - postgres CREATEUSER -P houseuser # WITH PASSWORD 'house1208fasd' createdb house_prod psql GRANT ALL PRIVILEGES ON DATABASE house_prod to houseuser

/etc/init.d/postgresql start 9.6

@holin
holin / node-js.js
Created April 15, 2017 00:17
node js
```
方法一:使用淘宝镜像
直接运行下面的命令即可:
SASS_BINARY_SITE=https://npm.taobao.org/mirrors/node-sass/ npm install node-sass
我们可能更希望能直接使用 npm install 安装所有依赖,所以我的做法是在项目内添加一个 .npmrc 文件:
sass_binary_site=https://npm.taobao.org/mirrors/node-sass/
phantomjs_cdnurl=https://npm.taobao.org/mirrors/phantomjs/
@holin
holin / nokogiri-example.rb
Created April 11, 2017 06:58
Nokogiri examples
```ruby
# remove attr and replace node
doc = Nokogiri::HTML::DocumentFragment.parse(self.description)
imgs = doc.search("img")
imgs.each do |img|
style = img.attr("style")
puts style.inspect
img.replace("<amp-img height='100' width='610' layout='responsive' src='#{img.attr("src")}' ></amp-img>")
end
doc.css('*').remove_attr('style')
@holin
holin / ecto-query.ex
Last active April 11, 2017 06:57
ecto query examples
# Query with preload and join
```elixir
q = from l in List,
join: ul in UserList,
where: ul.user_id == ^current_user.id and l.id == ul.list_id,
order_by: [desc: l.done_at, asc: l.id]
lists = q |> preload(:user) |> Repo.all
```
@holin
holin / plug.conn.ex
Created February 9, 2017 03:39 — forked from jamonholmgren/plug.conn.ex
Typical Elixir Phoenix Plug.Conn struct contents, in an easy-to-read format. By Jamon Holmgren.
%Plug.Conn{
adapter: {Plug.Adapters.Cowboy.Conn, :...},
assigns: %{
my_assigns: "here"
},
before_send: [
#Function<7.125546534/1 in Phoenix.Controller.fetch_flash/2>,
#Function<1.127904613/1 in Plug.Session.before_send/2>,
#Function<1.43511252/1 in Plug.Logger.call/2>,
#Function<0.70322810/1 in Phoenix.LiveReloader.before_send_inject_reloader/1>
@holin
holin / plug.conn.ex
Created February 9, 2017 03:39 — forked from jamonholmgren/plug.conn.ex
Typical Elixir Phoenix Plug.Conn struct contents, in an easy-to-read format. By Jamon Holmgren.
%Plug.Conn{
adapter: {Plug.Adapters.Cowboy.Conn, :...},
assigns: %{
my_assigns: "here"
},
before_send: [
#Function<7.125546534/1 in Phoenix.Controller.fetch_flash/2>,
#Function<1.127904613/1 in Plug.Session.before_send/2>,
#Function<1.43511252/1 in Plug.Logger.call/2>,
#Function<0.70322810/1 in Phoenix.LiveReloader.before_send_inject_reloader/1>
@holin
holin / init.lua
Created February 1, 2017 14:46
my Hammerspoon init file
local function keyCode(key, modifiers)
modifiers = modifiers or {}
return function()
hs.eventtap.event.newKeyEvent(modifiers, string.lower(key), true):post()
hs.timer.usleep(1000)
hs.eventtap.event.newKeyEvent(modifiers, string.lower(key), false):post()
end
end
@holin
holin / coder.pac
Created January 24, 2017 07:58
My PAC Conf
/*
gfw_whitelist.pac
GFW Whitelist
- inspired by autoproxy and chnroutes
v1.2
Author: [email protected]
License: MIT License
@holin
holin / embed_server.rb
Created January 17, 2017 13:38
Simple ruby embed http server
require 'socket'
require 'uri'
# Usage:
## => EmbedServer.new(web_root).run
class EmbedServer
attr_accessor :web_root, :port
def initialize(web_root, options = {})