Mischiefblog
I make apps for other people

OMG Eclipse

Posted by Chris Jones
On March 19th, 2014 at 09:02

Permalink | Trackback | Links In |

No Comments |
Posted in Java

I haven’t been using Eclipse since I worked at Amazon, except for a few short stints pulling configuration values from one project to another at Overstock. Now that I’m at IBM, the corporate home of the Eclipse Project, and on a project that requires it (because I can’t get the IntelliJ IDEA Rational Team Concert (RTC) plug-in to install correctly) I’m getting a chance to see just how bad parts of Eclipse are.

I’m missing:
* Search everywhere
* Being able to click a button to point to the current file in the project/workspace
* When creating new files, being able to scroll around and reference other files to maintain consistency in naming
* Find a file by name (not just a class name). I’ve got over 24,000 files in this project . . .

I can adapt to the keystrokes well enough, but I’d hate to see how Eclipse would dog on any less of a machine than the Lenovo W530 I’m using.

Mint VM setup

Posted by Chris Jones
On December 30th, 2013 at 13:13

Permalink | Trackback | Links In |

Comments Off
Posted in Java, Tech

On Windows, use VMWare. I’ve run into problems with Oracle VirtualBox and Windows networking, although it works very well on Linux.

On the Thinkpad T420s I needed to enable VT-x (Virtualization support) in the BIOS setup under the Security-Virtualization menu.

VM Configuration
For a Core i5 vPro with four cores, I assign:

  • Four GB of RAM
  • Two processors
  • 32 GB of disk in a single file

Distribution Choice
On my hardware (Thinkpad T420s) I’ve had problems with Fedora. Ubuntu derived distributions work fine, including Linux Mint. I’ll assume that you’re using Linux Mint 16 Petra 64-bit.

I’ll download the .iso version via BitTorrent. Both VMWare and VirtualBox can mount and use ISO files for VM installation, plus it boots significantly faster than physical media.
(more…)

A simple FastCGI bottle.py Python web application for Dreamhost

Posted by Chris Jones
On August 18th, 2012 at 16:55

Permalink | Trackback | Links In |

Comments Off
Posted in General

Here are instructions for setting up a simple bottle.py Python web application running on Dreamhost (shared) with virtualenv.
(more…)

HOWTO Create a CSV report from an Oracle query

Posted by Chris Jones
On August 3rd, 2012 at 13:09

Permalink | Trackback | Links In |

Comments Off
Posted in General

Here’s a simple shell script that turns an Oracle query into a CSV file suitable for mailing.
(more…)

HOWTO change your password in Oracle

Posted by Chris Jones
On July 25th, 2012 at 16:35

Permalink | Trackback | Links In |

Comments Off
Posted in General

With SQLPlus

Log into Oracle with SQLPlus.$ sqlplus user@dbname
SQL*Plus: Release 11.1.0.6.0 - Production on Mon Apr 12 11:46:48 2010

Copyright (c) 1982, 2007, Oracle. All rights reserved.

Enter password: <enter it here>

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options

SQL> password
Changing password for USER
Old password: <old pass>
New password: <new pass>
Retype new password: <new pass>
Password changed
SQL> CTRL-D
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options

With SQL Developer
To change your password in SQL Developer, log into the database in SQL Developer and execute the following statement:

alter user username identified by "newpassword" replace "oldpassword"

The quotes make the password safe for punctuation characters.

Shell scripts that make my life easier

Posted by Chris Jones
On July 25th, 2012 at 15:53

Permalink | Trackback | Links In |

Comments Off
Posted in General

Below, a series of shell scripts that make my life easier. Don’t expect any great revelations or virtuoso bash scripting.
(more…)

HOWTO proxy with nginx

Posted by Chris Jones
On July 25th, 2012 at 13:51

Permalink | Trackback | Links In |

Comments Off
Posted in General

