Skip to content

Instantly share code, notes, and snippets.

@tony-landis
tony-landis / pdo-adodb-singleton-refactor.class.php
Created December 3, 2008 07:44
PHP PDO Singleton w/AdoDB backwards compatable
<?php
/**
* PDO SINGLETON CLASS, ADODB ENABLED
*
* @author Tony Landis
* @link http://www.tonylandis.com
* @license Use how you like it, just please don't remove or alter this PHPDoc
*/
class sdb
{
# used to alter columns in postgresql
module AlterColumn
def alter_column(table_name, column_name, new_type, mapping, default = nil)
drop_default = %Q{ALTER TABLE #{table_name} ALTER COLUMN #{column_name} DROP DEFAULT;}
execute(drop_default)
# puts drop_default
base = %Q{ALTER TABLE #{table_name} ALTER COLUMN #{column_name} TYPE #{new_type} }
if mapping.kind_of?(Hash)
contains_else = mapping.has_key?("else")
// Simple spreadsheet, with first sheet containing form submission repsonses
// when the form is submitted:
// 1) grab the latest response,
// 2) post it to a third party service via an HTTP POST
function testWebhook() {
var ss = SpreadsheetApp.openById(SPREADSHEET_ID);
var form=ss.getSheets()[0];
var lr=form.getLastRow();
var el=form.getRange(lr,2,1,1).getValue();
var t=el;
@hubgit
hubgit / html-purifier-strict.php
Created August 18, 2010 15:21
strict purification of HTML using HTMLPurifier
<?php
$url = 'http://en.wikipedia.org/wiki/1,1,1-Trichloroethane'; // example
$config = HTMLPurifier_Config::createDefault();
$config->set('URI.Base', $url); // set the base URL (overrides a <base element in the HTML head?)
$config->set('URI.MakeAbsolute', true); // make all URLs absolute using the base URL set above
$config->set('AutoFormat.RemoveEmpty', true); // remove empty elements
$config->set('HTML.Doctype', 'XHTML 1.0 Strict'); // valid XML output (?)
$config->set('HTML.AllowedElements', array('p', 'div', 'a', 'br', 'table', 'thead', 'tbody', 'tr', 'th', 'td', 'ul', 'ol', 'li', 'b', 'i'));
@kaylarose
kaylarose / RaphaelJSShapeDrawingApp.html
Created November 11, 2010 21:07
A Simple Vector Shape Drawing App with RaphaelJS and jQuery
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js"></script>
<script src="http://yandex.st/raphael/1.5.2/raphael.min.js"></script>
<script>
/**
* A Simple Vector Shape Drawing App with RaphaelJS and jQuery
* copyright 2010 Kayla Rose Martin - Licensed under the MIT license
* Inspired by http://stackoverflow.com/questions/3582344/draw-a-connection-line-in-raphaeljs
**/
@stomita
stomita / SimpleSalesforceConnection.js
Created May 25, 2011 08:40
A Google Apps Script, which simply connects and fetches data from Salesforce RESTful API with OAuth authentication.
/**
* Connect and fetch Salesforce data via OAuth
*/
function queryDataFromSalesforce() {
// Read OAuth consumer key / secret of this client app from script properties,
// which can be issued from Salesforce's remote access setting in advance.
var sfConsumerKey = ScriptProperties.getProperty("sfConsumerKey");
var sfConsumerSecret = ScriptProperties.getProperty("sfConsumerSecret");
if (!sfConsumerKey || !sfConsumerSecret) {
Browser.msgBox("Register Salesforce OAuth Consumer Key and Secret in Script Properties");
@naaman
naaman / gist:1053217
Created June 29, 2011 05:33
Hot Swapping With Maven, Jetty and IntelliJ

Hot Swapping With Maven, Jetty and IntelliJ

Based on Configuring Jetty, Maven, and Eclipse together with Hot Swap

I've always been a bit jealous when it comes to the Play! framework and the great dev mode they have for hot swapping classes at runtime. Jetty has a configuration setting, scanIntervalSeconds, that mimics this when working with a more traditional WAR, but does so by looking for changes to a file and restarting the server.

Fortunately, Jetty also provides the ability to rapidly test code with hot swapping. No more server restarts. The trick to getting hot swapping to work is to attach a remote debugger to your Jetty process. The following instructions outline how to do this in IntelliJ (tested with IDEA 10.5 CE).

Modify your jetty-maven-plugin to ignore the scan interval

  1. Open your pom and locate the plugins section
@mhawksey
mhawksey / gist:1276293
Last active October 23, 2023 09:00
Google App Script to insert data to a google spreadsheet via POST or GET - updated version as per https://mashe.hawksey.info/2014/07/google-sheets-as-a-database-insert-with-apps-script-using-postget-methods-with-ajax-example/
/*
Copyright 2011 Martin Hawksey
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
@bortzmeyer
bortzmeyer / gist:2605348
Created May 5, 2012 20:21
Sample Apache's mod_security rules for rate-limiting
# Activates mod_security
SecRuleEngine On
# Only filters requests for /toto
SecRule REQUEST_FILENAME "!^/toto" "phase:1,skip:5,nolog"
# Only filters requests for rosalind
SecRule REQUEST_HEADERS:Host "rosalind\.abgenomica\.com" "phase:1,skip:5,nolog"
# Stores the number of visits in variable IP.pagecount
SecAction "phase:1,nolog,initcol:IP=%{REMOTE_ADDR},setvar:IP.pagecount=+1,expirevar:IP.pagecount=60"
# Denies requests when excessive
# 429 would be a better error status but mod_security rewrites it as 500 :-(
@erkie
erkie / background.html
Created May 19, 2012 09:43
Save parts of screen using Chrome extension
<script>
var Constants = {
saveURL: 'http://random/birthday/saveimage.php',
w: 500,
h: 500,
x: 200,
y: 200
};