Skip to content

Instantly share code, notes, and snippets.

@miyagawa
miyagawa / battery.rb
Last active April 13, 2024 10:13
Get OS X Bluetooth device's battery from the command line
#!/usr/bin/env ruby
require 'plist'
def visit(thing, want, &block)
case thing
when Hash
thing.keys.each do |key|
if want.include?(key)
yield key, thing[key]
else
-- Set selected Address Book contact pictures from Gravatar.
-- Released under GPL.
-- by Doug Smith, http://smithsrus.com
-- Fixed md5_email routine by Tatsuhiko Miyagawa
-- Grab the selected records and see how many there are.
tell application "Address Book"
set selected_contacts to selection
set count_selected to number of items in selected_contacts
@miyagawa
miyagawa / gist:1912431
Created February 26, 2012 02:53
How to represent Links in REST

How to embed HATEOAS/Link inside JSON

HTTP Headers

For HTTP headers it's quite straightforward: draft-nottingham-http-link-header defines this.

Link: <http://example.com/>; rel="previous"; titile="Previous chapter"
@miyagawa
miyagawa / tweet_import.rb
Last active December 26, 2021 18:25
import tweets from tweets.zip into Day One app. May or may not work with your dayone preference...
#!/usr/bin/env ruby
require 'json'
require 'open3'
require 'date'
class Importer
def initialize(*args)
@js_files = *args
end
@miyagawa
miyagawa / gist:1961801
Created March 2, 2012 22:16
Import 4sq checking to Day One app
#!/usr/bin/env ruby
require 'open-uri'
require 'open3'
require 'date'
require 'ri_cal'
class Importer
attr_reader :url
@miyagawa
miyagawa / circular-detect.pl
Last active November 2, 2021 15:33
Circular perl/CPAN dependencies with requires/recommends/suggests for configure/runtime/build/test for all modules in 02packages
#!/usr/bin/env perl
use strict;
use Parse::CPAN::Packages;
use Module::CoreList;
use JSON::XS;
$| = 1;
my $packages_file = "$ENV{HOME}/minicpan/modules/02packages.details.txt.gz";

NAME

cpanfile - A format for describing CPAN dependencies for Perl applications

SYNOPSIS

requires 'Catalyst', '5.8000';
requires 'CatalystX::Singleton', '>= 1.1000, < 2.000';

recommends 'JSON::XS', '2.0';
@miyagawa
miyagawa / sale.md
Last active January 25, 2021 07:49
@miyagawa
miyagawa / curl.rb
Created August 30, 2018 01:54
curl --resolve with typhoeus
require 'typhoeus'
require 'ethon'
resolve = Ethon::Curl.slist_append(nil, "example.com:443:1.2.3.X")
r = Typhoeus::Request.new(
"https://example.com",
resolve: resolve,
# verbose: true,
)