This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ApplicationController < ActionController::Base | |
before_action :detect_device_variant | |
private | |
def detect_device_variant | |
case request.user_agent | |
when /iPad/i | |
request.variant = :tablet | |
when /iPhone/i |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<img src="abc.JPG" onerror="this.src='default.JPG'" /> | |
或者 | |
<script type="text/javascript"> | |
t = document.getElementsByClassName("defaultImg"); | |
for(i = 0; i < t.length; i++){ | |
t.item(i).onerror = function(){ | |
this.src = "test.gif" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app/views/layouts/_async_javascript.html.erb | |
<script type="text/javascript"> | |
(function() { | |
var script = document.createElement('script'); | |
script.type = 'text/javascript'; | |
script.async = true; | |
script.src = '<%= j javascript_path(path) %>'; | |
var other = document.getElementsByTagName('script')[0]; | |
other.parentNode.insertBefore(script, other); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Pre-requisites | |
sudo apt-get -y update | |
sudo apt-get -y install git-core curl autoconf automake openssl vim build-essential libc6-dev libreadline6 libreadline6-dev zlib1g zlib1g-dev libssl-dev libyaml-dev mysql-server libmysqlclient-dev ncurses-dev libtool bison libxslt1-dev libxml2-dev | |
# rbenv | |
curl https://raw.github.com/fesplugas/rbenv-installer/master/bin/rbenv-installer | bash | |
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile | |
echo 'eval "$(rbenv init -)"' >> ~/.bash_profile |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<style type="text/css"> | |
<!-- | |
div { | |
position:absolute; | |
top:50%; | |
left:50%; | |
margin:-150px 0 0 -200px; | |
width:400px; | |
height:300px; | |
border:1px solid #008800; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf-8 | |
#正则用于匹配用户名 | |
str = "@wikimo @中國 @水手 测试看看" | |
#{2,20}字符长度至少2个,不多于20个,以下任意方式匹配 | |
#arr = str.scan(/@([一-龠\w]{2,20}\s)/u).flatten | |
arr = str.scan(/@([\p{Han}+\w]{2,20}\s)/u).flatten | |
前端:https://github.com/ichord/jquery-atwho-rails |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Creating and Signing Your Certs | |
This is SSL, so you'll need an cert-key pair for you/the server, the api users/the client and a CA pair. You will be the CA in this case (usually a role played by VeriSign, thawte, GoDaddy, etc.), signing your client's certs. There are plenty of tutorials out there on creating and signing certificates, so I'll leave the details on this to someone else and just quickly show a sample here to give a complete tutorial. NOTE: This is just a quick sample of creating certs and not intended for production. | |
# Create the CA Key and Certificate for signing Client Certs | |
openssl genrsa -des3 -out ca.key 4096 | |
openssl req -new -x509 -days 365 -key ca.key -out ca.crt | |
# Create the Server Key, CSR, and Certificate | |
openssl genrsa -des3 -out server.key 1024 | |
openssl req -new -key server.key -out server.csr |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Load libraries | |
var https = require('https'); | |
var fs = require('fs'); | |
var socketio = require('socket.io'); | |
// The server options | |
var svrPort = 8888; // This is the port of service | |
var svrOptions = { | |
key: fs.readFileSync('certs/server.key'), | |
cert: fs.readFileSync('certs/server.crt'), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
通过json访问新浪ip数据库,可以获得相应城市的ip地址。 | |
例行惯例,不解释: | |
<script type="text/javascript" > | |
$(document).ready(function(){ | |
jQuery.getScript("http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js", function(){ | |
alert("province : "+remote_ip_info.province+", city : "+remote_ip_info.city); | |
}); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
wget -m -p -E -k -K -np http://twitter.github.io/bootstrap/ |