Skip to content

Instantly share code, notes, and snippets.

View cherenkov's full-sized avatar

cherenkov cherenkov

View GitHub Profile
@cherenkov
cherenkov / prime_number.rb
Created February 24, 2016 19:05
エラトステネスのふるい(おみくじ付き) #PictRuby
def main
p = []
x = Popup.input "入力した数の中から素数を探します"
x = x.to_i
s = [*2..x]
while (1)
t = s.shift
p << t
s.select! {|e| e % t != 0 }
break if (x**0.5) <= t
@cherenkov
cherenkov / get_ameblo_image.rb
Created February 21, 2016 18:30
アメブロの画像URLを取得する #pictruby
def main
url = Popup.input "amebloのURLを入力してください"
url = "https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20html%20where%20url%3D'" + url + "'%20and%20xpath%3D'%2F%2Fimg%5Bcontains(%40src%2C%20%22http%3A%2F%2Fstat.ameba.jp%2Fuser_images%2F%22)%5D%5Bnot(contains(%40src%2C%20%22%3Fcpd%3D%22))%5D'&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys"
json = Browser.json url
p json
end
@cherenkov
cherenkov / what_grade
Last active February 21, 2016 15:43
中学何年生かわかる便利スクリプト #pictruby
def main
age = Popup.input "中学何年生か計算します。年齢を入力してください。"
Popup.msg "中学#{age.to_i - 12}年生"
end
@cherenkov
cherenkov / get_anchor.rb
Created April 18, 2012 01:30
あるWebページ内にある全ての「リンク先のURLと文字列」を上手く.. - 人力検索はてな http://q.hatena.ne.jp/1334564001
# coding: utf-8
#あるWebページ内にある全ての「リンク先のURLと文字列」を上手く.. - 人力検索はてな
#http://q.hatena.ne.jp/1334564001
require 'mechanize'
class String
def strip_with_full_size_space!
s = " \s\r\n\t\f\v"
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="utf-8">
<title></title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script>
<script>
$(function() {
});
@cherenkov
cherenkov / fangate_sample.php
Created November 15, 2012 18:45
facebook. タブページのアプリのファンゲート
<?php
$signed_request = $facebook->getSignedRequest();
// pr($signed_request);
if (isset($signed_request['page']) && isset($signed_request['page']['liked'])) {
$pageLiked = $signed_request['page']['liked'];
} else {
if (isset($signed_request['user_id']) && $signed_request['user_id']) {
// ここでリロードさせることによって、次のアクセスで$signed_request['page']['liked']が取れる。
echo '<script>window.location = window.location;</script>';
@cherenkov
cherenkov / gist:4045645
Created November 9, 2012 13:23
xargsの限界?
echo . | xargs xdg-open
→正しく開かれる
ところが、
.zshrcに
function xdg_open_background() {
xdg-open $* &
}
alias o=xdg_open_background
@cherenkov
cherenkov / hateq_demo.html
Created November 4, 2012 21:25
jQueryを使用したスライドショーの表示について 今回、jQueryを.. - 人力検索はてな http://q.hatena.ne.jp/1351994896
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja" lang="ja" dir="ltr">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>jQuery SIMPLE SLIDESHOW</title>
<meta http-equiv="content-style-type" content="text/css" />
<meta http-equiv="content-script-type" content="text/javascript" />
<link rel="stylesheet" type="text/css" href="http://kotenbu.sakura.ne.jp/css/screen.css" media="all" />
<script type="text/javascript" src="http://kotenbu.sakura.ne.jp/js/jquery-1.5.2.min.js"></script>
<script type="text/javascript">
@cherenkov
cherenkov / test.user.js
Created November 2, 2012 21:01
firefox用のアドオン開発について質問です。 インストールしてお.. - 人力検索はてな http://q.hatena.ne.jp/1351864226
// ==UserScript==
// @name test
// @namespace http://d.hatena.ne.jp/Cherenkov/
// @description
// @include http://*
// @include https://*
// ==/UserScript==
document.getElementById('hoge').textContent = 'TEST';
@cherenkov
cherenkov / shebang.sublime-snippet
Created October 19, 2012 22:24
sublime text 2: shebang: # coding: utf-8
<snippet>
<content><![CDATA[
# coding: utf-8
]]></content>
<tabTrigger>shebang</tabTrigger>
<description>shebang: # coding: utf-8</description>
<scope>source.ruby</scope>
</snippet>