Skip to content

Instantly share code, notes, and snippets.

@awesome
awesome / strip HTML tags
Created November 3, 2009 16:29
ruby strip HTML tags
# copied from (thanks!): http://codesnippets.joyent.com/posts/show/615
str = <<HTML_TEXT
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<body>
<h1>Application error</h1>
<p>Change this error message for exceptions thrown outside of an action (like
in Dispatcher setups or broken Ruby code) in public/500.html</p>
@huyng
huyng / reflect.py
Created February 7, 2011 17:57
A simple echo server to inspect http web requests
#!/usr/bin/env python
# Reflects the requests from HTTP methods GET, POST, PUT, and DELETE
# Written by Nathan Hamiel (2010)
from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler
from optparse import OptionParser
class RequestHandler(BaseHTTPRequestHandler):
def do_GET(self):
@huy
huy / Hash.from_xml
Created February 10, 2011 05:29
Convert xml to hash using Nokogiri
# USAGE: Hash.from_xml(YOUR_XML_STRING)require 'rubygems'
require 'nokogiri'
# modified from http://stackoverflow.com/questions/1230741/convert-a-nokogiri-document-to-a-ruby-hash/1231297#123129
7
class Hash
class << self
def from_xml(xml_io)
begin
result = Nokogiri::XML(xml_io)
@kklimonda
kklimonda / pybrowser.py
Created March 28, 2011 15:18
A minimal Gtk+/Webkit based browser in Python
import sys
from gi.repository import Gtk, Gdk, WebKit
class BrowserTab(Gtk.VBox):
def __init__(self, *args, **kwargs):
super(BrowserTab, self).__init__(*args, **kwargs)
go_button = Gtk.Button("go to...")
go_button.connect("clicked", self._load_url)
self.url_bar = Gtk.Entry()
@sandro
sandro / threaded_httparty.rb
Created August 27, 2011 01:34
Parallel HTTParty requests using threads
require 'rubygems'
require 'httparty'
require 'benchmark'
require 'thread'
class Google
include HTTParty
base_uri 'http://google.com'
def self.benchmark
@entaroadun
entaroadun / gist:1653794
Created January 21, 2012 20:10
Recommendation and Ratings Public Data Sets For Machine Learning

Movies Recommendation:

Music Recommendation:

@xentek
xentek / httparty-xml-example.rb
Created February 7, 2012 01:57
HTTParty with XML example
require 'httparty'
response = HTTParty.get('http://www.google.com/ig/api?weather=Chicago')
data = response.parsed_response
puts data['xml_api_reply']['weather']['current_conditions']['condition']['data']
@komamitsu
komamitsu / AndroidManifext.xml
Created February 23, 2012 15:52
Android Simple web server using NanoHTTPD (http://elonen.iki.fi/code/nanohttpd)
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"></uses-permission>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
@follesoe
follesoe / RubyXmlDslExercise.md
Created May 22, 2012 16:57
Simple Ruby XML DSL exercise implemented by Torgeir and Jonas

Simple Ruby DSL to generate XML

Implemented as an exercise to learn about metaprogramming in Ruby. The DSL is implemented using instance_eval and method_missing.

Usage

require 'xmldsl'

Twitter = Struct.new :name, :avatar, :text
twitters = []
5.times { twitters << Twitter.new("Jonas", "/profile.png", "Hello World!") }
@kimjoar
kimjoar / create_xml.rb
Created May 23, 2012 06:47
Simple Ruby DSL to generate XML
require './xmldsl'
Twitter = Struct.new :name, :avatar, :text
twitters = []
5.times { twitters << Twitter.new("Jonas", "/profile.png", "Hello World!") }
xml = XML.generate do
html do
body do
twitters.each do |tw|