Skip to content

Instantly share code, notes, and snippets.

@polikeiji
polikeiji / gist:6199809
Created August 10, 2013 09:50
SSHで接続してサーバ先のGUIアプリをサーバ上で実行するときにいる設定。 raspberry piをSSH経由でいじるときに。 ネタ元:http://d.hatena.ne.jp/gikogeek/20080220
export DISPLAY=:0.0
@polikeiji
polikeiji / gist:6621462
Created September 19, 2013 10:08
SSHの鍵認証使ってる時用の、複数台のサーバーにファイルをアップする為のshellスクリプト。
#!/bin/bash
# target hosts
TO_HOSTS=("${TO_HOSTS[@]}" "web01.example.com")
TO_HOSTS=("${TO_HOSTS[@]}" "web02.example.com")
# ssh keys
SSH_KEYS=("${SSH_KEYS[@]}" "ssh-private-key-for-web01.example.com.pem")
SSH_KEYS=("${SSH_KEYS[@]}" "ssh-private-key-for-web02.example.com.pem")
@polikeiji
polikeiji / gist:6621501
Created September 19, 2013 10:12
パスワード使ったSSH用のアップロードスクリプト。
#!/bin/bash
# target hosts
TO_HOSTS=("${TO_HOSTS[@]}" "web01.example.com")
TO_HOSTS=("${TO_HOSTS[@]}" "web02.example.com")
# target directory
TO_BASE_DIRECTORY="/remote/directory/"
TO_DIRECTORIES=("${TO_DIRECTORIES[@]}" "php/")
@polikeiji
polikeiji / redirect.coffee
Created September 19, 2013 10:16
基本的には、スマホはスマホ用にリダイレクトする。ただ、PCサイトを見るってした時は、クッキーにそれを入れて、スマホでもPCサイトを見れる。というJS。
is_smart_phone = () ->
lower_user_agent = window.navigator.userAgent.toLowerCase()
return (lower_user_agent.indexOf('android') != -1 and
lower_user_agent.indexOf('android 1.') == -1 and
lower_user_agent.indexOf('android 2.') == -1) or
(lower_user_agent.indexOf('iphone') != -1 and
lower_user_agent.indexOf('iphone os 2_') == -1 and
lower_user_agent.indexOf('iphone os 3_') == -1)
redirect_to_sp = () ->
@polikeiji
polikeiji / gist:7941321
Created December 13, 2013 08:27
UIImageViewを3つ使い回して、iOSデフォルトの「写真」アプリみたいに、たくさんの写真を横向きに見ていく為のコード。 「scrollViewWillEndDragging」のUIScrollViewDelegateを使って書いた。 iOS Scroll Viewプログラミングガイドには、「scrollViewDidScroll」のデリゲートを使うって書いてあったけど、それだと早く連続で写真をめくるときの処理がうまくかけなかった。 なお、UIImageのloadImageFromPathは、自分でカテゴリを使って追加していて、非同期で画像を落としてくるスタティックメソッド。
@implement MyScrollViewDelegate
{
UIImageView *currentImageView;
UIImageView *nextImageView;
UIImageView *previousImageView;
NSInteger currentPhotoIndex;
NSArray *photos;
}
- (void)resetPhotoSlideImageViews
@polikeiji
polikeiji / gist:8e3145aaac9b67fd3456
Last active August 29, 2015 14:02
Stringで[1..4]とかできるようにするextension
extension String {
subscript(range:Range<Int>) -> String {
return self[advance(self.startIndex, range.startIndex)..advance(self.startIndex, range.endIndex)]
}
}
var s = "abcdefghij"
s[1..4] // print "bcd"
s[1...4] // print "bcde"
@polikeiji
polikeiji / gist:8fcbdc88bb213257da9f
Last active August 29, 2015 14:03
S3用のrsync的なPythonスクリプト。botoが必要。excludeパターンの指定可。
# -*- coding: utf-8 -*-
"""
File Name: upload_s3.py
Usage: python upload_s3.py
"""
import sys
import os
import os.path
import fnmatch
@polikeiji
polikeiji / gist:1fd44508f7efff2e5074
Last active August 29, 2015 14:03
InstagramでOAuthする為に作ったクラス。結構昔だから、今はちゃんとしたSDKあるかも。
<?php
class InstagramOAuth {
const CLIENT_ID = Configuration::INSTAGRAM_CLIENT_ID;
const CLIENT_SECRET = Configuration::INSTAGRAM_CLIENT_SECRET;
const CALLBACK_URL = Configuration::INSTAGRAM_CALLBACK_URL;
public static function getAuthorizationURL($state = null, $scope = InstagramScope::BASIC, $is_implicit_authentication = false) {
$scope = $scope == null ? InstagramScope::BASIC : $scope;
$response_type = !$is_implicit_authentication ? 'code' : 'token';
@polikeiji
polikeiji / gist:c82e0cb021394dd8432a
Created July 10, 2014 09:41
サムネイル作成用のPHPクラス。GDベース。サムネイル画像をバイナリーデータとして返してくれる。
<?php
class ThumbnailUtility {
const TYPE_KEEP_RATIO = 0;
const TYPE_TRIM = 1;
public static function Resize(
$file_path_or_url,
$thumbnail_width = null,
@polikeiji
polikeiji / gist:92b9b99a5263c73c7874
Created July 12, 2014 19:37
Twitterのフォロワー一覧のプロフ画像の解像度をあげるブックマークレット
javascript: $(".ProfileCard-avatarImage").each(function() { $avatarImg = $(this); $avatarImg.attr("src", $avatarImg.attr("src").replace("_bigger", "_400x400")); });