Skip to content

Instantly share code, notes, and snippets.

View huobazi's full-sized avatar
🎯
Focusing

Marble Wu huobazi

🎯
Focusing
View GitHub Profile
module RandomAttribute
def generate_unique_random_base64(attribute, n)
until random_is_unique?(attribute)
self.send(:"#{attribute}=", random_base64(n))
end
end
def generate_unique_random_hex(attribute, n)
until random_is_unique?(attribute)
ActiveSupport.on_load(:action_controller) do
after_action :set_csrf_cookie_for_angular_js
define_method :set_csrf_cookie_for_angular_js do
cookies['XSRF-TOKEN'] = form_authenticity_token if protect_against_forgery?
end
private :set_csrf_cookie_for_angular_js
define_method :verified_request_with_angular_header? do
verified_request_without_angular_header? || form_authenticity_token == request.headers['X-XSRF-Token']
//
// _oo0oo_
// o8888888o
// 88" . "88
// (| -_- |)
// 0\ = /0
// ___/`---'\___
// .' \\| |// '.
// / \\||| : |||// \
// / _||||| -:- |||||- \
@huobazi
huobazi / Order.cs
Last active August 29, 2015 14:11 — forked from dinowang/Order.cs
public enum Order
{
Ascending,
Descending
}
@huobazi
huobazi / proload.js
Last active August 29, 2015 14:11 — forked from matdombrock/proload.js
//USES JQUERY
var slides = [
"img/Lighthouse.jpg",
"img/Desert.jpg",
"img/Jellyfish.jpg"
];
$(slides).each(function () {
$('<img />').attr('src',this).appendTo('body').css('display','none');
});
@huobazi
huobazi / gist:2e7e6623b5effbee2148
Created December 11, 2014 05:24
禁用语法检查与自动首字母大写
<input id="input_reg_validecode" autocorrect="off" spellcheck="false" autocapitalize="off" type="text" class="intxt fl" style="width: 76px;" />
@huobazi
huobazi / HTML-tags.md
Last active August 29, 2015 14:11 — forked from yisibl/HTML-tags.md

常用的 HTML 头部标签

详细介绍参见原文:yisibl/blog#1

<!DOCTYPE html> <!-- 使用 HTML5 doctype,不区分大小写 -->
<html lang="zh-cmn-Hans"> <!-- 更加标准的 lang 属性写法 http://zhi.hu/XyIa -->
<head>
    <meta charset='utf-8'> <!-- 声明文档使用的字符编码 -->
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" /> <!-- 优先使用 IE 最新版本和 Chrome -->
@huobazi
huobazi / fixIE.js
Last active August 29, 2015 14:11 — forked from c0untd0wn/fixIE.js
'use strict';
// Add ECMA262-5 method binding if not supported natively
//
if (!('bind' in Function.prototype)) {
Function.prototype.bind= function(owner) {
var that= this;
if (arguments.length<=1) {
return function() {
return that.apply(owner, arguments);
@huobazi
huobazi / gist:e0c8148211ade289b294
Last active August 29, 2015 14:12
Rotating rails' logs
####################################################
# File: /etc/logrotate.d/rails_app
# Test: logrotate -f /etc/logrotate.d/rails_app
####################################################
/home/path_to/app/*/shared/log/*.log {
size=20M
dateformat -%Y%m%d-%s
dateext
notifempty
missingok
# Docs: http://smartinez87.github.io/exception_notification/
module ExceptionNotifier
class SlackNotifier
def initialize(options)
# do something with the options...
@channel = options[:channel] || '#somechannel'
@team = options[:team] || 'someteam'
@token = options[:token] || '__top_secret_token__'
@username = options[:username] || 'somename'