Skip to content

Instantly share code, notes, and snippets.

View abn's full-sized avatar

Arun Babu Neelicattu abn

View GitHub Profile
@abn
abn / mongodb-array-to-doc
Last active January 30, 2018 09:01
Mongodb: convert a an array into a sub-document. Eg: { "field" : ["v1", "v2", ...], 'date' : $DATE } to { "field" : { "v1" : $DATE, "v2" : $DATE, ... } , 'date' : $DATE}
db.collection.find({ field : { $exists : true } }).forEach( function (x) {
var temp = {}
var count = 0
for (var i in x.field) {
if (typeof x.field[i] == "string") {
// make sure index is a string
temp[x.field[i]] = x.date;
count++;
}
@abn
abn / securetemp.py
Created November 10, 2013 08:34
[python] secure tempfile creation/use usual examples out there seems to ignore the file descriptor returned.
from os import fdopen, remove
from tempfile import mkstemp
# http://docs.python.org/2/library/tempfile.html#tempfile.mkstemp
fd, filename = mkstemp(prefix='example')
# note the usage of fdopen/fd instead of open/filename
with fdopen(fd, 'w') as f:
# do something with the file
pass
@abn
abn / openshift-install-pcre.sh
Last active December 28, 2015 09:39
Install pcre on OpenShift
#!/bin/bash
# script to install pcre on openshift
# this can be called in your action_hooks to setup pcre
# useful if you want to use regex in uwsgi, or nginx
#
# NOTE:
# If scaling, make sure you call this in your pre_start* hook,
# ${OPENSHIFT_DATA_DIR} is not copied over for a new gear
@abn
abn / openshift-uwsgi-control.sh
Created November 15, 2013 07:45
uwsgi control script for OpenShift
#!/bin/bash -e
# This assumes that your openshift repo contains a uwsgi.ini
# configuration file.
# This is a extracted from a script used live for the victims project:
# https://github.com/victims/victims-server-openshift/blob/master/bin/control
source $OPENSHIFT_CARTRIDGE_SDK_BASH
# Setup globals
@abn
abn / openshift-mongofiles.sh
Created November 15, 2013 14:07
Convenience wrapper script to interact with mongofiles on openshift
#!/bin/bash
# Wrapper script interact with mongofiles
MONGOFILES_CMD="mongofiles \
-u $OPENSHIFT_MONGODB_DB_USERNAME \
-p $OPENSHIFT_MONGODB_DB_PASSWORD \
-h $OPENSHIFT_MONGODB_DB_HOST \
--port $OPENSHIFT_MONGODB_DB_PORT \
-d $OPENSHIFT_APP_NAME"
@abn
abn / python-flask-task-async.py
Last active February 18, 2021 12:29
A module to facilitate dispatch of asynchronous tasks in a Flask App. This was designed to work standalone in an embedded fashion without dependencies like flask-celery, redis etc. This is not meant to be a reliable means to execute tasks, just a quick and easy solution for most needs.
"""
An asynchronous task manager.
This is a simple implementation for background task handing. No guarentees are
provided for task execution.
This was developed in the course of the work don for the victims project and
that version is available at
https://github.com/victims/victims-web/blob/master/src/victims_web/handlers/task.py
@abn
abn / reliance_wireline_connect.sh
Created February 16, 2014 09:53
Helper script to keep connection alive for Reliance Broadband networks.
#! /usr/bin/env bash
# Hard-code credentials here, or better, pass them as env vars
USERNAME="${RELIANCE_USER}"
PASSWORD="${RELIANCE_PASS}"
# Reliance Broadband URLs
BASE_URL="http://reliancebroadband.co.in"
START_URL="${BASE_URL}/reliance/startportal_isg.do"
LOGIN_URL="${BASE_URL}/reliance/login.do"
@abn
abn / EmbeddedJettyServer.java
Last active August 29, 2015 14:02
Embedded Jetty PoC Quickstart
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with this
* work for additional information regarding copyright ownership. The ASF
* licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
@abn
abn / SimpleFileMonitor.java
Last active May 12, 2020 15:30
Apache VFS file listener PoC Quickstart
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with this
* work for additional information regarding copyright ownership. The ASF
* licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
#!/usr/bin/env bash
if [ "$(whoami)" != "root" ]; then
echo "This script needs to be run as root."
exit 1
fi
# Dependencues
yum install -y python git