Exploring Database Tables with jQuery

I woke up this morning tired of phpMyAdmin, and decided to take a stand.

phpMyAdmin is a web-based tool that most big hosting companies use for their shared hosting plans. It’s powerful in terms of the set of features it supports, but it’s NOT powerful in terms of ease-of-use and how much I can get done per minute using its interface. I think the reason all the big hosts use it is because of its long-time focus on security. After all, fewer customers will blame the host for a bad interface to the database as compared to the customers that will go nuts at the sight of any security issue (even though the customer himself is almost always at fault).

Anyway, there are several much better alternatives to phpMyAdmin (my favorite first):

  • SQL Buddy – Looks great, works great?
  • MonoQL – Looks even better, but it’s very new… where the documentation?
  • Adminer – Unlike the above two, this one is not AJAXified (aka Web 2.0). It’s just a leaner, cleaner, and more natural phpMyAdmin

Now on to the topic suggested by the title of this post… There are generally three things I do with a database:

  1. View table data.
  2. Edit table data.
  3. Edit table structure.

It hit me this morning, as I was sipping coffee in my despair over phpMyAdmin, that I do (1) a lot more than (2), and I do (2) a lot more than (3). Moreover, I really only want a better interface for (1) and maybe (2). So basically I just want a sexy Web 2.0 way of viewing table data. Luckily, jQuery inspired a ton of people to develop just such tools. Here are some awesome-looking examples (my favorite first):

Posted in Misc, Tools, Web Development | Tagged , , , | Leave a comment

Commas in a PHP For Loop

When generating a string that lists items (e.g. for a MySQL query) with a for-loop in PHP, you often need to add commas after every element except the last one.

It may be trivial advice, but instead of having an if statement that checks whether this is the last element in the list, use PHP’s implode.

while(list($column, $value) = each($FOO)) {
    $upd[] = " $column = '$value'";
}
$query = "UPDATE table SET ".implode(',',$upd)." WHERE blah = 3";

The above code takes the contents of the $FOO map and converts it into an SQL query (assuming in this example that all the values are stored as text).

Posted in Programming, Web Development | Tagged , , | Leave a comment

Markdown: Throw Away Your Mouse

Markdown is a markup language that’s used by StackOverflow and many other sites that I absolutely love. It converts **bold** into bold, `code` into code, etc. You can check out the official Markdown Syntax for more details and examples.

For those unsure what “problem” this addresses, it’s the problem of entering formatted text on the web. If you’re a blogger, for example, that has to insert images, bold text, headers, inline code, etc, you have many options. All these options ultimately generate HTML code. So, of course, you can just write HTML code yourself, but I find this to be (1) error-prone and (2) less readable during the writing/editing process. The benefit of writing HTML from scratch is that you only use the keyboard (no mouse) and have full control of the final result.

One step up from writing HTML code from scratch is writing in a slightly higher-level markup language like Markdown. It’s more readable, requires less typing, and still has the benefit of allowing you to keep your hands on the keyboard, and maintain good control of the look and feel of the final HTML.

StackOverflow (among many others) is a site that has embraced Markdown. That’s what sold it for me. The simplicity and power of a StackOverflow textbox is undeniable (at least to me).

 

Posted in Tools, Web Development | Tagged , , , , | Leave a comment

Janrain and Gigya: Sign in with Facebook, Google, etc

Janrain Engage and Gigya are two leading providers of “social sign-on” services. If you want users to use Facebook, Google, Twitter (or OpenID, etc) to log into your website for a “personalized experience”, it can be a pain in the a** to code that up. Since you need to keep up with the API of each service, and map the service-specific id to some centralized one that you can keep in a database.

Janrain and Gigya make it easy to do the pain-in-the-a** steps above to generate something like the pop-up shown in the image.

I find that trust is still a big problem in this process. Users seem to be reluctant to log in into any of the website I create using their Facebook. It probably has to do with the general reluctance of a user to click the “Yes” or “Okay” button when presented with a popup. I think a standardized interface such as the one that Janrain Engage and Gigya provide is a step into the right direction, where people will begin to associate this login process with something they can trust.

What’s the difference between Janrain and Gigya? Not much.

Basically, it boils down to Janrain being a little simpler to use but less feature rich, and Gigya having more features and steeper learning curve.

 

Posted in Tools, Web Development | Tagged , , , | 3 Comments

Styling Emacs Scrollbar in Ubuntu

Emacs uses GTK by default in Ubuntu. In your ~/.emacs file, there should be no (scroll-bar-mode nil).

Then add the following to ~/.gtkrc-2.0

