Skip to content

Instantly share code, notes, and snippets.

@TimLang
TimLang / deploy.rb
Created December 27, 2016 08:14 — forked from Kr00lIX/deploy.rb
Deploy Phoenix Elixir by mina
require 'mina/bundler'
require 'mina/git'
require 'mina/rbenv'
set :domain, 'your_domain.com'
set :deploy_to, '/home/deployer/app_name'
set :repository, 'git@github.com:user_name/app_name'
set :branch, ENV["brunch"] || 'master'
set :app_name, "app_name"
@TimLang
TimLang / python
Created December 21, 2016 09:48 — forked from 582033/python
多线程获取并验证代理
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys, re
import requests
import Queue
import threading
class Proxy():
def __init__(self, proxy_url, target_url, ver_keyword, timeout):
@TimLang
TimLang / is_gif.exs
Created December 1, 2016 06:01
How to know the image format is gif
result = to_string("identify #{file_path} | head -n1" |> String.to_char_list |> :os.cmd)
Regex.match?(~r/[\S]+[[:blank:]]+GIF[[:blank:]]\d+x\d+/, result)
@TimLang
TimLang / json_map_builder.ex
Created September 20, 2016 10:08 — forked from rcdilorenzo/json_map_builder.ex
Convert a elixir json-decoded object to a map no matter how deep
defmodule JSONMapBuilder do
def to_map(list) when is_list(list) and length(list) > 0 do
case list |> List.first do
{_, _} ->
Enum.reduce(list, %{}, fn(tuple, acc) ->
{key, value} = tuple
Map.put(acc, binary_to_atom(key), to_map(value))
end)
_ ->
list
@TimLang
TimLang / macro_fun.exs
Created September 20, 2016 04:02 — forked from rcdilorenzo/macro_fun.exs
Macro fun in Elixir mimicking Ruby's attr_accessor
defmodule MacroExp do
defmacro attr_accessor(atom) do
getter = String.to_atom("get_#{atom}")
setter = String.to_atom("set_#{atom}")
quote do
def unquote(getter)(data) do
data |> Map.from_struct |> Map.get(unquote(atom))
end
def unquote(setter)(data, value) do
data |> Map.put(unquote(atom), value)
@TimLang
TimLang / WeixinQQFaceUtil.java
Created June 28, 2016 07:16 — forked from meigesir/WeixinQQFaceUtil.java
微信中QQ表情web、wap页面展现,符号代码(如:/::) → 笑脸)转换为表情图片,目前支持微信5.1.0.6中QQ表情前五屏,只要在微信中输入文字代码[微笑]、/微笑,或符号代码/::) 都可以显示出表情,但是数据库是符号表情/::)
import java.util.Arrays;
import java.util.List;
public class WeixinQQFaceUtil {
private static final String WEIXIN_QQ_IMG_URL_PATH = "https://wx.qq.com/zh_CN/htmledition/images/qqface/{index}.png";//微信QQ表情符号代码转换为真正的表情图片路径(0~99)
private static final String IMG_FILL_PATH = "<img style=\"width:24px;height:24px;\" src=\"{IMG_PATH}\"/>";
public static final List<String> WEIXIN_QQ_FACE_LIST;//微信中的QQ表情符号代码
static{
// weixin_QQ_face(# - split char)
@TimLang
TimLang / mugiwara.html
Created March 3, 2016 14:14 — forked from wusuopu/mugiwara.html
CSS绘制海贼王 草帽路飞的海贼旗
<!DOCTYPE html>
<html>
<head>
<meta charset="utf8">
<title>むぎわら</title>
<style type="text/css">
h1 {
text-align: center;
}
#container {
@TimLang
TimLang / unicorn_init_script.sh
Created January 8, 2016 08:03 — forked from mdesantis/unicorn_init_script.sh
Unicorn init script; it uses start-stop-daemon and supports every Ruby version manager (RVM, rbenv, chruby...)
#!/bin/sh
### BEGIN INIT INFO
# Provides: unicorn
# Required-Start: $all
# Required-Stop: $network $local_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the unicorn instances
# Description: starts the unicorn server instances using start-stop-daemon
#
@TimLang
TimLang / gist:66a9a3ad4c95ecda9a6c
Created November 27, 2015 03:18 — forked from bkimble/gist:1365005
List local memcached keys using Ruby
#!/usr/bin/env ruby
# List all keys stored in memcache.
# Credit to Graham King at http://www.darkcoding.net/software/memcached-list-all-keys/ for the original article on how to get the data from memcache in the first place.
require 'net/telnet'
headings = %w(id expires bytes cache_key)
rows = []
@TimLang
TimLang / image-proxy.conf
Created November 7, 2015 06:53 — forked from tmaiaroto/image-proxy.conf
Nginx Image Filter Resize Proxy Service
# Feel free to change this path of course (and keys_zone value as well, but also change the usage of it below).
proxy_cache_path /var/www/cache/resized levels=1:2 keys_zone=resizedimages:10m max_size=1G;
# Gzip was on in another conf file of mine...You may need to uncomment the next line.
#gzip on;
gzip_disable msie6;
gzip_static on;
gzip_comp_level 4;
gzip_proxied any;
# Again, be careful that you aren't overwriting some other setting from another config's http {} section.