Skip to content

Instantly share code, notes, and snippets.

View jfcarr's full-sized avatar

Jim Carr jfcarr

View GitHub Profile
@jfcarr
jfcarr / rhythmbox-currently-playing.py
Created July 27, 2023 01:21
Displays a single line of text describing what's currently playing in Rhythmbox
#!/usr/bin/python3
# Example output:
# [ Baba O'Riley | The Who | 1970 (0:05:09)]
import datetime
import subprocess
def get_value(full_array, position):
@jfcarr
jfcarr / update-collection.cs
Created December 1, 2020 21:29
Update elements in a collection, using LINQ
using System;
using System.Collections.Generic;
using System.Linq;
namespace UpdateCollection
{
class Program
{
static void Main(string[] args)
{
@jfcarr
jfcarr / assert_double.c
Created August 24, 2020 03:02
Assertions on doubles with variable precision
/*
Assertions on doubles are tricky in C, because of the way precision is handled. The default precision
used in things like displaying and comparing is 6 decimal places, even though the internal precision value
is much higher. This makes things like assertions difficult, if you want to assert on any value other
than the default 6 decimal places. Here's a way to do it by converting both values to strings before
the assertion.
*/
#include <math.h>
#include <stdio.h>
@jfcarr
jfcarr / unread_email_count_via_imap.py
Created July 4, 2017 14:18
Show unread email count via IMAP.
#!/usr/bin/python
import imaplib
import sys
class MailHandler:
def CheckUnread(self, username, password):
imapConnection = imaplib.IMAP4_SSL('your.mailserver.com',993)
imapConnection.login (username, password)
imapConnection.select()
@jfcarr
jfcarr / unread_gmail_message_count.sh
Created July 4, 2017 14:17
Show unread Gmail message count.
#!/bin/bash
LASTGMAIL="$(curl -u johndoe:mypassword --silent 'https://mail.google.com/mail/feed/atom' | tr -d '\n' | awk -F '<entry>' '{for (i=2; i<=NF; i++) {print $i}}' | sed -n 's/<title>\(.*\)<\/title.*name>\(.*\)<\/name>.*/\2 - \1/p' | wc -l)"
if [ $LASTGMAIL -ne 0 ]
then
echo "$LASTGMAIL : [email protected]"
fi
@jfcarr
jfcarr / subject_unread_gmail.sh
Created July 4, 2017 14:17
Show subject of each unread Gmail message.
#!/bin/bash
curl -u johndoe:mypassword --silent "https://mail.google.com/mail/feed/atom" | tr -d '\n' | awk -F '<entry>' '{for (i=2; i<=NF; i++) {print $i}}' | sed -n "s/<title>\(.*\)<\/title.*name>\(.*\)<\/name>.*/\2 - \1/p"
@jfcarr
jfcarr / remove_dups_extension.cs
Last active July 4, 2017 20:41
Remove duplicates from a list collection - implemented as an extension
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
namespace Console1
{
public static class ListExtension
{
public static IEnumerable<T> RemoveDuplicates<T>(this List<T> inputList)
@jfcarr
jfcarr / remove_dups_method.cs
Last active November 1, 2017 15:09
Remove duplicates from a list collection - implemented as a method
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
namespace Console1
{
class Program
{
@jfcarr
jfcarr / feels_like.py
Created March 28, 2016 18:25
"Feels Like" (temperature) Calculation in Python
# I use a Python script to pull current weather conditions from the NOAA web service API. The NOAA web
# service does not return a windchill value for all locations, but given temperature, relative humidity,
# and wind speed you can calculate a “feels like” temperature as follows.
# This code assumes units of Fahrenheit, MPH, and Relative Humidity by percentage. In this example, a
# temperature of 35F, wind speed of 10mph, and relative humidity of 72% yields a "feels like" value of 27.4F
import math
vTemperature = float(35)