Tuesday, January 27, 2015

Completely remove devise secret key from git repository

Took me long enough to figure this out, so I might as well write it down. I'm replacing the secret key with an environment variable:

git filter-branch --tree-filter "sed -i -e 's/'\''123123123123123123123123123123123123123'\''/ENV[\"DEVISE_SECRET_KEY\"]/g' config/initializers/devise.rb || true"

Wednesday, March 19, 2014

Custom page & controller in Sonata Admin Bundle

I was stuck for a while trying to figure out how to get my own page into the admin backend of the Sonata Admin Bundle. Specifically, I wanted to have a link in the top menu bar to a page that is created by a controller of mine.

Let's assume that our bundle is the AcmeDemoBundle, residing in the src/Acme/DemoBundle/ folder, which is where most of the following files are in as well.

The first step was to extend the standard_layout.html.twig from the SonataAdminBundle by creating a file here: Resources/views/standard_layout.html.twig

This file contains:

{% extends 'SonataAdminBundle::standard_layout.html.twig' %}
{% block top_bar_after_nav %} 
        <a href="{{ path('acme_demo_hello_index', {'name': 'World'}) }}">
{% endblock %}

Enable this file by adding this configuration to your config.yml:

        layout: AcmeDemoBundle::standard_layout.html.twig

You can now create the Controller/HelloController.php with an indexAction function like so:

namespace Acme\DemoBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;

 * Hello controller.
 * @Route("/admin/hello")
