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
require 'nokogiri' | |
class Nokogiri::XML::Node | |
def to_hash(selector = 'body > *') | |
hash = [] | |
self.css(selector).each do |node| | |
hash << node.collect_nodes | |
end | |
hash | |
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
#compdef heroku | |
local state ret=1 | |
local -a cmds | |
cmds=( | |
"version:show the gem version" \ | |
"list:list your apps" \ | |
"create:create a new app" \ | |
"keys:show your user's public keys" \ | |
"keys\:add:add a public key" \ |
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
require 'curb' | |
require 'net/http' | |
require 'open-uri' | |
require 'benchmark' | |
Net::HTTP.version_1_2 | |
n = 100 | |
Benchmark.bm do |x| |
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
-- Ramanujan Numbers: | |
-- c.f. http://www.ipl.t.u-tokyo.ac.jp/~onoue/pub/jssst01.pdf | |
module Main where | |
main = print (take 10 (ramanujan (\(a,b) -> a^3 + b^3))) | |
ramanujan f = [(x,y) | (x,y)<- zip s (tail s), f x == f y] where s = fsort f 1 | |
fsort f k = (k,k) : fmerge f [(k,b) | b<-[k+1..]] (fsort f (k+1)) | |
fmerge f (x:xs) (y:ys) | |
| f x <= f y = x : fmerge f xs (y:ys) | |
| otherwise = y : fmerge f (x:xs) ys |
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
aj = [[0,1,2],[2,0,1],[1,2,0]] | |
n = 100 | |
m = 10 | |
while (n > 0) | |
hm = m/2 | |
(1..(m-6)/4).each { |a| a3 = a**3 | |
((a+1)..(((m2=m-a)-3)/3)).each { |b| b3 = b**3 | |
# a+b+c+d == m; a+d == b+c (mod 6) => c == m/2-b (mod 3) | |
c = b+1; c += aj[c%3][(hm-b)%3] | |
upper_c = ((m3=m2-b)-1)/2 |
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 BootstrapLinkRenderer < WillPaginate::LinkRenderer | |
def to_html | |
links = @options[:page_links] ? windowed_links : [] | |
links.unshift(page_link_or_span(@collection.previous_page, 'prev', @options[:previous_label])) | |
links.push(page_link_or_span(@collection.next_page, 'next', @options[:next_label])) | |
html = @template.content_tag(:ul, links.join(@options[:separator])) | |
@options[:container] ? @template.content_tag(:div, html, html_attributes) : html |
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
def ugly_guess_jp str | |
%w[UTF-8 EUC-JP Shift_JIS eucJP-ms Windows-31J].find do |encoding| | |
begin | |
tested = str.force_encoding(encoding) | |
tested.valid_encoding? && tested.encode('UTF-8').valid_encoding? | |
rescue Encoding::UndefinedConversionError => e | |
nil | |
end | |
end | |
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
# encoding: UTF-8 | |
class HolidayInfo | |
def initialize date | |
@date = date | |
@is_national = false | |
@name = "" | |
@is_substitute = false | |
end | |
attr_accessor :date, :is_national, :name, :is_substitute |
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
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> | |
<xsl:output method="xml" encoding="ISO-8859-1"/> | |
<xsl:param name="indent-increment" select="' '"/> | |
<xsl:template name="newline"> | |
<xsl:text disable-output-escaping="yes"> | |
</xsl:text> | |
</xsl:template> | |
<xsl:template match="comment() | processing-instruction()"> |
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
require 'nokogiri' | |
xml = <<EOS | |
<html> | |
<body> | |
<h1><a href="#">This is title</a></h1> | |
<p> | |
Hello <i>world</i>! | |
This is <em>another</em> line. | |
<p><h3>And a paragraph <em>with</em> a heading.</h3></p> |
OlderNewer