Skip to content

Instantly share code, notes, and snippets.

View cyjake's full-sized avatar

Chen Yangjian cyjake

View GitHub Profile
@cyjake
cyjake / gen_uid.js
Created January 16, 2012 14:49
UID Generating in JavaScript
// 还需要了解的:
// - 什么是 UID
// - 这四种方式优劣
function getId() {
return "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx".replace(/x/g, function() {
return Math.floor(Math.random()*16).toString(16).toUpperCase();
});
}
@cyjake
cyjake / html.js
Created April 20, 2012 07:54
A Simple HTML formatter in JavaScript
define(function(require, exports) {
var TAB_WIDTH = 2;
var str_helper = require('./string');
function squeeze(str) {
return str.replace(/^[ \n\t]+/, '').replace(/\>[\n\t ]+/g, '>');
}
@cyjake
cyjake / river.rb
Created August 20, 2012 03:15
A tool to minimize and bundle your SeaJS modules, in Ruby
class River
DEFAULT_CONFIG = {
:root => 'cc',
:base => Rails.root.join('public'),
:preloads => ['ent']
}
def initialize(attrs = nil)
attrs ||= DEFAULT_CONFIG.dup
@cyjake
cyjake / gist:3521950
Created August 30, 2012 03:10
[jekyll] [liquid] How to list posts of current page's category
{% for category in site.categories %}
{% if page.categories contains category[0] %}
<section>
<h3>{{ category | first | capitalize }}</h3>
{% assign posts = category[1] %}
</section>
{% endif %}
{% endfor %}
@cyjake
cyjake / grid.scss
Created September 26, 2012 01:45
Implement Brix Grid in SCSS
$gridGutterWidth: 10px;
$gridColumnWidth: 10px;
$gridColumns: 50;
$gridRowWidth: ($gridColumns * $gridColumnWidth) + ($gridGutterWidth * ($gridColumns - 1));
.row {
margin-left: $gridGutterWidth * -1;
*zoom: 1;
&:before,
&:after {
@cyjake
cyjake / style_paser.js
Last active December 10, 2015 20:49
A CSS Parser written in JavaScript as a SeaJS module. Parses css text into objects.
// Usage:
//
// seajs.use('style_parser', function(parser) {
// var console.log(parser.parse('body { padding: 0; margin: 0 }'))
// })
//
// will output:
// {
// "body": {
// "padding": 0,
@cyjake
cyjake / guard.sh
Last active December 14, 2015 16:39
A simple vsftpd guard script for preventing bad guys from brute guessing your ftp account. The original version is created by @hugozhu for blocking ssh account guessing. http://hugozhu.myalert.info/2013/03/08/block_failed_ssh_attempts_with_iptable.html
#!/bin/bash
last_ip=""
tail -f /var/log/vsftpd.log | while read LINE; do
{
if [[ "${LINE}" =~ "FAIL LOGIN" ]]; then
ip="$(echo ${LINE} | awk '{ip=$NF;gsub(/\"/,"",ip);print ip}')"
if [[ "$last_ip" == "$ip" ]]; then
echo "block $ip"
iptables -A INPUT -s "$ip" -j DROP
fi
@cyjake
cyjake / gist:5177621
Created March 16, 2013 18:16
Arch Linux 又一坑
# 2013-03-17 刚才不小心更新了一下 curl
sudo pacman -S curl
# 结果 curl 跪了,所有的 pacman 命令也是
curl: /usr/lib/libc.so.6: version `GLIBC_2.17' not found (required by curl)
curl: /usr/lib/libc.so.6: version `GLIBC_2.17' not found (required by /usr/lib/libcurl.so.4)
# 于是很悲剧地连回滚 curl 都不行,幸好找到了不通过 pacman 命令回滚软件的方式
# https://bbs.archlinux.org/viewtopic.php?pid=1148260#p1148260
zcat /var/cache/pacman/pkg/curl-7.26.0-1-<arch>.pkg.tar.xz | tar xv -C /
@cyjake
cyjake / gist:5177879
Created March 16, 2013 19:19
还是不要用 rmagick 了吧
# https://bbs.archlinux.org/viewtopic.php?id=49632
# rmagick 的 lib 文件检测机制太老,找不到新版本的 imagemagick(~> 6.8.0),
# 回退到旧版本就好了
sudo pacman -U /var/cache/pacman/pkg/imagemagick-6.7.8.9-1-i686.pkg.tar.xz
@cyjake
cyjake / deploy.rb
Last active December 15, 2015 01:39
capistrano deploy config for rabel app.
# encoding: utf-8
# config/deploy.rb
#
# - 使用 Unicorn
# - 链接 rabel 的配置文件和用户上传内容
# - 使用 RVM
# Add RVM's lib directory to the load path.
require "rvm/capistrano"