Skip to content

Instantly share code, notes, and snippets.

View srockstyle's full-sized avatar

Shohei Kobayashi srockstyle

View GitHub Profile
@srockstyle
srockstyle / schedule.rb
Created March 12, 2013 22:26
RailsのWhenneverでつかうschedule.rbのひな形。
## 3時間ごと
every 3.hours do
runner "Task::sample.exec"
end
## 4:30に実行
every :monday, :at => '4:30 am' do
runner "Task::sample.exec"
end
# データバックアップ(テーブル単位)
mysqldump -u ユーザ名 DB名 -p --default-character-set=binary --tables テーブル名 > backup.sql
# データのリストア(テーブル単位)
mysql -u ユーザ名 DB名 -p --default-character-set=binary < backup.sql
@srockstyle
srockstyle / time.sql
Created March 12, 2013 22:31
一定期間内のデータを抽出するには以下のSQL。二番目はRailsのcreated_atの場合引っ張ってきたいものを指定したりするのに使う。
SELECT id from table_name where date>=ADDDATE(CURDATE(),Interval -7 DAY)
SELECT `recruits`.* FROM `recruits` WHERE (keisai_flag = '1' and date_add(current_date, interval -3 day) <= created_at )
@srockstyle
srockstyle / logout.erb
Created March 12, 2013 22:37
Deviseでログアウト用のリンクを作るときの書き方。
<%if user_signed_in? %>
<%= link_to "Sign out", destroy_user_session_path, :method => :delete%>
<%end%>
@srockstyle
srockstyle / cap.sh
Created March 12, 2013 22:42
capistranoの初期設定&デプロイ手順。
# 初期設定(アプリ毎に行う)
cd /pathtoapps/app
capify .
[add] writing `./Capfile'
[add] writing `./config/deploy.rb'
[done] capified!
# deploy.rbを編集する
cap deploy:setup
@srockstyle
srockstyle / twitter_post.rb
Created March 12, 2013 22:46
TwitterのGemを使ってTwitterにRubyから投稿する方法。
# -*- coding: utf-8 -*-
require "twitter"
## Twitterのもろもろの情報。
Twitter.configure do |cnf|
cnf.consumer_key = "Consumer key"
cnf.consumer_secret = "Consumer secret"
cnf.oauth_token = "OAuth token"
cnf.oauth_token_secret = "OAuth token secret"
end
@srockstyle
srockstyle / titlecsv.php
Last active December 14, 2015 22:09
なんか作ってといわれたのでつくってみた。スクリプトが配置されているディレクトリのHTMLの中のtitleタグの中身とファイル名をCSVで出力する。
<?php
$output = `ls *.html`;
$filelist = preg_split("/\n/",$output);
foreach($filelist as $file){
if(empty($file)){
continue;
}
$fp = fopen($file, "r");
while ($line = fgets($fp)) {
if(preg_match("/\<title\>/",$line)){
@srockstyle
srockstyle / wp_postDelete.php
Created May 13, 2013 07:35
wp.deletePostとxml_encode_request使うことでWordPressの投稿を削除することは可能。ただカスタム投稿タイプを削除できないみたい。ここは要調査。
<?php
function deletePost($rpcurl,$username,$password,$post_id)
{
// xmlrpc settings
$params = array(0,$username,$password,$post_id);
// run xmlrpc
$request = xmlrpc_encode_request('wp.deletePost', $params);
$ch = curl_init();
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
@srockstyle
srockstyle / file0.txt
Last active September 17, 2016 02:01
Ruby on Railsで定数の指定 ref: http://qiita.com/srockstyle/items/daed31a78c343e607822
ApplicationCotnroller < ActionController::Base
NUM = 1
...
end
@srockstyle
srockstyle / file0.txt
Last active January 30, 2017 00:34
Railsのroutesでnamespaceとscopeの設定 ref: http://qiita.com/srockstyle/items/5b0bf6fe2a78e1aa7363
namespace :v3 do
get "/test/read",:to=>"test#read"
end