Skip to content

Instantly share code, notes, and snippets.

@abronte
abronte / gist:394371
Created May 8, 2010 05:22
Simple web server
#!/usr/bin/ruby
require 'rubygems'
require 'mongrel'
server = Mongrel::HttpServer.new("0.0.0.0", "3000")
server.register("/", Mongrel::DirHandler.new("."))
server.run.join
~/.node_libraries/redis-client.js
client = require('redis-client');
@abronte
abronte / PHP Image resize
Created October 4, 2010 02:56
PHP image resize
$image_w = imagesx($image);
$image_h = imagesy($image);
//figure out if we are going to resize by the width or the height
//if the original image is wider than the new dimension, resize by the width
// or else resize by the height
if (($image_w / $image_h) >= ($new_w / $new_h)) {
$h = $image_h * $new_w / $image_w;
$w = $new_w;
} else {
@abronte
abronte / resize_crop.php
Created October 5, 2010 02:21
PHP image crop resize
//if the image if taller than wide, resize W to desired length then crop the top and bottom to fit
if($image_w < $image_h) {
$tmp_h=$image_h*($new_h/$image_w);
$tmp_big = imagecreatetruecolor($new_w, $tmp_h);
$tmp = imagecreatetruecolor($new_w, $new_h);
$diff = ($tmp_h - $new_h)/2;
imagecopyresampled($tmp_big,$image,0,0,0,$diff,$new_w,$tmp_h,$image_w,$image_h);
imagecopyresampled($tmp,$tmp_big,0,0,0,$diff,$new_w,$new_h,$new_w,$new_h);
@abronte
abronte / HTML5_drawImage.js
Created December 16, 2010 22:32
draw image from a sprite
//get canvas element
var canvas = document.getElementById("main");
//get context
var ctx = canvas.getContext('2d');
//create new image object
var image = new Image();
//set callback for when the image actually loads
@abronte
abronte / gist:1085702
Created July 15, 2011 22:28
break it down
var nickname = "";
var socket;
//send the chat server your nickname and close the dialog box
function joinChat()
{
socket.emit('join', nickname);
$("#nick-modal").dialog('close')
}
@abronte
abronte / gist:1098535
Created July 21, 2011 23:57
Javascript type coercion
'' == '0' // false
0 == '' // true
0 == '0' // ture
false == 'false' // false
false == '0' // true
false == undefined // false
false == null // false
null == undefined // true
#!/bin/bash
nohup perl runner.pl -Delete=1 -LinkID=330410154 -AssumedDate=2011-08-02 -DoCache=1 &
/* REMOVE */
use lib "/usr/local/navivision/spidering/common";
use NVParser;
/* ADD */
BEGIN {
unshift (@INC, "$ENV{'CRAWLER_PATH'}/common");
}