Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

« Newer Snippets
Older Snippets »
Showing 1-9 of 9 total  RSS 

2ch RSS Icon

// ==UserScript==
// @name  2ch RSS Icon
// @namespace  http://d.hatena.ne.jp/youpy/
// @include  http://*.2ch.net/test/read.cgi/*
// @exclude  http://b.hatena.ne.jp/*
// ==/UserScript==

(function () {
 var a = document.createElement('a');
 a.href = location.href.replace(/^http:\/\/(\w+\.2ch\.net\/)test\/read\.cgi\/(.+)$/, "http://rss.s2ch.net/test/-/$1$2");
 var image = document.createElement('img'); 
 image.src = 'data:image/png;base64,'+
    'iVBORw0KGgoAAAANSUhEUgAAACQAAAAOCAMAAABw6U76AAAAA3NCSVQICAjb4U/gAAADAFBMVEX/'+
    '///18e346N3/5tXv5Nz33czw2svo18z20rvw0Lv/yKTmzLrwxqrgyrreybrowqrwvJnfv6nvsYj0'+
    'qXflrYjxqHfTsJnlo3fVp4f/mlfgoXfunGbeoHbWnXbjmGbFoIfflma7nIfJmHffjFXsh0TmhUS6'+
    'kXe5kXf0gDPUiFXufjPfgkTNhVX2dyLHglXxdSLSfUTkdy6zhWXedzO+f1WqgWa3fFT/ZgDScjPd'+
    'bSLraBH3YwCseFXFbTPvYACkdFTsXgDmXADiXQW4aDPGYyLUXxGzZjPeWQDNXBGhaUTZVwDGWRGm'+
    'YTPTVADPUwDHUACyURGUWjPFSgC7SwCcUyK1SACsRQCbSBGoQwCNQxGcPgCZPQCTOwB9MwI/GgEh'+
    'DgEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'+
    'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'+
    'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'+
    'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'+
    'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'+
    'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'+
    'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'+
    'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'+
    'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABJnr9zAAABHUlEQVR4nIWRWVODMBSFL5XWJVbc60K1'+
    '7gvuVYNGUuIWRQMtSNG6/f9/YQLTaRkfel7Omcw3uWfuhaGxgTqFRaxElHAWKaVp7Dr+zqDdum3b'+
    'T4IRTLZM8+BeUHK9YladgJEeBKnKbX5cSNOdmE4dRW4/dPG4p8FZWICdTmAZzgboH/FDzQhyUCti'+
    'o7AdAawlgcfZHOjPseDcJfmfTIBEjMgZ+nxT7KthE+fRv05aK3bJpKZSIjZL6mk1zndaB2hIiPGr'+
    'mibncs4tA+CL5zuNg/YWFJ3Q80pwUzVDn1ugf+agV58WQW/LRkiH4feKXEgZ4DK87UEzSy8MH1bM'+
    'k/osQlNHEafLBkILTZ/2QTi7AFVijFGVpbvds3R+Bur3DxzBWgFMxGSIAAAAAElFTkSuQmCC';
 image.width = 36;
 image.height = 14;
 a.appendChild(image);
 document.body.appendChild(a);
})();

Google Redirector

// ==UserScript==
// @name          Google Redirector
// @namespace     http://d.hatena.ne.jp/youpy/
// @include       *
// ==/UserScript==

