Skip to content

Instantly share code, notes, and snippets.

@RyoSugimoto
RyoSugimoto / .htaccess
Created December 23, 2014 08:05
ダウンロードファイルの処理。
<Files *.xls>
ForceType application/octet-stream
Header set Content-Disposition attachment
</Files>
<Files *.eps>
ForceType application/octet-stream
Header set Content-Disposition attachment
</Files>
@RyoSugimoto
RyoSugimoto / .htaccess
Created December 23, 2014 08:03
カスタムエラーページを表示する。
ErrorDocument 400 /errors/badrequest.html
ErrorDocument 401 /errors/authreqd.html
ErrorDocument 403 /errors/forbid.html
ErrorDocument 404 /errors/notfound.html
ErrorDocument 500 /errors/serverr.html
@RyoSugimoto
RyoSugimoto / .htaccess
Last active August 29, 2015 14:12
直リンクを防止する。
RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http://(.+\.)?mysite\.com/ [NC]
RewriteCond %{HTTP_REFERER} !^$
RewriteRule .*\.(jpe?g|gif|bmp|png)$ /images/nohotlink.jpg [L]
@RyoSugimoto
RyoSugimoto / .htaccess
Created December 23, 2014 07:59
「index.html」を省略する。
Options FollowSymLinks
RewriteEngine on
RewriteCond %{THE_REQUEST} ^.*/index.html [NC]
RewriteRule ^(.*)index.html$ http://www.example.com/$1 [R=301,L]
@RyoSugimoto
RyoSugimoto / add
Last active August 29, 2015 14:12
URLを「www」付きに統一する(またはその逆)。
# add www
RewriteEngine on
RewriteCond %{HTTP_HOST} ^mysite\.com [NC]
RewriteRule (.*) http://www.mysite.com/$1 [L,R=301]
var throttle = (function () {
var interval = 500; // 間引き間隔
var lastTime = new Date().getTime() - interval;
return function () {
// 最後に実行した時間から間引きしたい時間が経過していたら実行
if ((lastTime + interval) <= new Date().getTime()) {
lastTime = new Date().getTime();
// 処理
@RyoSugimoto
RyoSugimoto / ua.js
Created November 23, 2014 22:37
スマートフォンかどうかを判別する。
function isSp () {
var ua = navigator.userAgent;
if (ua.indexOf('iPhone') > 0 || ua.indexOf('Android') > 0) {
return true;
} else {
return false;
}
}
@RyoSugimoto
RyoSugimoto / kerning.css
Last active August 29, 2015 14:10
テキストをカーニングする。
.kern {
text-rendering: optimizeLegibility;
}
@RyoSugimoto
RyoSugimoto / get_bg_position.js
Created October 14, 2014 05:21
background-positionを取得するjQueryメソッド。
;(function () {
$.fn.getBgPosition = function () {
var $elm = $(this).eq(0);
var defVal = $elm.css('background-position');
var positions = {};
if (defVal) {
var valAry = defVal.split(' ');
positions = {
x: parseInt(valAry[0], 10),
y: parseInt(valAry[1], 10)
@RyoSugimoto
RyoSugimoto / boolmark.js
Created October 14, 2014 05:10
ブックマークレットのテンプレート。
javascript: (function () {
var d = document;
if(!window.jQuery){
var s = d.createElement('script');
s.src = 'http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js';
d.body.appendChild(s);
}
setTimeout(function(){
// ここに処理を書きます。
}, 1000);