These instructions assume you’re using a Debian/Ubuntu-based system.

  1. Create a web service/app (i.e., a Maven CXF JAX-RS archetype, or Flask/Bottle/Django, etc.)
  2. Install curl
    sudo apt-get install curl
  3. Install nginx
    sudo apt-get install nginx-full
    which should include nginx-common as a dependency.
  4. Do not start nginx yet.
  5. Add the nginx load balancer configuration and mime.types to your web service project (called MyProject in the following examples)
    1. Copy the mime.types definition file (as an alternative to copying the nginx configuration to /etc/nginx)
      cp /etc/nginx/mime.type ~/workspace/MyProject/web/conf
    2. Copy and modify the following load balancer/proxy configuration into MyProject/web/conf/balancer.nginx

      worker_processes 1;
          
      events {
          worker_connections 64;
          # multi_accept on;
      }
          
      http {
          upstream service-backend {
              server 127.0.0.1:9260;
              # server 127.0.0.1:8102;
              # server 127.0.0.1:8103;
              # server 127.0.0.1:8104;
          }
          
          keepalive_timeout 300 300;
          charset utf-8;
          default_type application/octet-stream;
          ignore_invalid_headers on;
          include mime.types;
          keepalive_requests 20;
          recursive_error_pages on;
          sendfile on;
          server_tokens off;
          source_charset utf-8;
          gzip on;
          gzip_static on;
          
          log_format main '$remote_addr $host $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" $ssl_cipher $request_time';
          
          server {
              listen 127.0.0.1:8100;
              server_name mydesktop.domain.com mydesktop;
              add_header Cache-Control public;
              access_log /var/log/nginx/access.log main buffer=32k;
              error_log /var/log/nginx/error.log error buffer=8k;
              expires max;
              root /opt/MyProject/web/html;
          
              location /svc/ {
                  proxy_pass http://127.0.0.1:9260;
              }
          
              location / {
              
              }
          
              location /favicon.ico {
                  return 204;
              }
              }
      }
  6. Create a directory to hold your static web content (HTML pages, images, JavaScript)
    mkdir MyProject/web/html
  7. Create a placeholder HTML file in the static web content/html directory
  8. Set your webservice to run on the /svc URI endpoint (to match the nginx configuration)
    1. Update the MyProject integration tests

      <parameter name="com.domain.webservices.AppRest.url"
      type="text" desc="Example service URL">
      %<value>http://localhost:9260/MyProject/svc</value>
      </parameter>
    2. Update the MyProject/web/conf/web.xml to map the Jersey web application to “/svc/*” (or whatever is appropriate for your app)
      <servlet-mapping>
      <servlet-name>Jersey Web Application/svc/*
  9. Build your project
    cd ~/workspace/MyProject
    mvn clean install
  10. Install and start your app (under /opt, for instance)
  11. Start nginx as root
    nginx -c /opt/Myproject/web/conf/balancer.nginx
  12. Verify your deployment
    1. Check your placeholder HTML page
      curl http://localhost:8100/index.html
    2. Check your service health
      curl http://localhost:8100/svc/health

HOWTO minify JavaScript

Posted by Chris Jones
On July 25th, 2012 at 13:32

Permalink | Trackback | Links In |

Comments Off
Posted in General
  1. Get a copy of jsmin.c from http://crockford.com/javascript/jsmin
  2. Compile jsmin with
    gcc -o jsmin jsmin.c
  3. Put jsmin in your path (i.e., under ~/bin)
  4. Minify JavaScript
  5. jsmin < input.js > output.min.js

As a best practice, when modifying third-party code rename your JavaScript file to something like filename.domain.min.js.

Scalability Secrets: custom content that scales

Posted by Chris Jones
On July 15th, 2012 at 11:35

Permalink | Trackback | Links In |

Comments Off
Posted in General

Caveat: this isn’t about failover, security, or cloud computing.

Imagine you have 65 million registered users and you need to provide custom content for each (beyond “Hello, Bob”), say real time subscription content from tens of thousands of sources containing millions of posts.

Don’t try to show everything at once

You probably won’t be able to show everything to the user at once. Depending on your load and back-end systems, you may be lucky to simply let the registered user know that they have something to see.

Most of your users won’t be logged in

Most page views (at least to a homepage) won’t be on logged-in users: many will be first time users, or users who haven’t visited very often. You’ll need to hit your back-end servers with a specific ratio of total visits, something you can measure early, and use as a baseline for how many servers you need to scale.
(more…)

Query timing with SQLPlus

Posted by Chris Jones
On June 15th, 2012 at 10:59

Permalink | Trackback | Links In |

Comments Off
Posted in General

SQL Developer is a good tool for creating queries, but you should be using SQLPlus when trying to time queries. If you don’t already have SQLPlus installed you can get it from Oracle:

http://www.oracle.com/technetwork/database/enterprise-edition/downloads/112010-linx8664soft-100572.html

You want Oracle Database 11g Release 2 Client (11.2.0.1.0) for Linux x86-64. Unizip the client in your home directory.

Make sure you have the following environment variables defined:


# these point to wherever you have Oracle installed
ORACLE_HOME=~/oracle/product/11.1.0/client_1
LD_LIBRARY_PATH=~/oracle/product/11.1.0/client_1
PATH=$PATH:~/oracle/product/11.1.0/client_1

If you plan to run PL/SQL DDL/DML scripts, you’ll also need a SQLPATH environment variable which points to a directory where you keep the scripts.

SQLPATH=~/sqlscripts

If you don’t already have your database defined in your /etc/tnsnames.ora file (assuming you’re using that path and not something under /home/oracle), you’ll need to add the following TNS configuration:


dbalias =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = dbhost)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = dbname)
    )
  )

To run SQLPlus against your database as a specific user, use the following command line:

sqlplus username@dbalias

Enter the password when prompted and you’ll now be at the SQL> prompt.

To get script timings, enter the PL/SQL command:

SET TIMING ON