Skip to content

Instantly share code, notes, and snippets.

View MikeChristianson's full-sized avatar
👋

Mike Christianson MikeChristianson

👋
View GitHub Profile
@MikeChristianson
MikeChristianson / optional-first.java
Last active September 12, 2016 05:15
Get an Optional first element of a List.
/**
* Safely gets the first element of a {@link List}
* @param list a {@code List}
* @param <E> type of elements in list
* @return the first element of list or {@link Optional#absent()} if absent or null
*/
@Nonnull
private <E> Optional<E> first(@Nullable List<E> list) {
if (list == null || list.isEmpty()) {
return Optional.absent();
@MikeChristianson
MikeChristianson / clean-create-load-repo.sh
Created November 30, 2016 18:04
Restores a compressed Subversion dump to a new Subversion repository with its original repository UUID.
#!/bin/zsh -ex
# Restores a compressed Subversion dump to a new Subversion repository with its original repository UUID.
# Uses `svndumptool` to ensure improper EOLs in svn:log and svn:ignore are fixed.
# Paths are hardcoded, but easily changed to suit needs.
repo=$1
cd /data/svn
source svnenv/bin/activate
gunzip /extract/Recover/${repo}.gzip -c | pv -eta > ${repo}.svn
svndumptool.py eolfix-revprop svn:log ${repo}.svn ${repo}.eolfix-revprop-log.svn
rm ${repo}.svn
@MikeChristianson
MikeChristianson / jetbrains-keyboard-navigation.md
Last active May 26, 2017 15:36
JetBrains keyboard navigation basics

↑ ↑ ↓ ↓ ← → ← → Ⓑ Ⓐ

IntelliJ, WebStorm, PyCharm JetBrains Keyboard Navigation[^ ]

[^ ]: Mike Christianson


@MikeChristianson
MikeChristianson / sensor_forecast_nws.configuration.yaml
Created February 18, 2018 21:09
National Weather Service forecast sensor for Home Assistant
# Rather than create a whole new hass component, this minimal `rest` sensor configuration is sufficient for a
# high-quality National Weather Service point forecast.
# See https://forecast-v3.weather.gov/documentation for details on this point-based GeoJSON forecast and more.
# Thanks to the National Weather Service for their efforts providing timely weather data to protect life and property.
sensor Forecast:
- platform: rest
name: Forecast
resource: https://api.weather.gov/points/[LATITUDE],[LONGITUDE]/forecast # substitute your EPSG:4326 lat/long
value_template: "{{ value_json.properties.periods[0].name }}: {{ value_json.properties.periods[0].detailedForecast }}"
headers:

Optional<T>

Mike Christianson

^ Added in Java 8 (2014)

^ Optional is a solution to a problem. The problem of null. But, what is null?

@MikeChristianson
MikeChristianson / datadog-snmp-synology.yaml
Last active December 12, 2022 04:05 — forked from pmoranga/datadog-snmp-synology.yaml
Datadog SNMP configuration to collect Synology statistics. Should be put into `conf.d` folder. SNMP User should be created / enabled on Synology (RO access)
init_config:
mibs_folder: /mibs
profiles:
generic:
definition_file: _generic-host-resources.yaml
instances:
- ip_address: $REPLACE_WITH_SYNOLOGY_IP_ADDRESS
community_string: public
snmp_version: 2