Skip to content

Instantly share code, notes, and snippets.

@rungiraffe
rungiraffe / cleanquadrant.py
Created November 23, 2012 17:26
re.verbose
import re
#This is the same as (\,*? N\. ?E.)
#All spaces need to be escaped in verbose mode.
ne_pattern = re.compile(r """
( #start group
\,*? #look for comma (escaped); *? = 0 or more commas with fewest results
\ N\.? #look for (escaped) space + N that might have an (escaped) period after it
\ ?E #look for an E that may or may not have an space in front of it
. #the E might be followed by another character.
) #close group
@rungiraffe
rungiraffe / cartogram.js
Created November 12, 2012 19:14
Cartogram with missing states
//Attempting to get a d3 non-contiguous cartogram to work when data for some states does not exist.
// Ratio of state delegations in the 43rd Congress
var data = [
,0.025,0,0.003,0.018,0.018,0.003,0.018,0.008,0.003,0.01,0.03,0,0.003,0.056,0.038,0.028,
0.018,0.03,0.02,0.018,0.02,0.04,0.03,0.013,0.023,0.038,0.003,0.008,0.008,0.013,0.023,
0.003,0.096,0.025,0.003,0.058,0,0.01,0.076,0.01,0.02,0,0.03,0.02,0.003,0.013,0.03,0.003,
0.013,0.025,0.003,0
];
@rungiraffe
rungiraffe / address-functions.php
Created October 24, 2012 23:59
$_GET Array - Empty = NULL
<?php
/*My old nemisis, NULL, but this time I think it's a problem with my understanding of key value pairs. Both $_GET array and $Drop array return the following in a variable dump. I WANT $Drop to return NULL for empty values:
array(8) { ["street"]=> string(14) "106 3rd St. NW" ["new_street"]=> string(0) "" ["city"]=> string(10) "Washington" ["new_city"]=> string(0) "" ["state"]=> string(2) "DC" ["new_state"]=> string(0) "" ["new_modern_address"]=> string(0) "" ["new_hotel"]=> string(0) "" }
*/
include 'connect.php';
@rungiraffe
rungiraffe / google.html
Created October 16, 2012 00:24
Mapstraction API with Google and OpenLayer APIs
<!--Based on code in the API sandbox: http://mapstraction.appspot.com/#image_overlay. JS documentation here: http://www.mapscripting.com/mxndocs
/index.html
THIS CODE ONLY RENDERS BASE MAP
http://rungiraffe.com/clio3/mapexample/mapstraction/openlayers.html
-->
<html>
<head>
@rungiraffe
rungiraffe / congress-year-functions.php
Created September 26, 2012 22:47
For Blog Entry (20120926)
//Functions to calculate congress start and end years
function congressStart($congress) {
$start_calc = $congress * 2 + 1787;
return $start_calc;
}
function congressEnd($congress) {
$end_calc = $congress * 2 + 1789;
return $end_calc;
}
@rungiraffe
rungiraffe / connect.php
Created September 26, 2012 02:40
"C" is for CRUD - A form for creating entries in my database.
<?php
//Connect to mysql
$connect = mysql_connect("","","");
if (!$connect) {
die('Could Not Connect to MySQL');
}
//else echo "You are in mysql.<br />";
//Connect to database dc_address
mysql_select_db('dc_address_test') or die('You are not in dc_address_test.');
@rungiraffe
rungiraffe / joiner.php
Created September 26, 2012 02:20
Joiner Table Won't Update when NULL
/* The joiner table won't update when address_id is NULL. Table is structured so that address_id_fk will take a NULL value. Any ideas? */
$join_congq = "INSERT INTO join_cong (congress_num, bio_id_fk, address_id_fk, party_id_fk)
VALUES ('$congress','$bio_id','$address_id', '$party_id')";
//Update join_cong joiner table and check for failure
if (mysql_query($join_congq)){
echo ("<strong>The join_cong joiner table has been updated</strong>".$break);
echo ("Query: ".$join_congq.$break);
echo ("Data: ".$congress.$comma.$bio_id.$comma.$address_id.$comma.$party_id.$break);
@rungiraffe
rungiraffe / update-functions.php
Created September 25, 2012 02:46
C in CRUD 20120924
<?php
include 'connect.php';
//UNIVERSAL VARIABLES
$comma = ", ";
$break = "<br />";
//CONGRESS
@rungiraffe
rungiraffe / address.php
Created September 25, 2012 01:31
"OR" querying problem
/* Having trouble dealing with NULL values.
In some cases $street has a value and $hotel = NULL;
Sometimes $hotel has a value and $street = NULL;
Sometimes they both are NULL.
This code seems to require BOTH a street AND a hotel. I want to test for either or.
(for context see below) */
//Create variable containing MySQL Query for finding existing street.
@rungiraffe
rungiraffe / address-check.php
Created September 23, 2012 18:27
Trying to return empty strings as NULL
//Create variables for the bio entries
$street = mysql_real_escape_string($_POST['street']);
$city = mysql_real_escape_string($_POST['city']);
$state = $_POST['state'];
$hotel = mysql_real_escape_string($_POST['hotel']);
$modern_address = mysql_real_escape_string($_POST['modern_address']);
//Check for blank entries; make them NULL
if (empty($street)) {
$street = NULL;