Skip to content

Instantly share code, notes, and snippets.

View thanpolas's full-sized avatar

Thanos Polychronakis thanpolas

View GitHub Profile
@thanpolas
thanpolas / motion-illuminance-v2.yaml
Last active August 27, 2023 13:06
Home Assistant Blueprint for automation that triggers on motion. Taking Illuminance and lights state as criteria for triggering
blueprint:
name: Motion-activated Light with illuminance v2
description: Turn on a light when motion is detected and illuminance is below a
set Lux level. Will use a configured scene instead of the previous light
setting and will not trigger when the lights are already on to avoid
overriding user defined lighting (i.e. you've set the lights to a certain
scene, this automation should not override this).
This automation is based on the work of Danielbook
https://gist.github.com/Danielbook/7814e7eb32e880b2d7c3fb5ba8430f4f
Blueprint version 1.0.0
@thanpolas
thanpolas / stdquote.js
Created June 6, 2021 09:34
Normalize all UTF quotes in Javascript
/**
* Will normalize quotes in a given string. There are many variations of quotes
* in the unicode character set, this function attempts to convert any variation
* of quote to the standard Quotation Mark - U+0022 Standard Universal: "
*
* @param {string} str The string to normalize
* @return {string} Normalized string.
* @see https://unicode-table.com/en/sets/quotation-marks/
*/
helpers.stdQuote = (str) => {

Keybase proof

I hereby claim:

  • I am thanpolas on github.
  • I am thanpolas (https://keybase.io/thanpolas) on keybase.
  • I have a public key ASCWHXwoj4IjP1CA1lp-qmFAHe3t_kebLO6KeNNWzK5XBgo

To claim this, I am signing this object:

@thanpolas
thanpolas / singleton-class.js
Created September 16, 2016 09:45
ES6 Singleton Pattern
/**
* @fileOverview Singleton pattern on ES6.
*/
import logger from './logger.midd';
/**
* The class statement.
*
*/
@thanpolas
thanpolas / hidden-iframe.js
Last active August 8, 2018 03:06
In the absence of CORS support the Hidden Iframe technique is the only way to submit a big amount of data (over 2kb that jsonp can handle).
/**
* @fileOverview Hidden iFrame implementation for browsers without CORS.
*
* Usage:
* var iframe = new Iframe();
* iframe.submit(url, {data: yourData}, function(err) {});
*
* The server will get a POST request on the defined URL with the data
* JSON encoded in the body attribute named "data".
*/
@thanpolas
thanpolas / jquery-debounce.js
Created May 20, 2015 12:22
Angular window resize service
// http://www.paulirish.com/2009/throttled-smartresize-jquery-event-handler/
//
// debouncing function from John Hann
// http://unscriptable.com/index.php/2009/03/20/debouncing-javascript-methods/
var debounce = function (func, threshold, execAsap) {
var timeout;
return function debounced () {
var obj = this, args = arguments;
@thanpolas
thanpolas / hack-lusca.js
Created June 14, 2014 16:31
Hack lusca CSRF store
/**
* @fileOverview A CSRF Implementation for WebSocket calls.
*/
var Promise = require('bluebird');
var config = require('config');
var lusca = require('lusca');
var Middleware = require('./middleware');
@thanpolas
thanpolas / index.js
Created June 10, 2014 13:28
requirebin sketch
// example using the raf module from npm. try changing some values!
var requestAnimationFrame = require("raf")
var canvas = document.createElement("canvas")
canvas.width = 500
canvas.height = 500
document.body.appendChild(canvas)
var context = canvas.getContext("2d")
@thanpolas
thanpolas / README.md
Last active August 29, 2015 14:02
Heroku Environment mass export

Exporting sensitive data to Heroku's Environment

This script is ment to work with the node-config package, it will export whatever configuration data you set on the herokuOverride Object, as a JSON serialized string, onto the NODE_CONFIG environment variable on Heroku.

This results in the config package to use those values instead, thus enabling you to keep sensitive data out of your tracked files.

Usage

  • Add env.js to your .gitignore file
  • Edit it as per your needs
@thanpolas
thanpolas / README.md
Created March 6, 2014 22:43
Setup Heroku sensitive configs