Skip to content

Instantly share code, notes, and snippets.

@nileshk
nileshk / after-primefaces-css.xhtml
Created April 11, 2013 14:16
How to get a CSS file to load after Primefaces CSS (tested with Primefaces 3.5.0)
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:pe="http://primefaces.org/ui/extensions">
<h:head>
@nileshk
nileshk / http_basic.py
Created March 25, 2013 15:59
Fetch contents of a URL with HTTP Basic Authentication
import urllib2
import base64
def fetch(url, username, password):
try:
request = urllib2.Request(url)
base64string = base64.encodestring('%s:%s' % (username, password)).replace('\n', '')
request.add_header("Authorization", "Basic %s" % base64string)
return urllib2.urlopen(request).read()
except urllib2.HTTPError as ex:
@nileshk
nileshk / pid_exists.py
Last active December 15, 2015 09:28
Find out if a process exists based on PID
import os
import errno
def pid_exists(pid):
"""Check whether pid exists in the current process table."""
if pid < 0:
return False
try:
os.kill(pid, 0)
except OSError, e:
@nileshk
nileshk / top-level.py
Last active December 14, 2015 17:29
List top level folders of current directory
import os
print os.walk('.').next()[1]
@nileshk
nileshk / build.xml
Created March 8, 2013 20:51
Get SVN revision number of last commit in Ant build
<exec executable="svn" spawn="false" dir="." outputproperty="revision.number">
<arg line="info"/>
<redirector>
<outputfilterchain>
<linecontainsregexp><regexp pattern="^Last\sChanged\sRev:\s[0-9]*$" /></linecontainsregexp>
<tokenfilter>
<replaceregex pattern="^Last\sChanged\sRev:\s([0-9]*)$" replace="\1" flags="g" />
</tokenfilter>
</outputfilterchain>
</redirector>
@nileshk
nileshk / mac-init
Last active October 21, 2021 03:54
OS X Config Script
#!/bin/bash
# Run this on a new OS X installation
# Disable menu bar transparency
defaults write -g AppleEnableMenuBarTransparency -bool false
# Expand save panel by default
defaults write -g NSNavPanelExpandedStateForSaveMode -bool true
# Disable press-and-hold for keys in favor of key repeat
@nileshk
nileshk / image_list_json.php
Created October 29, 2011 04:17
JSON list of images in current directory
<?php
/*
JSON list of all images files in current directory
*/
$dir = ".";
$dh = opendir($dir);
$image_files = array();
require 'rubygems'
require 'sequel'
require 'fileutils'
module Jekyll
module Drupal
QUERY = "
select n.nid node_id,
n.title post_title,