Skip to content

Instantly share code, notes, and snippets.

View tadman's full-sized avatar
🤔
Enumerating

Scott Tadman tadman

🤔
Enumerating
View GitHub Profile
@tadman
tadman / refresh.js
Created January 27, 2015 21:23
Automatic Page Refresher
var refresh_element = $('#refresh')[0];
if (refresh_element) {
$(refresh_element).data('refresh', 1);
setInterval(function() {
if ($(refresh_element).data('refresh'))
$(refresh_element).load(window.location.href + ' #refresh');
}, 5000);
@tadman
tadman / db.rake
Created February 19, 2015 21:51
Postgres Database Sequence Resync Rake Task
namespace :db do
namespace :sequences do
desc 'Brings Postgres database sequences into sync with MAX(id)'
task sync: :environment do
ActiveRecord::Base.connection.execute("SET search_path TO public")
updates = ActiveRecord::Base.connection.select_rows(%Q{
SELECT 'SELECT setval('''||_schema||'.'||_seq||''', (SELECT MAX('||_column||') FROM '||_schema||'.'||_table||')+1); ' AS updatestring
FROM (
SELECT n.nspname AS _schema,
def are_okay?(list)
list.all? do |i|
begin
# Arbitrary method call
i.floor
true
rescue
# Should rescue from known exception (or Pokemon capture)
#!/usr/bin/env ruby
require 'benchmark'
COUNT = 1000
LOOP = 1000
def case_method_rb
[
"def case_method(x)",
def pm(object)
identifiers = %w[ + - > ]
list =
case (object)
when Class:
puts "#{object} (Class)"
[
(object.methods.sort - Class.methods),
(object.private_methods.sort - Class.private_methods),
HTTP/1.0 500 Internal Server Error
Date: Mon, 02 Mar 2009 23:26:11 GMT
Server: Apache/2.2.9 (Unix) mod_ssl/2.2.9 OpenSSL/0.9.8e-fips-rhel5
Set-Cookie: PHPSESSID=98bef3ac7d4ff6ba2c97822d2de167ee; path=/
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Set-Cookie: kaboom_playspacefinder=connect.kaboom.org%2C189.182.114.45%2C98bef3a
c7d4ff6ba2c97822d2de167ee; expires=Tue, 03-Mar-2009 00:26:11 GMT; domain=kaboom.
org
def pm(object)
identifiers = %w[ + - > # ]
list =
case (object)
when Class:
puts "#{object} (Class)"
[
(object.methods.sort - Class.methods),
(object.private_methods.sort - Class.private_methods),
#!/usr/bin/env ruby
class Array
def unique_by
inject(Hash.new(0)) do |h, i|
h[yield(i)] += 1
h
end.size == size
end
end
class Hash
def dig(*path)
path.inject(self) do |location, key|
location.respond_to?(:keys) ? location[key] : nil
end
end
end
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/environment'
conn = ActiveRecord::Base.connection
STDOUT.sync = true
while (true)
print "\e[;H"