Skip to content

Instantly share code, notes, and snippets.

View octavian-nita's full-sized avatar
:octocat:

Octavian Nita octavian-nita

:octocat:
View GitHub Profile
@octavian-nita
octavian-nita / PdfPageExtractor.java
Created September 10, 2014 06:54
Handy class for splitting or extracting pages from PDF documents
package be.thon.util.pdf;
import static java.lang.Integer.valueOf;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
@octavian-nita
octavian-nita / setenv.bat
Last active August 29, 2015 14:07
Set the Java environment
@if "%DEBUG%"=="" @echo off
if [%1]==[test] goto test
echo Setting the Java environment... & echo.
if [%1]==[] set JAVA_HOME=C:\Progra~2\Java\jdk1.6.0_43
if [%1]==[6] set JAVA_HOME=C:\Progra~2\Java\jdk1.6.0_43
if [%1]==[7] set JAVA_HOME=C:\Progra~2\Java\jdk1.7.0_15
if [%1]==[8] set JAVA_HOME=C:\Progra~2\Java\jdk1.8.0_11
#!/bin/sh
sudo /etc/init.d/mysql stop
# OR
sudo /etc/init.d/mysqld stop
sudo mysqld_safe --skip-grant-tables
sudo mysql -u root << EOF
@octavian-nita
octavian-nita / xutil.js
Created November 17, 2014 11:33
Node.js / JavaScript useful code snippets
'use strict';
var log = require('./log');
exports.slug = function(name) {
return name || name.
replace(/^[-\s_]*[\[\(]*[\s\d]+[\]\)]*[-\s_]*/g, ''). // remove eventual leading index / number in name
replace(/^[-\s_]+|[-\s_]+$/g, ''). // remove leading and trailing spaces, dashes, underscores
replace(/[-\s_]+/g, config.slugSeparator); // join by defined slug separator
};
@octavian-nita
octavian-nita / mime.js
Last active August 29, 2015 14:09
Simple MIME types for Node.js
'use strict';
/**
* Ideas compiled from multiple sources (but trying to keep things simple):
* - https://github.com/h5bp/server-configs-apache/
* - https://github.com/jhermsmeier/node-mime (normally, I would use this one!)
* - https://github.com/broofa/node-mime
* - https://github.com/andris9/mimelib
*
* See also:
@octavian-nita
octavian-nita / log.js
Created November 17, 2014 14:02
Simple logging for Node.js
'use strict';
var config = require('./config');
/**
* @param {string} [level=INFO] by default, 'expected' (from a formatting point of view) values are: ERROR, WARN,
* WARNING, INFO and DEBUG.
*/
function log(level, messageOrError /* messagePart1, messagePart2, ... */) {
var
@octavian-nita
octavian-nita / gallery.js
Created November 17, 2014 14:03
Simple gallery entity for Node.js
@octavian-nita
octavian-nita / cache.js
Last active August 29, 2015 14:09
Simple cache for Node.js
'use strict';
var
EventEmitter = require('events').EventEmitter,
util = require('util'),
log = require('./log'),
DEFAULT_OPTIONS = { capacity: 200, evictionCount: 10 };
function Cache(options) {
@octavian-nita
octavian-nita / Console.java
Created November 17, 2014 14:09
Simple Java / Swing console
package net.codarium.util;
import static java.awt.Font.BOLD;
import static java.lang.Boolean.TRUE;
import static java.lang.System.getProperty;
import static javax.swing.JEditorPane.HONOR_DISPLAY_PROPERTIES;
import static javax.swing.JFrame.EXIT_ON_CLOSE;
import static javax.swing.SwingUtilities.invokeLater;
import static javax.swing.UIManager.getSystemLookAndFeelClassName;
import static javax.swing.UIManager.setLookAndFeel;
<?php
class ThonResizer extends KokenPlugin
{
function __construct()
{
// Get information about the available graphics processing library:
list($version, $lib) = Darkroom::processing_library_version();
// Only install the hook if Imagick is available (no GD support for the moment):