This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
hkim = ["ホ","ク","イ","モ"] | |
random.shuffle(hkim) | |
s = hkim[0:2] * 2 | |
s += "の" | |
random.shuffle(hkim) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$text = <<<AAA | |
hogehoge | |
<b>hogehoge</b><i>fugafuga</i> | |
<big>bigbigbig</big> | |
<small>smallsmall</small> | |
<font color="red">redtext</font> | |
<script type="application/javascript"><b>alert();</b></script> | |
<span style="font-size:16pt;"><b>ほげほげ</b></span> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Vagrant.configure("2") do |config| | |
config.vm.box = "centos/7" | |
config.vm.box_download_insecure = true | |
config.vm.synced_folder ".", "/vagrant", disabled: true | |
config.vm.provision "shell", inline: <<-SHELL | |
if [ ! -e '/usr/bin/git' ]; then | |
yum install -y git | |
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private | |
def search_query | |
return {"title_or_body_matches_any" => Mecab.parse(params[:q][:title_or_body_matches_any]).map{|t| "%#{t}%"}} | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ArticlesController < ApplicationController | |
def index | |
if params[:q].present? | |
@articles = Article.ransack(search_query).result.page(params[:page]).per(10) | |
logger = Log.new | |
logger.write(params[:q][:title_or_body_matches_any].split(/\s/)) # せっかくMeCab入れたので修正する | |
render action: :search | |
elsif params[:tag].present? | |
@articles = Article.ransack({body_matches_all: "%##{params[:name]}%"}).result.page(params[:page]).per(10) | |
logger = Log.new |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div id="map"></div> | |
<% if form.present? %> | |
<%= form.hidden_field :latitude, {id: "shop_latitude"} %> | |
<%= form.hidden_field :longitude, {id: "shop_longitude"} %> | |
<%= form.hidden_field :name, {id: "shop_name"} %> | |
<%= form.hidden_field :address, {id: "shop_address"} %> | |
<script type="application/javascript"> | |
var map; | |
function initMap() { | |
map = new google.maps.Map(document.getElementById('map'), { |
def index
if params[:q].present?
@articles = Article.ransack(search_query).result.page(params[:page]).per(10)
render action: :search
else
@articles = Article.all
end
end
たぶん探せば便利なgemがあるんだろうけど、適当にggった感じでは出てこなかったので。
def focus(str, words)
length = 100 # 他の画面でも使うならどっかに出したほうがいいかもしれない
if !words.kind_of?(Array)
words = [words]
end
登録されるとつらいユーザー名リスト
上記をYAML化したもの
登録されるとつらいユーザー名を禁止するRails Validator
この辺りをアレしてバリデータを作った。 さすがに%w{}でリスト化するのは嫌すぎたのでYAML.loadした。
def validate_each(record, attribute, value)
@words = YAML.load(File.read(File.join(Rails.root, "config/ban.yml")))['ban']