Skip to content

Instantly share code, notes, and snippets.

@witwall
witwall / 1 - setting up RVM.sh
Created April 6, 2013 08:55
RVM and Bundler on Dreamhost, I can access https://gist.github.com/muffinista/3276350, so I copy it from the google cache
#
# Step One - Installing RVM
#
curl -L https://get.rvm.io | bash -s stable --ruby
# Then, install ruby 1.8.7 -- you need to basically match the same version of Ruby as Dreamhost
rvm install ruby-1.8.7-p334
<IfModule mod_fastcgi.c>
AddHandler fastcgi-script .fcgi
</IfModule>
<IfModule mod_fcgid.c>
AddHandler fcgid-script .fcgi
</IfModule>
Options +FollowSymLinks +ExecCGI
RewriteEngine On
@witwall
witwall / gist:5334142
Created April 8, 2013 03:56
Here’s the code to replace images in PDFs, in Java and C#. It will replace the first image in the first page.
PdfReader pdf = new PdfReader("in.pdf");
PdfStamper stp = new PdfStamper(pdf, new FileOutputStream("c:\\out.pdf"));
PdfWriter writer = stp.getWriter();
Image img = Image.getInstance("image.png");
PdfDictionary pg = pdf.getPageN(1);
PdfDictionary res =
(PdfDictionary)PdfReader.getPdfObject(pg.get(PdfName.RESOURCES));
PdfDictionary xobj =
(PdfDictionary)PdfReader.getPdfObject(res.get(PdfName.XOBJECT));
if (xobj != null) {
import java.awt.Graphics;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.HeadlessException;
import java.awt.Image;
import java.awt.Transparency;
import java.awt.image.BufferedImage;
import java.awt.image.ColorModel;
import java.awt.image.PixelGrabber;
@witwall
witwall / deskew.java
Created May 12, 2013 22:27
Automatic image deskew in Java http://anydoby.com/jblog/en/java/1990 Those who have to process scans should know how painful it is to manually deskew images. There are several approaches to do this deskewing automatically. The basis of all the methods is to identify lines following the same direction in a image and then by deviation from horizon…
public double doIt(BufferedImage image) {
final double skewRadians;
BufferedImage black = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_BYTE_BINARY);
final Graphics2D g = black.createGraphics();
g.drawImage(image, 0, 0, null);
g.dispose();
skewRadians = findSkew(black);
System.out.println(-57.295779513082320876798154814105 * skewRadians);
return skewRadians;
@witwall
witwall / svg.vba
Created May 17, 2013 13:14 — forked from wintercn/svg.vba
' svg.vba released 11.08.2002
Private Function get_export_scaling_factor() As Single
'' point to pixel conversion factor
get_export_scaling_factor = (4 / 3)
End Function
@witwall
witwall / hosts
Created November 4, 2013 14:25
hosts
#UPDATE:2013-07-07 21:01
127.0.0.1 localhost
#SmartHosts START
#Google Services START
203.208.46.200 0.docs.google.com
203.208.46.200 0.drive.google.com
203.208.46.200 1.docs.google.com
@witwall
witwall / monitrc
Created July 1, 2014 04:38 — forked from franck/monitrc
###############################################################################
## Monit control file
###############################################################################
##
## Comments begin with a '#' and extend through the end of the line. Keywords
## are case insensitive. All path's MUST BE FULLY QUALIFIED, starting with '/'.
##
## Below you will find examples of some frequently used statements. For
## information about the control file, a complete list of statements and
## options please have a look in the monit manual.
@witwall
witwall / pdf2bmp.cc
Last active August 29, 2015 14:03
Converting PDF to Bitmap with the help of PDFium and EasyBMP
//for detail, please visit
//http://blog.rubypdf.com/2014/07/08/convert-pdf-to-bitmap-with-pdfium
//do not forget #include "EasyBMP.h" first
static void WriteBmp(const char* pdf_name, int num,
const char* buffer, int stride
, int width, int height) {
BMP bmp;
bmp.SetSize(width,height);
// Set its color depth to 32-bits
bmp.SetBitDepth(32);
@witwall
witwall / pdfdecrypt.cpp
Created July 10, 2014 10:39
Decrypt PDF(remove pdf password and limitations) with pdfium
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "../fpdfsdk/include/fpdfview.h"
#include "../fpdfsdk/include/fpdfsave.h"
/*
author:Steven Lee