Skip to content

Instantly share code, notes, and snippets.

var basketModule = (function() {
var basket = [];
return {
addItem: function(values) {
basket.push(values);
},
getItemCount: function() {
return basket.length;
},
@kurorido
kurorido / gist:b8a4f827d52c6b47c890
Last active August 29, 2015 14:22
一些網頁基礎使用
if( /Android|webOS|iPhone|iPod|iPad|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
// some code..
window.location.href = "to mobile site url";
}
@kurorido
kurorido / .htaccess
Created April 28, 2015 13:48
htaccess cache
# Enable GZIP
<ifmodule mod_deflate.c>
AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x-javascript application/javascript
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
</ifmodule>
# Expires Headers - 2678400s = 31 days
<ifmodule mod_expires.c>
mongo 進入 Command Line
use <dbname> 使用特定db
show collections 顯示所有collections
db.<collection>.find() 顯示 collections 下所有的 document
db.<collection>.drop() 刪除 collections
## 掛載 rewrite module
sudo a2enmod rewrite
sudo service apache2 restart
修改 /etc/apache2/sites-available/default
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
# changed from None to FileInfo
AllowOverride FileInfo
Order allow,deny
# MySQL 連線
String driver = "com.mysql.jdbc.Driver";
Class.forName(driver);
String conUrl = "jdbc:mysql://localhost/smft?user=root&password=&charset=utf8&characterEncoding=UTF-8r";
Connection con = null;
PreparedStatement ps = conn.prepareStatement(SQL);
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
rs.getString("UserName");
}
# 更新時間
UPDATE table SET end_dt = DATE_ADD(end_dt, INTERVAL 15 second)
# Command Line Run SQL
mysql -u root dbname < "path.sql"
# 相框效果
img {
box-shadow: 1px 1px 2px rgba(0,0,0,0.3);
padding: 12px;
background: rgba(255,255,255,0.9);
}
## find out mount/partition a directory or file is on?
df -P file/goes/here | tail -1 | cut -d' ' -f 1
# delete line 135 in file, and save origin file into file.bak
sed -i.bak -e '135d' file
# Recursive find string from files
grep -R -i -n '<string>' <directory>
# nohup
@kurorido
kurorido / restframework blog note
Last active August 29, 2015 14:10
restframework blog note
class ArticleSerializer(serializers.ModelSerializer):
tags = serializers.RelatedField(many=True)
class Meta:
model = Article
fields = ('title','content','tags')
owner = serializers.Field(source='owner.username')