Skip to content

Instantly share code, notes, and snippets.

View perpouh's full-sized avatar
🍺
drinking!

perpouh perpouh

🍺
drinking!
View GitHub Profile
@perpouh
perpouh / .markdown
Created July 12, 2019 06:21
商品タイルてきなもの+リボン
@perpouh
perpouh / hkim.py
Created July 3, 2019 09:13
ホクホクのイモ
import random
hkim = ["ホ","ク","イ","モ"]
random.shuffle(hkim)
s = hkim[0:2] * 2
s += "の"
random.shuffle(hkim)
@perpouh
perpouh / trimtag.php
Created March 28, 2019 08:05
一部の許可されたタグ以外を取り除く
<?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>
@perpouh
perpouh / Vagrantfile
Created February 28, 2019 08:18
vagrant upでpython環境を立ち上げたい
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
@perpouh
perpouh / article_controller.rb
Last active February 22, 2019 06:46
ユーザーが入力した検索ワードをMeCabでアレする
private
def search_query
return {"title_or_body_matches_any" => Mecab.parse(params[:q][:title_or_body_matches_any]).map{|t| "%#{t}%"}}
end
@perpouh
perpouh / article_controller.rb
Created February 21, 2019 02:19
検索ログをファイルに書き出しつつバッチ処理で集計してDBに吐くためのモデルクラス
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
@perpouh
perpouh / _map.html.erb
Created February 6, 2019 05:26
Vueに毒されたのでパーシャルがコンポーネントみたいになったの図
<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'), {
@perpouh
perpouh / search.md
Created January 29, 2019 01:44
ransackでキーワード検索を実装する
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
@perpouh
perpouh / hepler.md
Created January 24, 2019 08:05
検索画面で検索語をハイライトするヘルパー

たぶん探せば便利なgemがあるんだろうけど、適当にggった感じでは出てこなかったので。

  def focus(str, words)
    length = 100 # 他の画面でも使うならどっかに出したほうがいいかもしれない

    if !words.kind_of?(Array)
      words = [words]
    end
@perpouh
perpouh / validate.md
Created January 23, 2019 10:02
登録されるとつらいユーザー名リストについて