Skip to content

Instantly share code, notes, and snippets.

View JanPetterMG's full-sized avatar

Jan-Petter Gundersen JanPetterMG

View GitHub Profile
@JanPetterMG
JanPetterMG / nordpool_top_x_cheapest.yaml
Last active August 8, 2023 15:44
Home Assistant automation blueprint - Nord Pool top X cheapest hours
# Dependency: https://github.com/custom-components/nordpool
blueprint:
name: Nord Pool top X cheapest hours
description: Set up automation based on which hours of the day are the cheapest or most expensive.
domain: automation
input:
prices:
name: Nord Pool
description: Price sensor.
selector:
@JanPetterMG
JanPetterMG / string_combination_generator.php
Last active January 25, 2016 18:00
PHP: Generate all possible alphabetical combinations of given strings
/**
* Generate all possible alphabetical combinations of given strings
*
* @param array $strings - Strings to combine
* @param array $combinationArray - for internal use only
* @param int $start - for internal use only
* @param string $prefix - for internal use only
* @return array
*/
function generateCombinations($strings, &$combinationArray = array(), $start = 0, $prefix = "")
@JanPetterMG
JanPetterMG / validate_hostname.php
Created January 19, 2016 15:50
Validate URL hostname
/**
* Validate host name
*
* @link http://stackoverflow.com/questions/1755144/how-to-validate-domain-name-in-php
* @param string $host
* @return bool
*/
function isValidHostName($host)
{
return (preg_match("/^([a-z\d](-*[a-z\d])*)(\.([a-z\d](-*[a-z\d])*))*$/i", $host) //valid chars check
@JanPetterMG
JanPetterMG / url_to_absolute.php
Created January 19, 2016 15:38
Convert various relative URLs to absolute
/**
* Convert various relative urls to absolute
*
* @author Jan-Petter Gundersen (europe.jpg@gmail.com)
* @param $url - url to convert
* @param $base - parent url
* @return string - absolute url
*/
function url_absolute($url, $base)
{
@JanPetterMG
JanPetterMG / urlencoder_rfc3986.php
Created January 19, 2016 15:28
URL encoder according to RFC 3986
/**
* URL encoder according to RFC 3986
* Returns a string containing the encoded URL with disallowed characters converted to their percentage encodings.
* @link http://publicmind.in/blog/url-encoding/
*
* @param $url
* @return string
*/
function encode_url($url)
{
@JanPetterMG
JanPetterMG / astro_widget_large_stian.php
Last active November 1, 2015 03:22
Astro widget script, customized for Stian on Diskusjon.no - Forum thread: http://www.diskusjon.no/index.php?showtopic=1682430
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
date_default_timezone_set('Europe/Oslo');
setlocale(LC_TIME, 'nb_NO.UTF-8');
function astro_api_sunrise($parameters)
{
$debug = false;