Skip to content

Instantly share code, notes, and snippets.

@youpy
youpy / twitter_zws.rb
Created August 20, 2012 05:17
post ZWSed text to twitter
# usage: twitter_zws.rb "normal text <encoded text>"
if File.basename($0) == 'bundle'
source :rubygems
gem 'therubyracer'
gem 'twitter'
else
def require_gems
require 'v8'
require 'v8'
require 'open-uri'
class ZWS
def initialize
@cxt = V8::Context.new
open("https://raw.github.com/youpy/node-zws/master/lib/zws.js") do |file|
@cxt.eval(file, "zws.js")
end
end
str = ARGV.shift
str.unpack("U*").map{|c| c.to_s(2)}.join('').scan(/.{1,140}/).each do |s|
s = s.split(//).map do |c|
c == '1' ? "\u200b" : "\u200c"
end
p s.join('')
end
@youpy
youpy / tee.rb
Created August 9, 2012 16:51
generate image for TEE PARTY
# -*- coding: utf-8 -*-
require 'shellwords'
require 'nokogiri'
require 'open-uri'
def main
unicode, font_path, file = ARGV
info = info(unicode)
abort unless info.name
# noisy_typer.rb ~/Downloads/hammerhead_drum_sounds/*909*.wav
require "mac-event-monitor"
require "shellwords"
class NoisyTyper
def initialize(files)
@files = files
end
def monitor
@youpy
youpy / gist:3137528
Created July 18, 2012 17:12
Noisy Typer in Ruby
require "mac-event-monitor"
def main
m = Mac::EventMonitor::Monitor.new
m.add_listener(:key_down) do |e|
system('afplay /Users/youpy/Downloads/NoisyTyper-v001/NoisyTyper.app/Contents/Resources/%s.mp3 &' % keycode2name(e.keycode))
end
m.run
end
@youpy
youpy / load.rb
Last active October 6, 2015 10:58
run Sinatra app on demand
# usage:
#
# ruby load.rb ruby /path/to/sinatra_ondemand.rb
#
# or (with rbenv):
#
# ruby load.rb /bin/zsh -c "RBENV_VERSION=1.9.3-rc1 ruby /path/to/sinatra_ondemand.rb"
require 'launch_agent'
%w(open-uri nokogiri uri).each {|g| require g }
p !!Nokogiri::HTML(open(url = ARGV.shift)).xpath('//script[@src]').find {|s| (URI(url) + s['src']).to_s =~ /\/a.js$/ }
// usage: tail -f xxx.log | node tailf.js
var
WebSocket = require('ws'),
async = require('async'),
spawn = require('child_process').spawn,
wsUrl = 'http://beer.jit.su',
webUrl = 'http://tailf.herokuapp.com',
id,
_.extend(Function.prototype, {
toRequestSpec: function(method, path, options) {
var self = this;
return function(done) {
request(
_.extend({
method: method,
url: 'http://localhost:' + port + path
}, options || {}),
function(req, res) {