style "contrast"    {
GtkScrollbar::has_forward_stepper  = 0
GtkScrollbar::has_backward_stepper = 0
bg[NORMAL]   = "red"
bg[PRELIGHT] = "dark red"
bg[ACTIVE] = "red"
bg[INSENSITIVE] = "red"
bg[SELECTED] = "red"
}    class "GtkScrollbar" style "contrast"
Posted in Linux | Tagged , , | Leave a comment

Interesting Graph Theory Terms

The following is a few of the more unique graph theory terms which I have misused in the past.

  • A giant component is a connected subgraph that contains a majority of the entire graph’s nodes
  • The order of the graph is the number of vertices, and the size is the number of edges.
  • A walk is an alternating sequence of vertices and edges, beginning and ending with a vertex. A closed walk starts and ends son the same vertex. An open walk doesn’t. A trail is a walk where all the edges are distinct.
  • An (open) neighborhood of a vertex v is all the vertices adjacent to v, but excluding v. A closed neighborhood includes v.
  • This one is trivial but I’ve seen it misused often which is can be a big source of confusion. For an edge (i,j), i is the tail and j is the head. I remember that by thinking of the head as the arrowhead.
  • The zweieck of an undirected edge e=(u,v) is the pair of directed edges (u,v) and (v,u). It’s a german word that means “biangle”.
  • An orientation is an assignment of directions to the edges of an undirected graph. A strong orientation is an orientation that produces a strongly connected digraph.
Posted in Data Structures and Algorithms | Tagged , , | Leave a comment

Bash Script to Determine Terrorist Threat Level

I’ve really been immersing myself into the world of Bash scripting lately. There is an incredible amount of productivity-increasing scripts available online, and I have already written several of my own that make my programming life just a little easier.

That said, I have also come across quite a few pointless but entertaining scripts, such as this one which detects the current “terrorist threat level” as determined by the U.S. Department of Homeland Security.

The script is all on one line, but I broke it up for display purposes:

function terrorist-level() {
    echo "Terrorist threat level:
    $(curl -s 'http://www.dhs.gov/dhspublic/getAdvisoryCondition'
    | awk -F\" 'NR==2{ print $2 }')"}
}

This reminds me of two things: (1) how powerful scripting is and (2) how absurd the idea of a “threat level” is in the context of the politicization of the “war on terror”.

Posted in Linux, Programming | Tagged , , | Leave a comment

PHP IDE: Avoiding Emacs

I love Emacs. I consider this a problem, because while it’s an exceptionally powerful and productive environment for a programmer, I feel like it’s a tool that has a good chance of being left in the dust of quickly developing modern IDE’s.

I use Emacs for basically every kind of programming and writing, both in Windows and Linux, but I’ve resisted using it in programming for the web. I’ve been using Dreamweaver: the Visual Basic of PHP IDE’s in Windows, and I mean that in a bad way. I don’t use almost any of the visual features of Dreamweaver, because in my opinion, those features are intended for designers that are for the most part new to web design. They are not nearly as powerful as they at first may seem.

Anyway, after playing around with other IDE’s, I finally made the switch to Rapid PHP. There are a lot of alternatives here depending on what features you need, and most are quite surprisingly top-notch and nearly identical. For me, the ability to customize syntax highlighting and intuitive interaction with the server through FTP are important. I played around with the following alternatives, and settled with Rapid PHP because its coding environment just felt most natural for me:

All these say “PHP”, but they are designed to work with HTML, PHP, CSS, Javascript, and other web programming languages. Again, I went with Rapid PHP for no reason but instinct.

Posted in Programming, Web Development | Tagged , , , , , , , , | 3 Comments

Flatten Directory Structure in Linux

Move all the files with extension pdf in the directory tree starting at the current location as root to directory bla.

find . -type f -name "*.pdf" -exec mv {} bla \;

So for example it would find ./path/to/image/lex.pdf and move it to ./bla/lex.pdf

Posted in Linux | Tagged , , | 3 Comments

Prevent Figures from Floating Outside Sections in LaTeX

LaTeX floats a figure for you as if it was a rotting raft in the middle of a stormy ocean. Most folks learn to tame this beast of burden, but I find that there are times when I need my figures to stay within the section, subsection, or subsubsection I references them in.

Using \FloatBarrier from the placeins package, you can force LaTeX to display all the figures that precede the \FloatBarrier command before displaying any of the content after the command.

You can add \FloatBarrier to the section, subsection, or subsubsection commands using the extraplaceins package that I modified to include subsection and subsubsections. Then add this to your LaTeX document:

\usepackage[section,subsection,subsubsection]{extraplaceins}

Download it here: http://lexfridman.com/files/research/extraplaceins.sty

Posted in Programming, Tools | Tagged , , , , | 5 Comments