Skip to content

Instantly share code, notes, and snippets.

@thr3a
thr3a / app.rb
Created October 4, 2015 23:36
例のWIKIからスクレイピングするやつ ex. app.rb > denko.json
require 'mechanize'
require 'json'
result = []
top_url = 'http://stationmemories.wiki.fc2.com/'
wiki = Mechanize.new.get(top_url)
wiki.search('ul.treemenu_ul')[0].css('li a').each do|denko|
# でんこ個別ページ取得
page = Mechanize.new.get(top_url + denko[:href])
# でんこの名前取得
name = page.search('.page_title h1').text
@thr3a
thr3a / package.json
Created October 26, 2015 14:14
Nodejsを使った山手線の家賃平均を求めるスクリプト
{
"name": "yamanote-tintai",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
upstream php-handler {
# server 127.0.0.1:9000;
server unix:/var/run/php5-fpm.sock;
}
server {
listen 80;
server_name _;
# ssl_certificate /etc/ssl/nginx/cloud.example.com.crt;
# ssl_certificate_key /etc/ssl/nginx/cloud.example.com.key;
require 'benchmark'
namespace :bulk do
desc "TODO"
task insert: :environment do
Task.delete_all
Benchmark.bm 100 do |r|
r.report "normal" do
1000.times do |i|
Task.create(title: "#{i}", content: "content #{i}")
end
@thr3a
thr3a / Gemfile
Last active March 30, 2016 07:22
hoge
# A sample Gemfile
source "https://rubygems.org"
# gem "rails"
gem 'slack-ruby-bot'
gem 'natto'
gem 'activerecord'
gem 'sqlite3'
@thr3a
thr3a / bot.rb
Created April 14, 2016 03:27
slack-slot
require 'slack-ruby-bot'
class SlotBot < SlackRubyBot::Bot
match /slot/ do |client, data, match|
array = %w(:ulicknormanowen: :shausagi: :fire: :sushi:)
result = []
3.times do
result << array.sample
end
msg = "Start! =>"
msg << result.join(" ")

Gemfile に以下を追加

gem 'compass'

ひな壇を生成

bundle exec compass create 

vagrant編

vagrantのディレクトリに bundle init

以下を追加

gem 'itamae'
gem 'itamae-plugin-recipe-rtn_rbenv'

PHPからJavascriptにデータを渡す方法としてJSON形式に変換がよく使われる。

<?php
$data = array(
  'name' => '太郎',
  'url' => 'https://github.com',
  'age' => 20,
  'is_human' => true
);