Skip to content

Instantly share code, notes, and snippets.

@jceresearch
jceresearch / gist:808d325d372e66a7e90a3813896d090b
Created July 28, 2024 19:49
calculate beginning and end of the month given a date or datetime
from datetime import datetime, timedelta, date
def start_and_end_of_month(d,return_datetime=True):
if return_datetime:
if isinstance(d,date):
d=datetime(d.year,d.month,d.day)
start = d.replace(day=1)
next_month=d.replace(day=28)+timedelta(days=4)
end = next_month - timedelta(days=1)+timedelta(hours=23,minutes=59,seconds=59)
@jceresearch
jceresearch / VBA Excel find external validation
Last active August 22, 2018 19:12
To detect the pesky links to external validation that trigger errors when opening the file
Public Sub FindExtValidation()
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Sheets
ws.Activate
On Error Resume Next
Set v1 = ws.Cells.SpecialCells(xlCellTypeAllValidation)
If Err.Number > 0 Then
GoTo next_sheet
End If
@jceresearch
jceresearch / gist:061438407a53021efc0b
Last active August 29, 2015 14:12
Sed command to redact sh... p... file for safe extraction
sed -r 's/^([^:]+):([^:])([^:]?)([^:]?)([^:]*):(.*)$/\1:\2\3\4:\6/w shadowredacted' < shadow
@jceresearch
jceresearch / NumpyGroupBy
Created December 29, 2014 13:23
Phython - Numpy loop to group an array by certain key, supposed to be the faster way
import numpy as np
data = np.arange(1, 7)
groups = np.array([0,0,1,2,2,1])
unique_groups = np.unique(groups)
sums = []
for group in unique_groups:
sums.append(data[groups == group].sum())
@jceresearch
jceresearch / Clean github history
Created July 31, 2014 08:31
Steps to cleanup old version data from a github repository, brute force
Here's the brute-force approach. It also removes the configuration of the repo.
You need to save first the gitignore
Step 1: remove all history
rm -rf .git
Step 2: reconstruct the Git repo with only the current content
@jceresearch
jceresearch / gist:5755030
Last active July 6, 2020 06:51
Google Apps Script to create a digest from a set of messages in Gmail. It does a bit more than that, filters by time, strips the html, trims legalese (or whatever) and tags messages so they are not processed again. Ideal to schedule it in gmail.
function GenerateDigest() {
//Function that goes through a search query based on time and optional label in gmail, strips html, collates into a single email, sends it to a desired address and then labels the emails as processed.
// Where the digest email is going
var to_emailAddress = "[email protected]";
//We calculate the 24 hour range, I plan to run this every day at 9:00 to get last 24 hours of emails
var month = new Date().getMonth();