Skip to content

Instantly share code, notes, and snippets.

View massenz's full-sized avatar
💻
Building AI Agents

Marco Massenzio massenz

💻
Building AI Agents
View GitHub Profile
@massenz
massenz / venv.sh
Created March 28, 2013 00:00
Derived from: https://gist.github.com/codysoyland/2198913 Enables automatic activation of a virtualenv once one navigates to a directory with a .venv file whose contents are the path to a virtual environment
#!/bin/bash
# venv.sh
#
# Installation:
# Add this line to your .bashrc or .bash-profile:
#
# source /path/to/venv.sh
#
# Whenever a directory has a file called `.venv` its contents
# will be interpreted as the path to a base directory of
@massenz
massenz / repset_mongo.sh
Last active March 1, 2017 12:57
Creates and initializes a MongoDb replica set: allows the user to choose the number of members and the starting port number; this should also work on a remote host, but I have only tested it so far on localhost
#!/bin/bash
#
# Starts up a MongoDB replica set
#
# There is a lot of documentation about replica sets:
#
# http://docs.mongodb.org/manual/reference/replica-configuration/
# http://docs.mongodb.org/manual/administration/replica-sets/
#
# To read data from a SECONDARY, when in the client, use:
@massenz
massenz / scp-pub-remote.sh
Created August 16, 2013 05:30
Having to type a thousand times the password when SSH'ing into a server commonly used is a pain: the obvious solution is to use key-based auth - this is a handy script that takes out even the effort of having to remember (not to mention) type up every time the same set of commands. You will have to enter the password to the remote host twice, bu…
#!/bin/bash
#
# Copies the PUB key to a server via SCP then adds it to
# .ssh/authorized_keys.
#
# Must be invoked like this:
# scp-pub-remote.sh user@server
declare -r REMOTE=$1
@massenz
massenz / truncate.cpp
Created September 4, 2013 23:05
A simple implementation of the Linux `truncate` function - this is missing in Mac OSX so I decided to implement it. The binary is a Release build for Mac OSX 10.8.4; should run in most versions.
/*
* truncate.cpp
*
* Created on: Sep 4, 2013
* Author: marco
*/
#include <iostream>
#include <stdio.h>
#include <unistd.h>
@massenz
massenz / JsonSerialize.java
Last active December 7, 2021 15:57
How to convert from JSON to Inet4Address in Java - incidentally, this is the only way to create an InetAddress object for a host that is not DNS-resolvable (see in the example, how it sets both hostname and IP for an arbitrary server).
package com.alertavert.samples;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.net.Inet4Address;
/**
* Simple example to show how to create a Java @link{InetAddress} from a JSON representation.
*
* <p>Jackson will try to use the @link{Inet4Address#Inet4Address(String, int)} constructor, and it
@massenz
massenz / SamplePlugin.java
Last active December 27, 2015 22:59
Dynamic plugins loading using JCL (https://github.com/kamranzafar/JCL/) This is an example of a plugin that can be used with the babysitter server (https://github.com/massenz/babysitter)
package com.rivermeadow.plugins.simple;
import com.rivermeadow.babysitter.alerts.AlertPlugin;
import com.rivermeadow.babysitter.alerts.Context;
import com.rivermeadow.babysitter.alerts.Pager;
import com.rivermeadow.babysitter.model.Server;
/**
* Simplest example of a ``babysitter`` plugin, does nothing but demonstrate how to create a pluggable component.
*
@massenz
massenz / Preferences.sublime.json
Last active December 30, 2015 02:19
My finely-tuned Sublime Text 2 personal preferences (you'll have to rename it - remove the .json: I'm using it only because Github loses the syntax highlight unless the extension is recognized).
{
"auto_complete_commit_on_tab": true,
"auto_complete_selector": "source - comment",
"margin": 4,
"rulers": [80, 100],
"draw_white_space": "all",
"ensure_newline_at_eof_on_save": true,
"highlight_line": true,
#!/bin/env python
__author__ = 'Marco Massenzio <m.massenzio (at) gmail com'
""" Simple python decorator example.
@see: http://codetrips.com/2014/01/27/python-decorators-again
"""
from functools import wraps
@massenz
massenz / alert
Last active April 2, 2017 11:24
Originally written for Mandrill (screw them), this script can send an email alert, for example, when a remote job fails or some other unexpected event happens: I'm using it on my QNAP TS-212 NAS to alert me about backup jobs failures and other abnormal events.
#!/bin/bash
#
# Failure reporter, logs to a well-known log file failure messages
#
# Created 2014-04-30, M. Massenzio ([email protected])
declare -r LOGFILE="/var/log/fail.log"
declare -r ALERT_ICON="/usr/share/icons/ubudao-style/actions/dialog-warning.png"
declare -r ERROR_ICON="/usr/share/icons/ubudao-style/actions/stock_dialog-error.png"
@massenz
massenz / auth_server.py
Last active December 24, 2017 15:15
Simple Flask server to demonstrate how to use LaunchKey (http://www.launchkey.com) to authenticate users
# Copyright AlertAvert.com (c) 2013. All rights reserved.
#
# Licensed 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
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,