Skip to content

Instantly share code, notes, and snippets.

@vaidik
vaidik / StackOverflow Question: Aggs on Nested Documents
Last active August 29, 2015 14:04
Displays how to use aggregations in Elasticsearch on documents with nested types
# Answer for: http://stackoverflow.com/questions/24631409/average-and-histogram-aggregation-on-nested-fields-in-elasticsearch
curl -XPUT "http://localhost:9200/aggs/test/_mapping" -d'
{
"test": {
"properties": {
"doctxt": {
"type": "string"
},
"nested": {
@vaidik
vaidik / outward_walk.py
Created August 21, 2014 21:44
Python: Outward Walk
import os
def outward_walk(bottom, func, arg=None):
'''
Walks out of directory to the upper level directories in the path.
Usage is very similar to os.path.walk.
'''
levels = bottom.split('/')
while len(levels) > 1:
@vaidik
vaidik / redis
Created November 19, 2012 13:23
Redis Service Startup Script for Red Hat derivatives
#!/bin/sh
#
# chkconfig: 2345 50 50
# description: redis-server is a key-value store by VMWare.
# processname: redis-server
# pidfile: /var/run/redis.pid
# config: /etc/redis/6379.conf
# command: /usr/local/bin/redis-server
#
# Taken from original https://github.com/antirez/redis/blob/unstable/utils/redis_init_script
@vaidik
vaidik / utils.js
Created November 24, 2012 03:10
Some utility script that I have used (at times) and might want to use later in my projects.
/**
* Checks if an object is empty or not.
*/
Object.prototype.isEmpty = function() {
for(var key in this) {
if (this.hasOwnProperty(key)) {
return false;
}
}
return true;
class ReloaderEventHandler(FileSystemEventHandler):
"""
Listen for changes to modules within the Django project
On change, reload the module in the Python Shell
Custom logic required to reload django models.py modules
Due to the singleton AppCache, which caches model references.
For those models files, we must clear and repopulate the AppCache
"""
def __init__(self, *args, **kwargs):
{
"auto_upgrade_last_run": null,
"installed_packages":
[
"Alignment",
"All Autocomplete",
"Calculate",
"Case Conversion",
"Clipboard Manager",
"Codechef",

Hyde publisher plugin for publishing content to Github Pages (User Pages).

https://github.com/vaidik/vaidik.github.io/tree/dev/publishers

Usage

  • Make sure that the hyde project lives in your dev branch. master branch, in case of user github pages, is left for serving static files.
  • Create an orphan master branch.
import json
import requests
import unittest
from time import time
def get_status_code(url):
response = requests.get(url, verify=False, allow_redirects=True)
return response.status_code
@vaidik
vaidik / gist:5905762
Last active December 19, 2015 05:39
Get element's source only in Selenium or Marionette. Both Selenium and Marionette have APIs to get source of the entire page but not just the source of the `WebElement` or `HTMLElement`. This utility function fills that gap.
def element_html(driver, elements):
"""Return source of a particular HTML element on the page.
:param driver: webdriver or marionette object - the object you use
to drive your webdriver or marionette tests.
:param elements: Webdriver.remote.webelement.WebElement object or
marionette.marionette.HTMLElement object or
a list of WebElement or HTMLElement objects
#!/bin/bash
set -e
echo "Plug in your device"
adb wait-for-device
echo "Found device"
#dir=$(mktemp -d -t revision)
dir=$(mktemp -d -t revision.XXXXXX)
cd $dir
adb pull /system/b2g/omni.ja &>/dev/null || echo "Error pulling gecko"
adb pull /system/b2g/webapps/settings.gaiamobile.org/application.zip &> /dev/null || echo "Error pulling gaia file"