Skip to content

Instantly share code, notes, and snippets.

View install_memcached.sh
#!/bin/bash
#
# Download and install libevent and memcached from source on Debian Etch or
# Debian Lenny.
#
# Assumptions
# - libevent and memcached have not been installed from apt repositories
# - memcached is not already running
# - it is ok to clobber scripts at
# /etc/memcached.conf
@reyesyang
reyesyang / Translation.rb
Created Apr 11, 2013
Rewrite human_attribute_name method in ActiveModel::Translation file for Padrino project which use ActiveRecord as ORM.
View Translation.rb
module ActiveModel
module Translation
include ActiveModel::Naming
def human_attribute_name(attribute, options = {})
options = { :count => 1 }.merge!(options)
parts = attribute.to_s.split(".")
attribute = parts.pop
namespace = parts.join("/") unless parts.empty?
attributes_scope = "models"
@reyesyang
reyesyang / AjaxExceptionHandler.js
Created Apr 11, 2013
Ajax exception handler for rails-ujs
View AjaxExceptionHandler.js
on('ajax:error', function(e, xhr, status, errors){
var error;
try {
error = $.parseJSON(xhr.responseText);
} catch(e) {
error = {message: '服务器忙,请稍后再试!'};
}
//code to show error message
@reyesyang
reyesyang / getSelectionText.js
Created Apr 23, 2013
Method to get selection text.
View getSelectionText.js
function getSelectionText() {
var text = "";
if (window.getSelection) {
text = window.getSelection().toString();
} else if (document.selection && document.selection.type != "Control") {
text = document.selection.createRange().text;
}
return text;
}
@reyesyang
reyesyang / font.css
Created Apr 24, 2013
Font CSS basic settings
View font.css
body {
font-family: "Helvetica Neue",​Helvetica,​Arial,​sans-serif
font-size: 14px;
color: #333333;
line-height: 20px;
}
View getWindowWidthOrHight.js
function GetWidth()
{
var x = 0;
if (self.innerHeight)
{
x = self.innerWidth;
}
else if (document.documentElement && document.documentElement.clientHeight)
{
x = document.documentElement.clientWidth;
View eigenclass.rb
class Object
def eigenclass
class << self; self; end
end
end
@reyesyang
reyesyang / link_text_overflow.css
Created Jun 28, 2013
Hidden overflow text in link element
View link_text_overflow.css
View solarized-dark.css
/* Solarized Dark
For use with Jekyll and Pygments
http://ethanschoonover.com/solarized
SOLARIZED HEX ROLE
--------- -------- ------------------------------------------
base03 #002b36 background
base01 #586e75 comments / secondary content
@reyesyang
reyesyang / clear_after.css
Created Dec 20, 2013
Clear float with :after
View clear_after.css
&:after {
content: ".";
display:block;
height:0;
clear:both;
visibility:hidden;
}