Skip to content

Instantly share code, notes, and snippets.

@lxyuma
lxyuma / new_gist_file_0.md
Last active December 12, 2015 10:29
mysql user command

よく忘れてしまうので、mysqlのuser系のコマンドのまとめ

  • ユーザー作成

  • create user 'username'@'host'

  • ユーザー変更

  • rename user old to new

  • ユーザー一覧

  • select Host,User from mysql.user;

# railsのmodelで***_path(resourceのURL)を使う方法
- Rails.application.routes.url_helpers.posts_path
- 参考
- http://stackoverflow.com/questions/5380703/rails-get-resource-path-in-model
- ところが、これだと、パスしか分からない。URLのホスト部分が入らない。
- posts_urlに変えると、以下のエラーが出る。
- ArgumentError (Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true):
@lxyuma
lxyuma / gist:5202528
Created March 20, 2013 05:28
ruby omniauth twitter feed
# omniauth + omniauth-twitter gems are required
class TwitterApi
SITE = "http://api.twitter.com"
API_URL = { :update_status => SITE + "/1.1/statuses/update.json"}
def self.feed
access_token = official_access_token
response = access_token.request(:post,
API_URL[:update_status],
@lxyuma
lxyuma / gist:5642433
Last active December 17, 2015 16:59
mongodb replicaset basic memo

dataとlogディレクトリの準備

mkdir -p /srv/mongodb/rs0/ /srv/mongodb/rs1/ /srv/mongodb/rs2/

mkdir /var/log/mongo
@lxyuma
lxyuma / gist:5642687
Last active December 17, 2015 16:59
mongodb backup

mongodb dump

やり方

  • ファイルコピー
  • メリット:高速
  • デメリット:DB停止かロック(db.fsyncLock())が必要
  • (replica setはoplog溢れないよう注意)
  • mongodump
  • メリット:ファイル小さくなる
@lxyuma
lxyuma / gist:5660240
Last active December 17, 2015 19:29
jasmine rails
@lxyuma
lxyuma / gist:6424131
Last active December 22, 2015 05:28
marionette script
// sample
var MyView = Marionette.ItemView.extend({
template: "my-template-id"
});
var myView = new MyView({ model: Dog});
myView.render();
// ItemView sample
@lxyuma
lxyuma / gist:7508850
Created November 17, 2013 03:48
yeomanのgenerator backboneを使って、handlebarsをtemplateにしたprojectでひな形作るまで

前提

node.js / npm / yeoman をinstall

手順

project作成

$ npm install -g backbone

@lxyuma
lxyuma / gist:7543763
Last active March 17, 2021 02:02
Backbone.View入門

Backbone.Viewの使い方

基本的な使い方は、ModelやCollectionと一緒です。流れとしては、Backboneのコンポーネントをextendした物を宣言して、必要な時にnewしていくという形になります。

var PostView = Backbone.View.extend({
  // your source
});
var postView = new PostView
@lxyuma
lxyuma / gist:8753581
Created February 1, 2014 15:17
Ractive.js 公式pageのsample
<html>
<script src="http://cdnjs.cloudflare.com/ajax/libs/ractive.js/0.3.7/ractive.min.js"></script>
<body>
<div id="result">
</div>
<p>※consoleから、ractive.set('messages.unread', 5); とコピペして実行してみると</p>
</body>
<script id='myTemplate' type="text/ractive">
<p>こんにちわ{{user}} さん。
<strong>{{messages.unread}} 件の未読メッセージがあります。</strong>