(function() {
    var targets = document.evaluate('//a[starts-with(@href, "http")]', document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
    for (var i = 0; i < targets.snapshotLength; i ++) {
	targets.snapshotItem(i).href = 'http://www.google.com/url?sa=D&q=' + encodeURIComponent(targets.snapshotItem(i).href);
    }
})();

Campfire Bot

// ==UserScript==
// @name Campfire Bot
// @namespace http://d.hatena.ne.jp/youpy/
// @description bot on campfire
// @include http://*.campfirenow.com/room/*
// ==/UserScript==

(function (){
    getLastMessage = function() {
	div = document.evaluate("//tr[contains(@class,'text_message') and not(contains(@class,'you'))]/td[@class='body']/div", document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
	return div.snapshotItem(div.snapshotLength - 1).innerHTML;
	
    }
    
    window.setInterval(
		       function() {
			   last_message = getLastMessage();
			   if(this.last_message != (sorted = last_message.split('').sort().join(''))) {
			       this.last_message = sorted;
			       if(last_message.match(/^\//)) {
				   switch(last_message) {
				   case '/now':
				       this.chat.speaker.speak(new Date().toString());
				       break;
				   }
			       } else  {
				   this.chat.speaker.speak(last_message.split('').reverse().join(''));
			       }

			   }
		       }, 3000);
})();


residents at here

audible web browsing

You need to install esound.
$ esd -public -tcp &
$ sudo /usr/sbin/tcpdump -w - port 80 | esdcat -r 5000 -s 127.0.0.1 < /dev/stdin

get annual event name

Object.extend(Date.prototype, {
  getAnnualEventName:
    function() {
      var annualEvents = $H({
            'newyear':        '1/1-1/3',
            'haloween':       '10/31',
            'christmas':      '12/1-12/25',
      });

      var today = new Date(this.getYear(), this.getMonth(), this.getDate());
      var annualEventName = '';

      annualEvents.each(
                        function(pair, index) {
                          days = pair[1].split('-');
                          if(!days[1]) {
                            if(today.getTime() ==
                               new Date(this.getYear(),
                                        days[0].split('/')[0] - 1, days[0].split('/')[1]).getTime()) {
                                annualEventName = pair[0];
                            }
                          } else {
                            from = new Date(this.getYear(),
                                            days[0].split('/')[0] - 1, days[0].split('/')[1]);
                            to = new Date(this.getYear(),
                                          days[1].split('/')[0] - 1, days[1].split('/')[1]);
                            if(from > to) {
                              if(!(today > to && today < from)) {
                                annualEventName = pair[0];
                              }
                            } else {
                              if(today >= from && today <= to) {
                                annualEventName = pair[0];
                              }
                            }
                          }
                        }.bind(this)
                        );

      return annualEventName;
    }
});

mailto storm

(1 .. 100).each { |v| print "<img src=\"mailto:#{sprintf('%03d', v)}@example.org\">\n" }

Effect.MoveTo

Effect.MoveTo = Class.create();
Object.extend(Object.extend(Effect.MoveTo.prototype, Effect.MoveBy.prototype), {
  update: function(position) {
    var topd  = (this.toTop - this.originalTop) * position + this.originalTop;
    var leftd = (this.toLeft - this.originalLeft) * position + this.originalLeft;
    this.setPosition(topd, leftd);
  }
});

Klaus Nomi

// ==UserScript==
// @name nomi
// @namespace http://www.bigbold.com/snippets/user/youpy
// @description NOMI
// @include *
// ==/UserScript==

(function (){
imgs = document.getElementsByTagName('img');
for(i = 0; i < imgs.length; i ++) {
imgs[i].src = 'http://images.google.com/images?q=tbn:v0zJeXKeczEJ:www.icicom.up.pt/blog/tendadosindios/archives/klausnomi1.jpg'
}

})();

Lighttpd Rails Script with SSL options

#!/usr/bin/env ruby

require 'optparse'
require 'fileutils'
require 'tmpdir'

OPTIONS = {
  :port        => 3000,
  :ip          => "0.0.0.0",
  :daemon      => false,
  :environment => "development",
  :app_name    => Process::pid.to_s,
  :max_procs   => 3,
  :min_procs   => 1,
  :ssl         => false,
  :pemfile     => "server.pem",
}

ARGV.options do |opts|
  script_name = File.basename($0)
  opts.banner = "Usage: ruby #{script_name} [options]"

  opts.separator ""

  opts.on("-p", "--port=port", Integer,
          "Runs Rails on the specified port.",
          "Default: 8000") { |OPTIONS[:port]| }
  opts.on("-b", "--binding=ip", String,
          "Binds Rails to the specified ip.",
          "Default: 0.0.0.0") { |OPTIONS[:ip]| }
  opts.on("-e", "--environment=name", String,
          "Specifies the environment to run this server under (test/development/production).",
          "Default: development") { |OPTIONS[:environment]| }
  opts.on("-a", "--app-name=name", String,
          "Specifies the application name.",
          "Default: process_id") { |OPTIONS[:app_name]| }
  opts.on("-d", "--daemon",
          "Make lighttpd / Rails run as a Daemon (only works if fork is available -- meaning on *nix)."
          ) { OPTIONS[:daemon] = true }
  opts.on("-n", "--min-procs=number", Integer,
          "Minimum number of FastCGI processes allowed.",
          "Default: 1") { |OPTIONS[:min_procs]| }
  opts.on("-m", "--max-procs=number", Integer,
          "Maximum number of FastCGI processes allowed.",
          "Default: 3") { |OPTIONS[:max_procs]| }
  opts.on("-l", "--enable-ssl",
          "Enable SSL."
          ) { OPTIONS[:ssl] = true }
  opts.on("-f", "--pemfile=pemfile", String,
          "path to the PEM file for SSL support."
          ) { |OPTIONS[:pemfile]| }
  
  opts.separator ""

  opts.on("-h", "--help",
          "Show this help message.") { puts opts; exit }

  opts.parse!

end

ENV["RAILS_ENV"] = OPTIONS[:environment]
RAILS_ROOT = Dir.pwd + "/./"
TMP_DIR = Dir.tmpdir
LIGHTTPD_CONF_FILE = TMP_DIR + "/lighttpd.#{OPTIONS[:app_name]}.conf"

conf = DATA.read
conf.gsub!('__PORT__', OPTIONS[:port].to_s)
conf.gsub!('__BINDING__', OPTIONS[:ip])
conf.gsub!('__RAILS_ROOT__', File.expand_path(RAILS_ROOT))
conf.gsub!('__APP_NAME__', OPTIONS[:app_name])
conf.gsub!('__MIN_PROCS__', OPTIONS[:min_procs].to_s)
conf.gsub!('__MAX_PROCS__', OPTIONS[:max_procs].to_s)
conf.gsub!('__RAILS_ENV__', ENV['RAILS_ENV'])
conf.gsub!('__TMP_DIR__', TMP_DIR)
conf.gsub!('__SSL__', OPTIONS[:ssl] ? "enable" : "disable")
conf.gsub!('__PEMFILE__', OPTIONS[:pemfile])
File.open(LIGHTTPD_CONF_FILE, "w") { |output| output.write(conf) }

CMD = "/usr/sbin/lighttpd -f #{LIGHTTPD_CONF_FILE}"
CMD << " -D" if not OPTIONS[:daemon]

puts "=> Rails application started on http://#{OPTIONS[:ip]}:#{OPTIONS[:port]}"
puts "=> Ctrl-C to shutdown server; call with --help for options" if not OPTIONS[:daemon]

puts CMD
`#{CMD}`

FileUtils.rm Dir.glob(TMP_DIR + "/lighttpd.#{OPTIONS[:app_name]}.*") if not OPTIONS[:daemon]

__END__
server.port                = __PORT__
server.bind                = "__BINDING__"
server.pid-file             = "__TMP_DIR__/lighttpd.__APP_NAME__.pid"
server.max-keep-alive-requests = 4
server.max-keep-alive-idle = 4

ssl.engine = "__SSL__"
ssl.pemfile = "__PEMFILE__"

#server.event-handler = "freebsd-kqueue"

server.modules = ( "mod_rewrite", "mod_redirect", "mod_access", "mod_fastcgi", "mod_accesslog" )
server.document-root        = "__RAILS_ROOT__/public/"
server.indexfiles           = ( "index.html" ,"dispatch.fcgi")
accesslog.filename          = "__RAILS_ROOT__/log/lighttpd.__RAILS_ENV__.access.log"
server.errorlog             = "__RAILS_ROOT__/log/lighttpd.__RAILS_ENV__.error.log"
server.error-handler-404 = "/dispatch.fcgi"

#### fastcgi module

## read fastcgi.txt for more info
fastcgi.server =  (
                   ".fcgi" => (
                               "__APP_NAME__" => (
                                                  "socket" => "__TMP_DIR__/lighttpd.__APP_NAME__.fcgi.socket",
                                                  "bin-path" => "__RAILS_ROOT__/public/dispatch.fcgi",
                                                  "min-procs" => __MIN_PROCS__,
                                                  "max_procs" => __MAX_PROCS__
                                                  )
                               )
                   )


mimetype.assign             = (
                               ".rpm"          =>      "application/x-rpm",
                               ".pdf"          =>      "application/pdf",
                               ".sig"          =>      "application/pgp-signature",
                               ".spl"          =>      "application/futuresplash",
                               ".class"        =>      "application/octet-stream",
                               ".ps"           =>      "application/postscript",
                               ".torrent"      =>      "application/x-bittorrent",
                               ".dvi"          =>      "application/x-dvi",
                               ".gz"           =>      "application/x-gzip",
                               ".pac"          =>      "application/x-ns-proxy-autoconfig",
                               ".swf"          =>      "application/x-shockwave-flash",
                               ".tar.gz"       =>      "application/x-tgz",
                               ".tgz"          =>      "application/x-tgz",
                               ".tar"          =>      "application/x-tar",
                               ".zip"          =>      "application/zip",
                               ".mp3"          =>      "audio/mpeg",
                               ".m3u"          =>      "audio/x-mpegurl",
                               ".wma"          =>      "audio/x-ms-wma",
                               ".wax"          =>      "audio/x-ms-wax",
                               ".ogg"          =>      "audio/x-wav",
                               ".wav"          =>      "audio/x-wav",
                               ".gif"          =>      "image/gif",
                               ".jpg"          =>      "image/jpeg",
                               ".jpeg"         =>      "image/jpeg",
                               ".png"          =>      "image/png",
                               ".xbm"          =>      "image/x-xbitmap",
                               ".xpm"          =>      "image/x-xpixmap",
                               ".xwd"          =>      "image/x-xwindowdump",
                               ".css"          =>      "text/css",
                               ".html"         =>      "text/html",
                               ".htm"          =>      "text/html",
                               ".js"           =>      "text/javascript",
                               ".asc"          =>      "text/plain",
                               ".c"            =>      "text/plain",
                               ".conf"         =>      "text/plain",
                               ".text"         =>      "text/plain",
                               ".txt"          =>      "text/plain",
                               ".dtd"          =>      "text/xml",
                               ".xml"          =>      "text/xml",
                               ".mpeg"         =>      "video/mpeg",
                               ".mpg"          =>      "video/mpeg",
                               ".mov"          =>      "video/quicktime",
                               ".qt"           =>      "video/quicktime",
                               ".avi"          =>      "video/x-msvideo",
                               ".asf"          =>      "video/x-ms-asf",
                               ".asx"          =>      "video/x-ms-asf",
                               ".wmv"          =>      "video/x-ms-wmv",
                               ".bz2"          =>      "application/x-bzip",
                               ".tbz"          =>      "application/x-bzip-compressed-tar",
                               ".tar.bz2"      =>      "application/x-bzip-compressed-tar"
                               )
« Newer Snippets
Older Snippets »
Showing 1-9 of 9 total  RSS