Skip to content

Instantly share code, notes, and snippets.

View dtan4's full-sized avatar

Daisuke Fujita dtan4

View GitHub Profile
require "slim"
Slim::Template.new { "h1 hoge" }.render #=> <h1>hoge</h1>
@dtan4
dtan4 / transpose.rb
Created January 31, 2014 12:52
Transpose text
text = <<-EOS.strip
このあと
滅茶苦茶
サックスした
EOS
text.lines.map{|line|line.strip.ljust(text.lines.map(&:size).max).chars}
.transpose.map(&:join).map(&:reverse).join("\n")
=begin
@dtan4
dtan4 / htmlbody2json.rb
Created March 23, 2014 08:42
Convert <body> to JSON
#!/usr/bin/env ruby
require "nokogiri"
html = <<-EOS
<!DOCTYPE html>
<html>
<head>
<title>hoge</title>
</head>
{"status":true,"tree":{"name":"body","class":"","id":"","children":[{"name":"div","class":"container","id":"","children":[{"name":"div","class":"jumbotron","id":"","children":[{"name":"div","class":"container","id":"","children":[{"name":"h1","class":"","id":"","children":[]},{"name":"p","class":"","id":"","children":[]},{"name":"form","class":"form-inline","id":"","children":[{"name":"div","class":"form-group","id":"","children":[{"name":"label","class":"sr-only","id":"","children":[]},{"name":"input","class":"form-control","id":"","children":[]}]},{"name":"button","class":"btn btn-default","id":"","children":[]}]}]}]}]},{"name":"script","class":"","id":"","children":[]}]}}
#!/usr/bin/env ruby
CHECK_DIRS = %w(dotfiles dot.emacs.d dot.zsh)
COMMANDS = {
push: "git push -u origin master",
pull: "git pull --stat --rebase origin master",
status: "git status -s"
}
type = ARGV.shift
#!/usr/bin/env ruby
filepath = ENV["HOME"] + "/git/dotfiles/Brewfile"
lines = []
open(filepath).each do |line|
next if line.strip == ""
next if line =~ /^tap/
lines << line.split(" ")
end
@dtan4
dtan4 / check.sh
Last active August 29, 2015 14:00
#!/bin/bash
USAGE="Usage: check.sh [pull|push|status]"
if [[ $# -lt 1 ]] ; then
echo $USAGE 1>&2
exit 1
fi
base_dir=$(pwd)
#!/bin/bash
USAGE="Usage: git_bulk.sh [pull|push|status]"
if [[ $# -lt 1 ]] ; then
echo $USAGE 1>&2
exit 1
fi
base_dir=$(pwd)
#!/usr/bin/env ruby
require "json"
require "open-uri"
URL = "https://api.github.com/users/dtan4/repos"
json = open(URL).read
repositories = JSON.parse(json, symbolize_names: true)
require "spec_helper"
module Sample
describe Spec do
it "should return JSON without id" do
task = described_class.new(id, params)
end
end
end