Skip to content

Instantly share code, notes, and snippets.

View malavbhavsar's full-sized avatar

Malav Bhavsar malavbhavsar

View GitHub Profile
@malavbhavsar
malavbhavsar / _flash.html.erb
Created October 1, 2012 04:07 — forked from potomak/_flash.html.erb
Rails flash messages using Twitter bootstrap
<% [:notice, :error, :alert].each do |level| %>
<% unless flash[level].blank? %>
<div class="alert-message <%= flash_class(level) %>">
<a class="close" href="#">×</a>
<%= content_tag :p, flash[level] %>
</div>
<% end %>
<% end %>
require 'bundler/setup'
require 'mechanize'
require 'open-uri'
agent = Mechanize.new
# agent.set_proxy 'localhost', 3128
# login
agent.get('https://www.codeschool.com/users/sign_in') do |page|
result = page.form_with(:action => '/users/sign_in') do |form|
//l.sauer 2011, public domain
//returns a hash table with the word as index and frequency as value; good for svg / canvas -plotting or other experiments
//[:punct:] Punctuation symbols . , " ' ? ! ; : # $ % & ( ) * + - / < > = @ [ ] \ ^ _ { } | ~
var wordcnt = function(id){
var hist = {}, words = document.getElementById(id).innerText.split(/[\s*\.*\,\;\+?\#\|:\-\/\\\[\]\(\)\{\}$%&0-9*]/)
for(var i in words)
if(words[i].length >1 )
hist[words[i]] ? hist[words[i]]+=1 : hist[words[i]]=1;
return hist;
};