Skip to content

Instantly share code, notes, and snippets.

require 'rubygems'
require 'mechanize'
require 'nokogiri'
require 'open-uri'
def build_url(html)
title_begin = html =~ /<title>/
title_end = html =~ /<\/title>/
# get the title - ignore the YouTube prefix
@davekaro
davekaro / gist:7313218
Last active December 27, 2015 10:39 — forked from ivanvanderbyl/gist:4222308
Upgrade Postgres from 9.2 to 9.3 on Ubuntu
sudo add-apt-repository ppa:pitti/postgresql
sudo apt-get update
sudo apt-get install postgresql-9.3 postgresql-server-dev-9.3 postgresql-contrib-9.3
sudo su -l postgres
service postgresql stop
/usr/lib/postgresql/9.3/bin/pg_upgrade -b /usr/lib/postgresql/9.2/bin -B /usr/lib/postgresql/9.3/bin -d /var/lib/postgresql/9.2/main/ -D /var/lib/postgresql/9.3/main/ -O "-c config_file=/etc/postgresql/9.3/main/postgresql.conf" -o "-c config_file=/etc/postgresql/9.2/main/postgresql.conf"
logout # logout postgresql back to previous user
timeline = client.user_timeline(@user_name, { count: 200, include_entities: true })
hashtag_list = timeline.map { |tweet| tweet.hashtags.collect(&:text) }
@hashtags = hashtag_list.uniq.map do |tag|
{ text: tag,
weight: hashtag_list.grep(tag).size,
link: { href: "https://twitter.com/search?q=%23#{tag}", target: '_blank', title: "#{tag}" } }
end
@hashtags = @hashtags.to_json
@davekaro
davekaro / keybase.md
Created September 22, 2014 17:59
Keybase

Keybase proof

I hereby claim:

  • I am davekaro on github.
  • I am davekaro (https://keybase.io/davekaro) on keybase.
  • I have a public key whose fingerprint is C421 4D56 84D1 5A4B ACB1 EE96 3818 49BD 558A AAE1

To claim this, I am signing this object:

@davekaro
davekaro / live_reload_middleware.rb
Created November 16, 2015 15:27
Live reload middleware for ember-cli
# Mostly copied from http://stackoverflow.com/questions/11057905
class LiveReloadMiddleware < Rack::Proxy
def initialize(app)
@app = app
end
def call(env)
# call super if we want to proxy, otherwise just handle regularly via call
(proxy?(env) && super) || @app.call(env)
end
@davekaro
davekaro / 100000_response.ru
Last active December 31, 2020 19:15
Falcon performance
require "securerandom"
response = SecureRandom.hex(100_000)
run lambda { |env|
[200, {"Content-Type" => "text/plain"}, [response.dup]]
}
<div data-controller="multi-select">
<%= form.label(method, id: "#{id_base}__label", class: "funky-label") %>
<%# used as descriptive text for option buttons; if used within the button text itself, it ends up being read with the input name %>
<span id="<%= "#{id_base}__remove" %>" class="hidden">remove</span>
<ul id="<%= "#{id_base}__selected" %>" class="space-x-2 selected-options">
<template id="<%= "#{id_base}__selected-option-template" %>">
<li>
<%= form.hidden_field(method, multiple: true, value: nil) %>
<button class="space-x-1 btn-rounded" aria-describedby="<%= "#{id_base}__remove" %>">
<span class="combobox-remove-text"></span>