class HelloController extends Controller
     * @Route("/{name}")
     * @Template()
    public function indexAction($name)
        $admin_pool = $this->get('sonata.admin.pool');
        return array(
            'admin_pool' => $admin_pool,
            'name' => $name


finally you need to create the template Resources/views/Hello/index.html.twig

{% extends 'AcmeDemoBundle::standard_layout.html.twig' %}

{% block content %}
    Hello {{ name }}!
{% endblock %}

PS: Having written this, I also stumbled upon this StackOverflow question wherein two other solutions are discussed: http://stackoverflow.com/questions/15966575/sonataadminbundle-display-non-crud-statistics/22507027

Wednesday, September 11, 2013

JavaScript API to control loading progress indicator in browser adress bar

Instead of adding a JavaScript library to indicate the loading progress of a page I propose creating a JavaScript browser API that allows the programmer to set (or get) the position of the loading bar in percent. This is useful because many sites or single-page applications asynchronously load content.

As an example it could live as an object in the window.navigator.progress namespace and have the following functions:

set the progress bar to zero

set( percent )
set the progress bar to the given percentage value

set the progress bar to the full position and possibly hide it

returns the current loading progress in percent

Having said that, I noticed, that the browsers I use (firefox and chromium) don't even have the loading progress indicator anymore. I can only speculate, that this is because the vendors noticed, that the indicator wasn't helping much anymore due to the increased usage of javascript to control content in the DOM. I think that bringing back the indicator and handing control over it to the developers would be a nice touch in terms of usability.

Sunday, September 9, 2012

External Blogposts and JavaScript Libraries


I wrote two blogposts which are not hosted on this blog.

The first one was about implementing a suffix-tree in JavaScript in order to generate a grammar-based code for compressing a given string, because I was playing code golf.

 The second post is about using JavaScript for responsive webdesign using two helper functions I wrote called minwidth.js and relocate.js.

JavaScript libraries

My most popular JavaScript on github is a jquery plugin for fullscreen gallery slideshows. I don't have a blogpost about it yet, but considering that there are a lot of people watching the project I should write one.

Another JavaScript library I created is called facetedsearch.js and it lets you filter and sort an array of objects by the values of keys they share, or, in other words, browse through different facets of the objects.

I'm actually pretty proud of the jQuery map plugin JUMP that displays OpenStreetMap tiles (or others) using nothing but jQuery, so no OpenLayers, Leaflet, GMap or other libraries required.

Sunday, October 23, 2011

Bookmarklet to Visualize Hacker News Polls

Today I stumbled upon a poll on Hacker News on programmer salaries, where I found it difficult to read the results. So I wrote a bookmarklet which makes that easier:

HNPolls <- Drag this to your bookmarks bar and use it on a HN polls page. The source is available on github under the MIT license.

After using it, the poll looks like this:

Wednesday, November 10, 2010

Ten+ things you have to do before you launch a website

After reading some good advice, some very specific to SEO, what to do after launching a website which I ran across on HN I decided to write my own. This is a checklist if you're in charge of creating a website. I wrote it, so I would think about it myself, but I'm looking forward to your comments. I have a "regular" website with mostly text and image content in mind, but lots of it applies to forums, wikis, html5 apps etc.
  1. You may or may not be the person who came up with the idea of the website
    1. Create a list of all features, break them up in smaller pieces until you can approximate how long each step will take. This is called a work-breakdown-structure. Talk to the client / partners about these features and how long you think they'll take.
    2. Figure out what is important about the website. Get the priorities right, some features may not make the initial launch. Suggest less expensive alternatives.
  2. What parts are you responsible for? The content, the design or the implementation? (MVC anyone?)
  3. Find out who the website's audience will be.
    1. What is the audience looking for on the site? How can you help with that?
    2. Does your audience have special needs, think about accessibility.
    3. What kind of traffic will you get? How will you accommodate for that?
  4. If you're responsible for implementing the design, decide which browsers you would like to support:
    1. A-Grade as defined by Yahoo maybe?
    2. What about mobile? Separate site or a fluid layout using media queries?
  5. Learn the SEO Basics
    1. Make sure the basics of your website work without JavaScript as well as it does without.
    2. Have nice URLs
    3. If it's a relaunch, make sure, the old URLs forward to a sensible place and not a 404 page.
  6. Features
    1. What content types have you identified? Can they be simplified? 
    2. Avoid feature creep.
    3. If your editors want to embed videos, mp3s, PDFs, DOCs, PPT etc, how should they do that?
    4. How is search done?
    5. What users and access controls should exist?
    6. What social media integration?
      1. User sign up?
      2. Twitter, Facebook, Google, OAuth etc.
      3. Comments? By Disqus or IntenseDebate or with own user accounts only?
    7. Figure out if you'll need a content workflow, like a review process for new user generated content or regular content from editors.
  7. What development framework do you want to use?
    1. The main point is: Will you use a out-of-the box solution, like a CMS or do you want to use a web development framework? Lots of options, no way of finding out what is the right tool, getting a broad overview is important though.
    2. Will you always be the only one working on it? If not, consider how difficult it is to find smalltalk-devs for seaside... Maybe Drupal is the bettter alternative, lots of PHP devs around, filtering out the bad ones is the bigger task. With Rails its a little more work, but also more control, ruby developers tend to have a better grasp of the technologies they are using. 
  8. Security
    1. Avoid all the common security vulnerabilities:
      1. SQL injections
      2. HTML injections
      3. XSS
      4. CSRF
      5. ...
    2. Protect yourself against session hijacking, have a SSL version available
    3. Set up a backup process and test it
    4. Make sure you're able to apply security updates to the whole stack: OS, WebServer, Database, Language, Framework, Plugins
    5. Apply them.
  9. Testing
    1. Use unit tests
    2. Create integration tests
    3. Do uptime monitoring and set up alerts
    4. How will you do the load-testing?
    5. What are the response times you're aiming for?
    6. Use YSlow to see how you can improve performance.
    7. Will you need more than one database-, web- or cache-server?
  10. Hosting
    1. Have a plan how you'll deploy, also how you'll continue development and testing once it's launched
    2. Avoid a shared hosting environment (it's also a security issue), use a VM at least (they're cheap too).
    3. Try the backup if there is one that comes out-of-the-box  by your hosting provider
If you think this should be a wiki page, let me know if you know the right place where to put it, so people can find it and contribute easily. Wikibooks maybe?

Edit: Just found this pre-launch list as well...