Skip to content

Instantly share code, notes, and snippets.

View johnciacia's full-sized avatar
👋

John Ciacia johnciacia

👋
View GitHub Profile
@johnciacia
johnciacia / ocr.php
Created November 7, 2010 19:56
This is a very basic optical character recognition script written in PHP. This is untested and serves merely a proof of concept. As noted in the comments, adjusting the sample size can improve results, since with a large sample size on a small image there
<?php
/* create a test image */
$im = @imagecreate(100, 20) or die("Cannot Initialize new GD image stream");
$background_color = imagecolorallocate($im, 255, 255, 255);
$text_color = imagecolorallocate($im, 0, 0, 0);
imagestring($im, 1, 5, 5, "Hello, World!", $text_color);
/***
* Assumptions:
@johnciacia
johnciacia / border.php
Created November 7, 2010 19:57
Add a border to text using GD
<?php
/**
* Writes the given text with a border into the image using TrueType fonts.
* @author John Ciacia
* @param image An image resource
* @param size The font size
* @param angle The angle in degrees to rotate the text
* @param x Upper left corner of the text
* @param y Lower left corner of the text
* @param textcolor This is the color of the main text
@johnciacia
johnciacia / itoa.c
Created November 7, 2010 20:00
Convert an integer to an ASCII string
/* K&R2 60-63 */
char *itoa(int n, char s[])
{
int c, i, j, sign;
if((sign = n) < 0)
n = -n;
do {
s[i++] = n % 10 + '0';
@johnciacia
johnciacia / sierpinski.html
Created December 15, 2010 23:36
Sierpinski's Triangle IFS
<!DOCTYPE html>
<html>
<head>
<title>Sierpinski Triangle</title>
</head>
<body>
<canvas id="sierpinski">
Oops! Your browser does not support HTML5 Canvas.
@johnciacia
johnciacia / permute.lsp
Created December 15, 2010 23:47
Generate the permutations of a given list
* (load "permute.lsp")
; Loading #p"/home/john/permute.lsp".
T
* (p (list 'a 'b 'c 'd 'e))
((A B C D E) (A B C E D) (A B D C E) (A B D E C) (A B E C D) (A B E D C)
(A C B D E) (A C B E D) (A C D B E) (A C D E B) (A C E B D) (A C E D B)
(A D B C E) (A D B E C) (A D C B E) (A D C E B) (A D E B C) (A D E C B)
(A E B C D) (A E B D C) (A E C B D) (A E C D B) (A E D B C) (A E D C B)
@johnciacia
johnciacia / Autocomplete Demo
Created May 14, 2011 19:12
autocomplete.html
<!DOCTYPE html>
<html>
<head>
<title>jQuery Autocomplete Demo</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.0/jquery.min.js" type="text/javascript"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.12/jquer
y-ui.min.js" type="text/javascript"></script>
</head>
<?php
$a = array(3, 2, 1, 5, 9, 0, 7, 4, 6, 8);
while(!is_sorted($a))
shuffle($a);
print_r($a);
@johnciacia
johnciacia / bmp.c
Created July 18, 2011 02:28
Encode text in a BMP image format
//because I can...
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
int main(int argc, char **argv) {
if(argc != 3)
@johnciacia
johnciacia / e.c
Created July 18, 2011 22:25
Calculate the value of e as the sum of the infinite series
#include <stdio.h>
/**
* This code will calculate e
* as the sum of the infinite series
* 1/1! + 1/2! + 1/3! + ... + 1/n!
* g++ e.c
* ./a.out
*/
int factorial(unsigned int i);
<?php
/**
* Calculate the binary value needed to
* display hexidecmal 0-F on a seven-segment
* display for an ARM
*/
(strpos($argv[1], "a") !== false) ? $a = 1 : $a = 0;
(strpos($argv[1], "b") !== false) ? $b = 1 : $b = 0;
(strpos($argv[1], "c") !== false) ? $c = 1 : $c = 0;