Skip to content

Instantly share code, notes, and snippets.

@avaccari
avaccari / SmokePing.py
Last active October 3, 2021 14:06
A very short and simple ASCII smoke ping in Python
import re
import time
import subprocess as sbpr
import datetime as dt
HOST = 'google.com'
DELAY_MS = 1000
while(True):
t = float(re.findall(r'time=(.*) ms',sbpr.check_output(['ping', '-c', '1', HOST]).decode('ascii'))[0])
@avaccari
avaccari / createFile.applescript
Last active January 25, 2024 17:13
Apple script to create a file with desired extension in a folder. Can be used in automator to create an app or a quick action.
(*
* Apple script to create a new file/folder based on the current selection in Finder:
* - if there is nothing selected, it will create the file/folder in the currently displayed folder
* - if a file is selected, it will create the file/folde in the folder of the selected file
* - if a folder is selected, it will create the file/folder in the selected folder
* - if an application is selected, it will not create the file/folder
*
* Notes:
* - By default it creates files named "untitled.txt".
* - Pressing "shift" will prompt the user for the file name
@avaccari
avaccari / CaptureClickJupyter.ipynb
Last active November 28, 2022 13:17
A jupyter notebook showing how to display an interactive image and capture and return the position and other information about the mouse each time it is clicked over the image.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@avaccari
avaccari / AttacksStats_with_Google_Maps_API.py
Created June 21, 2016 15:50
Python server side script that uses Google maps API to generate map of a set of IPs stored as lines within a file and plots origin statistic
#!/usr/bin/env python
# A script to graph the statistics of a set of IP blacklists generated by your favorite
# firewall program as long as the lists consist of a series of IP addresses one for each
# line.
import re
import sys
import json
import urllib2
import socket
@avaccari
avaccari / TestPlotting.pyt
Created January 18, 2016 18:06
Create a matplotlib plot from within an ArcGIS python toolbox using tkinter
import Tkinter as tk
import matplotlib
from numpy import arange, sin, pi
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
from matplotlib.figure import Figure
class Toolbox(object):
def __init__(self):
self.label = "test plotting dev"
@avaccari
avaccari / PopupMessage.pyt
Created January 18, 2016 18:04
Pop-up a message from an ArcGIS python toolbox using ctypes
import ctypes
class Toolbox(object):
def __init__(self):
self.label = "popup message dev"
self.alias = "pupMesg_dev"
self.tools = [PopupMessage]
@avaccari
avaccari / CSSAlign.css
Created October 20, 2015 03:18
Aligned row of buttons with centered multiline text using CSS
#buttons {
display: inline-block;
text-decoration: none;
height: 100px;
width: 90%;
text-align: justify;
padding-left: 5%;
padding-right: 5%;
}
@avaccari
avaccari / AttacksStats_in_d3.py
Last active June 21, 2016 15:48
Python server side script that uses D3 to generate map of a set of IPs stored as lines within a file and plots origin statistic
#!/usr/bin/env python
# A script to graph the statistics of a set of IP blacklists generated by your favorite
# firewall program as long as the lists consist of a series of IP addresses one for each
# line.
import re
import sys
import json
import urllib2
import scoket
@avaccari
avaccari / ApLabels.py
Last active November 6, 2020 07:28
Arcpy: programmatically adding labels to layers using fields values
# Import arcpy
import arcpy as ap
# Load the reference to the current map document.
# Caveat: not sure it will work if the toolbox is running in background.
# This is because background execution is performed within a separate
# kernel.
mxd = ap.mapping.MapDocument("CURRENT") # (mxd_path)
# Get list of dataframes. There might be more than one dataframe in a map
@avaccari
avaccari / TkAlign.py
Created August 3, 2015 15:39
An example on how to align widgets within widgets within widgets within.... with TkInter and grid in python
#!/usr/bin/env python
import Tkinter as tk
class AlignTest(tk.Frame):
def __init__(self, parent):
tk.Frame.__init__(self, parent)
self.parent = parent
self.grid()
self.parent.title('Align test')