Skip to content

Instantly share code, notes, and snippets.

CREATE OR REPLACE function join ( p_cursor sys_refcursor, p_del varchar2 := '; ' )
return varchar2 is l_value varchar2(32767);
l_result varchar2(32767);
begin loop fetch p_cursor into l_value;
exit when p_cursor%notfound;
if l_result is not null then
l_result := l_result || p_del;
end if;
l_result := l_result || l_value;
end loop;
@jak
jak / gist:796979
Created January 26, 2011 16:45
Pictures over Web Services - Service side
[WebMethod]
public string GetPicture() {
// Load the picture
Image img = Image.FromFile("Path/To/Picture.jpg");
// Create a memory stream, and put the image contents into it.
MemoryStream stream = new MemoryStream();
img.Save(stream, img.RawFormat);
// return data, encoded in Base64
return Convert.ToBase64String(stream.ToArray());
}
@jak
jak / gist:796985
Created January 26, 2011 16:48
Pictures over Web Services - Client side
private void LoadImage() {
// Create web service
WebServiceSoapClient service = new WebServiceSoapClient();
// Fetch encoded image using the web service method
string encodedImage = service.GetPicture();
// turn the Base64 string back into bytes
byte[] buffer = Convert.FromBase64String(encodedImage);
// create a stream from the data
MemoryStream stream = new MemoryStream(buffer, false);
// recreate Image object, and display it in pictureBox1
@jak
jak / gist:826196
Created February 14, 2011 17:20
c# accessing database example
public List<String> GetFirstNames(string surname) {
List<String> names = new List<String>();
using (SqlConnection con = new SqlConnection(<connection string>)) {
using (SqlCommand cmd = new SqlCommand("SELECT firstname FROM People WHERE surname=@surname", con)) {
cmd.Parameters.AddWithValue("@surname", surname);
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read()) { // while there is data
string name = reader["firstname"].ToString(); // for other data, use Convert.ToInt32() etc
names.Add(name);
}
@jak
jak / dnsmasq-setup.py
Created March 3, 2012 21:51
Setup script for dnsmasq on sandbox
#!/usr/bin/python
#
# Sandbox dnsmasq setup script
#
# Jak Spalding <jak.spalding@bbc.co.uk>
# 2012-03-03
#
# for Python 2.4
import re
@jak
jak / gist:2466500
Created April 22, 2012 19:57
from_time()
<?php
function pluralise($count, $single, $plural = null) {
if ($count == 1 || $count == -1) {
return $single;
}
if ($plural == null) {
$plural = $single . 's';
}
return $plural;
@jak
jak / gist:2483923
Created April 24, 2012 21:23
kohana php-fpm and nginx
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /index.php {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
}
@jak
jak / How to convert P12 to PEM file
Last active December 27, 2015 11:19
How to convert P12 to PEM file
openssl pkcs12 -in myfile.p12 -out newfile.pem -nodes
#!/usr/bin/env ruby
require 'fileutils'
def guess_name(name)
md = /([\w\.]+)\.(\d{4})\..*/i.match(name)
moviename = md[1].gsub(/\./, ' ')
year = md[2]
"#{moviename} (#{year})"
end
@jak
jak / gist:70a40c45dd008f5759ff
Created September 1, 2014 08:42
Need a faster hard drive temporarily? Use a RAM disk on OS X
› diskutil erasevolume HFS+ 'RAM Disk' `hdiutil attach -nomount ram://4194304` # Create a 2GB ramdisk
› rsync -avr Code/ /Volumes/RAM\ Disk/ # Copy your work over
› open /Volumes/RAM\ Disk/ # Open in Finder
# Change ram://XXXX to MB required x 2048 (4194304 = 2048 x 2048)
# 1GB = 2097152
# 2GB = 4194304
# 3GB = 6291456
# 4GB = 8388608
# 8GB = 16777216