Skip to content

Instantly share code, notes, and snippets.

@srgrn
srgrn / line_by_line_python3.py
Created November 17, 2016 08:55
download a gzipped file line by line (for example http://csr.lanl.gov/data/cyber1/ files)
import urllib.request
import gzip
N = 200000
def read_line_by_line(url,handlefunc,**kwargs):
with gzip.open(urllib.request.urlopen(url),'r') as f:
for i in range(N):
try:
arr =f.readline().decode('ascii').strip().split(',')
handlefunc(arr,kwargs)
""" simple azure uploader script """
import sys
import argparse
import os
from azure.storage.blob import BlockBlobService
import logging
LOG_LEVEL = 'WARNING'
@srgrn
srgrn / scriptname.bat
Created May 30, 2016 10:35
Simple Jenkins Batch runner for powershell scripts - replace the scriptname.bat to the powershell script name.
@ECHO OFF
PowerShell.exe -NoProfile -NonInteractive -ExecutionPolicy unrestricted -Command "& %~d0%~p0%~n0.ps1" %*
EXIT /B %errorlevel%
@srgrn
srgrn / runner.sh
Created May 8, 2016 11:32
simple python runner that runs a python script in a given virtual env for cron
VIRTUALENV=$1
SCRIPT=$2
PARAMS="${@:3}"
source $VIRTUALENV/bin/activate
if [ -f $(dirname $SCRIPT)/requirements.txt ]
then
pip install -r $(dirname $SCRIPT)/requirements.txt
fi
python $SCRIPT $PARAMS
@srgrn
srgrn / SendEventToEventHub.rb
Created April 19, 2016 06:50
A simple script to send event to event hub with SAS authentication
require "optparse"
require "CGI"
require 'openssl'
require "base64"
require "Faraday"
require 'Digest'
def generateToken(url,keyname,keyvalue)
encoded = CGI::escape(url)
ttl = (Time.now + 60*5).to_i
@srgrn
srgrn / SqlServer.py
Last active April 5, 2016 09:12
Azure Sql Server Metrics gatharer
"""Azure Test SQL Module"""
import json
import argparse
import sys
import logging
import pymssql
def connect(server, database_name):
try:
@srgrn
srgrn / carbon-cache
Created March 28, 2016 07:31
monit and service configuration scripts
check process carbon-cache
matching "carbon-cache"
start program = "/usr/sbin/service carbon-cache restart"
stop program = "/usr/sbin/service carbon-cache stop"
if 5 restarts within 5 cycles then alert
@srgrn
srgrn / getting_user_email.py
Last active December 5, 2015 00:59
example of how to get user email from google apis
from bottle import route, request, redirect, view
from apiclient import discovery
# from apiclient import errors
from oauth2client import client
import httplib2
import json
import os
CLIENT_ID = 'YOURCLIENTID.apps.googleusercontent.com'
@srgrn
srgrn / runner_script_skeleton.py
Last active September 27, 2016 14:35
simple runner script skeleton
""" <replace with string description> """
import json
import argparse
import sys
import logging
CONFIG = None
def setup(args):
log_level = 'WARNING'
@srgrn
srgrn / general_azure_uploader.py
Created November 1, 2015 09:08
Simple script to upload files to azure
""" uploads files to azure and reports to dashboard """
import sys
import argparse
import os
from azure.storage import BlobService
import logging
LOG_LEVEL = 'WARNING'