Skip to content

Instantly share code, notes, and snippets.

View sharpred's full-sized avatar

Paul Ryan sharpred

View GitHub Profile
@sharpred
sharpred / renamepdffields.vb
Created December 3, 2010 11:01
sample code to rename pdf fields created with period/full stops in fieldname
Function ChangeFieldNamesInForm()
Try
Dim sourcePDF As String = "source.pdf"
Dim outputPDF As String = "destination.pdf"
Dim fsw As FileStream = New FileStream(outputPDF, FileMode.OpenOrCreate, FileAccess.ReadWrite)
Dim reader As PdfReader = New PdfReader(sourcePDF)
Dim stamper As PdfStamper = New PdfStamper(reader, fsw)
Dim root As PdfDictionary = reader.Catalog()
Dim form As PdfDictionary = root.GetAsDict(PdfName.ACROFORM)
Dim fields As PdfArray = form.GetAsArray(PdfName.FIELDS)
@sharpred
sharpred / drupalhelper.vb
Created August 17, 2011 09:50
Drupal helper functions based on an article at http://drupal.org/node/308629
Imports System.IO
Imports System.Text
Imports System.Security.Cryptography
Public Class DrupalHelper
'most of the ideas here came from an article at http://drupal.org/node/308629
Public Function getUnixTimestamp() As String
Dim ts As New TimeSpan
@sharpred
sharpred / DrupalForm.vb
Created August 17, 2011 09:52
creates an HttpMultipartMimeForm for sending a request to a Drupal6 service
Imports Microsoft.Http
Imports System.Text
Public Class DrupalForm
Public Function create(ByVal type As String, ByVal formatoutput As Boolean, ByVal authenticate As Boolean) As HttpMultipartMimeForm
Dim form As New HttpMultipartMimeForm
Dim helper As New DrupalHelper
Dim method As String = Nothing
Dim methodstring As String = Nothing
Try
@sharpred
sharpred / consoleapp.vb
Created August 17, 2011 09:54
Simple console app that posts a form to a drupal 6 service to return a view in JSON format
Imports Microsoft.Http
Imports Microsoft.Http.HttpClient
Imports Microsoft.Http.HttpMethodExtensions
Imports Newtonsoft.Json
Imports Newtonsoft.Json.Converters
Imports System.Net
Imports System.Xml
Imports System.IO
Imports System.Text
Module Module1
@sharpred
sharpred / mapview
Created December 9, 2011 10:06
map code
win.addEventListener('focus',function() {
//create map annotation
longitude = -1.7933350801467896;
latitude = 51.531768798828125;
objLocationAnnotation = Titanium.Map.createAnnotation({
        latitude: latitude,
        longitude: longitude,
        title:"Issue",
        animate:true
    });
@sharpred
sharpred / fblike
Created December 12, 2011 10:38
Facebook Like Button
<html>
<head>
</head>
<body>
<div id="fb-root"></div>
<script>(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "http://connect.facebook.net/en_GB/all.js#xfbml=1&appId=171477789617721";
@sharpred
sharpred / uploads.json
Created May 23, 2012 09:44
uploads data
{ "_id" : ObjectId("4fb10c8aaaf231ec96000009"), "id" : 21, "claimid" : "SUS14052012-004", "data" : { "id" : 2, "claimid" : "SUS14052012-004", "status" : "updated", "validationstatus" : 0, "locationtype" : "externaldamage", "locationid" : 1, "ratetype" : 3, "roomshape" : 1, "groupedrepairlist" : null, "otherscopelist" : null, "nonlistedlist" : null, "formid" : "scopeofworks" }, "status" : "pending", "type" : "data", "devicepin" : "testuser", "modified" : ISODate("2012-05-14T13:45:46.507Z"), "created" : ISODate("2012-05-14T13:45:46.507Z") }
{ "_id" : ObjectId("4fb10c8aaaf231f68f000006"), "id" : 20, "claimid" : "SUS14052012-004", "data" : { "id" : 1, "claimid" : "SUS14052012-004", "status" : "updated", "validationstatus" : 0, "locationtype" : "internaldamage", "locationid" : 1, "ratetype" : 1, "roomshape" : 1, "roomlength" : 2, "roomwidth" : 2, "roomheight" : 2, "floorceilingarea" : 4, "perimeter" : 8, "wallarea" : 16, "groupedrepairlist" : "[{\"groupedrepairitemcode\":\"GRI02\",\"groupedrepairitemunits\":\"4\"}
@sharpred
sharpred / getMongoAttachment.php
Created May 23, 2012 12:00
retrieve mongo attachment data, iterate through and retrieve each file
<?php
$mongoDB = new Mongo();
$database = $mongoDB->selectDB("BVS");
$collection = $database->createCollection('fs.files');
//to get the attachments metadata back
$query = array("metadata.formdata.claimid" => "SUS14052012-001");
// $items is a cursor of mongodata
$items = $collection->find($query);
//iterate through the collection and retrieve the named file
$grid = $database->getGridFS();
@sharpred
sharpred / howrweajax.js
Created June 1, 2012 12:53
howrwe json callback
/*global $ Highcharts */
$(function () {
$(document).ready(function () {
$.ajax({
url: 'http://www.stepupsoftware.co.uk/howrwe.json',
method: 'GET',
async: false,
success: function (chartvalues) {
var chart = new Highcharts.Chart({
chart: {
@sharpred
sharpred / howrwejson.js
Created June 1, 2012 12:55
howrwe getjson
$(function() {
$(document).ready(function() {
$.getJSON('howrwe.json', function(chartvalues) {
var chart = new Highcharts.Chart({
chart: {
renderTo: 'container',
type: 'bar'
},
tooltip: {
formatter: function() {