Skip to content

Instantly share code, notes, and snippets.

@dannymcc
dannymcc / branch-wireshark
Created November 14, 2011 09:53
Branch Wireshark
No. Time Source Destination Protocol Length Info
1 0.000000 192.168.1.99 192.168.3.12 TCP 54 printer > 43664 [ACK] Seq=1 Ack=1 Win=740 Len=0
Frame 1: 54 bytes on wire (432 bits), 54 bytes captured (432 bits)
Ethernet II, Src: Draytek_e6:eb:40 (00:50:7f:e6:eb:40), Dst: IntelCor_dc:6a:d0 (00:27:10:dc:6a:d0)
Internet Protocol Version 4, Src: 192.168.1.99 (192.168.1.99), Dst: 192.168.3.12 (192.168.3.12)
Transmission Control Protocol, Src Port: printer (515), Dst Port: 43664 (43664), Seq: 1, Ack: 1, Len: 0
No. Time Source Destination Protocol Length Info
2 0.000112 192.168.1.99 192.168.3.12 TCP 54 [TCP Window Update] printer > 43664 [ACK] Seq=1 Ack=1 Win=2100 Len=0
@dannymcc
dannymcc / incoming_calls.rake
Created January 7, 2012 14:52
nokogiri and mechanize
desc "Import incoming calls"
task :fetch_incomingcalls => :environment do
# Logs into manage.phoneprovider.co.uk and retrieved list of incoming calls.
require 'rubygems'
require 'mechanize'
require 'logger'
# Create a new mechanize object
agent = Mechanize.new { |a| a.log = Logger.new(STDERR) }
@dannymcc
dannymcc / dial9.html
Created January 12, 2012 14:37
dial9 html
<tr class='o'>
<tr>
<td>06 Jan 21:01</td>
<td></td>
<td>1234567891</td>
<td>00:02:21</td>
<td></td>
<td class='opt recording'></td>
</tr>
</tr>
<?php include('perch/runtime.php'); ?>
<!doctype html>
<!--[if lt IE 7 ]> <html class="ie ie6 no-js" lang="en"> <![endif]-->
<!--[if IE 7 ]> <html class="ie ie7 no-js" lang="en"> <![endif]-->
<!--[if IE 8 ]> <html class="ie ie8 no-js" lang="en"> <![endif]-->
<!--[if IE 9 ]> <html class="ie ie9 no-js" lang="en"> <![endif]-->
<!--[if gt IE 9]><!--><html class="no-js" lang="en"><!--<![endif]-->
<!-- the "no-js" class is for Modernizr. -->
# Be sure to restart your server when you modify this file.
#
# This file contains settings for ActionController::ParamsWrapper which
# is enabled by default.
# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
ActiveSupport.on_load(:action_controller) do
wrap_parameters format: [:json]
end
@dannymcc
dannymcc / app.rake
Created March 11, 2012 22:46 — forked from ChuckJHardy/app.rake
Rake Task for Database Population
------------ From Rake Task
namespace :app do
# Checks and ensures task is not run in production.
task :ensure_development_environment => :environment do
if Rails.env.production?
raise "\nI'm sorry, I can't do that.\n(You're asking me to drop your production database.)"
end
end
# Add each row to a new call record
page = agent.page.search("table tbody tr").each do |row|
next if (!row.at('td'))
time, source, destination, duration = row.search('td')[1..5].map{ |td| td.text.strip }
call = Call.find_by_time(Time.parse(time))
call = Call.create_by_time(Time.parse(time))
call.update_attributes({:time => time, :source => source, :destination => destination, :duration => duration})
end
@dannymcc
dannymcc / gist:2287501
Created April 2, 2012 21:54
Legacy database table names
Add this to the model
set_table_name  'old_table_name'
set_primary_key 'old_key_column'
desc "Import Service Provider Location"
task :fetch_serviceproviderlocation => :environment do
# Logs into service provider and retrieved latitude and longitude.
require 'rubygems'
require 'mechanize'
require 'logger'
require 'nokogiri'
# Create a new mechanize object
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!-- saved from url=(0028)http://www.serviceprovider.co.uk/ -->
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>serviceprovider</title>
<link href="css/screen.css" media="screen" rel="stylesheet" type="text/css" />
<!--[if lte IE 6]>
<link href="http://www.serviceprovider.co.uk/styles/default/screen_ie6.css" media="screen" rel="stylesheet" type="text/css" />