Skip to content

Instantly share code, notes, and snippets.

View kyamaguchi's full-sized avatar

kyamaguchi kyamaguchi

View GitHub Profile
@kyamaguchi
kyamaguchi / list_dropbox_files.rb
Last active August 2, 2017 15:50
List files on Dropbox with Ruby
require 'dropbox_api'
require 'byebug'
client = DropboxApi::Client.new('your_access_token')
start_dir = '/broken_files'
def find_files(client, f)
if f.to_hash[".tag"] == "folder"
puts "[FOLDER] #{f.path_lower}"
@kyamaguchi
kyamaguchi / git-fixup
Last active December 14, 2015 05:59
git fixup
#!/bin/bash
# https://github.com/deiwin/git-dotfiles/blob/docs/bin/git-fixup
set -e
# Get the reference to the commit before creating the fixup commit,
# because, say, if the argument is relative to the HEAD then the
# commit it refers to will change once we create a new commit on the
# HEAD.
@kyamaguchi
kyamaguchi / gitopen.sh
Last active October 1, 2015 02:02 — forked from arnorhs/gist:1517095
gitopen - Open all files from a git diff or show command
#!/bin/bash
# This script will open all files from a git diff or a git show in vim.
# My bash skills are a bit primitive so this can probably be done more intelligently
# Usage:
# gitopen -- opens all added files that have changed since HEAD
# gitopen diff HEAD -- these are the default parameters
# gitopen diff master -- opens files that have changed from master
@kyamaguchi
kyamaguchi / good_reader_annotations.rb
Last active November 20, 2015 01:53
Extract highlights and notes which are exported from Good Reader app
#/usr/bin/env ruby
raise "Set input file. $ ruby #{__FILE__} input.txt" if ARGV.empty?
PAGE_SEPARATOR = %r{--- Page (\S+) ---}
ANNOTATION_SEPARATOR = %r{(?<type>Highlight|Note) \((?<color>[^)]+)\), (?<time>.*)(?:, (?<owner>.*))?:}
lines = File.readlines(ARGV[0])
annotations = []
lines.map(&:chomp)
@kyamaguchi
kyamaguchi / rerun_commands_output_spec.rb
Last active August 29, 2015 14:19
Test output of rerun commands of shared_examples_for
require 'spec_helper'
# Version: rspec (3.2.0)
RSpec.describe "Rerun commands output" do
shared_examples_for "random" do
it "more than 3" do
expect(rand(10)).to be > 3
end
(function(){
var total = {};
var year = '2012';
var all = false;
function init(num) {
if(typeof num !== 'number') {
num = 0;
$('<div/>').css({
position: 'fixed',
left: 0,
@kyamaguchi
kyamaguchi / create_models_from_core_data.rb
Created August 31, 2013 04:16
Migration to create tables using CoreData file
# gem 'core_data'
class CreateModelsFromCoreData < ActiveRecord::Migration
TYPE_MAP = {
"Boolean" => 'boolean',
"Date" => 'datetime',
"Integer 32" => 'integer',
"String" => 'string',
}
@kyamaguchi
kyamaguchi / pre-commit
Last active December 10, 2015 01:48
Check specific keywords on commit.
#!/usr/bin/env ruby
class String
# colorization
# from http://stackoverflow.com/questions/1489183/colorized-ruby-output
def colorize(color_code)
"\e[#{color_code}m#{self}\e[0m"
end
def red ; colorize(31) ; end
def green ; colorize(32) ; end
@kyamaguchi
kyamaguchi / oneline_detailed_logging.rb
Created December 7, 2012 05:55 — forked from troy/oneline_detailed_logging.rb
One-line detailed logging for Rails 3 (ActiveSupport::Notifications) and later
# Outputs this at warn log level:
# 1.2.3.4 GET /path 200 OK BlahController#action HTML 938.2 (DB 11.8, View 719.7) {params} {optional params from flash[:log]}
#
# Save as config/initializers/oneline_detailed_logging.rb. Consider
# decreasing the log level from "info" to "warn" (in production.rb) so
# the one-line log message replaces the standard request logs.
# override process_action to add 2 things to the payload:
# - remote IP
@kyamaguchi
kyamaguchi / gist:3227662
Created August 1, 2012 15:10
Full backtrace with RSpec
RSpec.configure do |config|
# Comment out to get full backtrace
config.backtrace_clean_patterns = []
end