Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View neilgupta's full-sized avatar

Neil Gupta neilgupta

View GitHub Profile
@neilgupta
neilgupta / tovala.rb
Created August 23, 2020 16:44
Tovala meals history
#!/usr/bin/env ruby
# Print out your last 5 tovala deliveries, along with who the chef was and whether it was a best seller/chef's pick or not
# Add "csv" arg to get in csv format for easy adding to spreadhsheet (`./tovala.rb csv`)
require 'net/http'
require 'uri'
require 'json'
require 'date'
@neilgupta
neilgupta / styles.css
Created July 20, 2020 13:52
HLS-compatible video player
.VideoButtons {
text-align: center;
margin: 3em auto 5.5em auto;
}
.VideoButtons span {
margin: 1em;
}
@media only screen and (max-width: 550px) {
@neilgupta
neilgupta / mqtt.py
Created May 3, 2020 00:34
Hiome MQTT example
import paho.mqtt.client as mqtt
import json
def onConnect(client, userdata, flags, rc):
client.subscribe('hs/1/com.hiome/#/occupancy', qos=1)
def onMessage(client, userdata, payload):
topic = payload.topic.split('/')
room_id = topic[3]
msg = json.loads(payload.payload)
@neilgupta
neilgupta / synesthesia.py
Created April 12, 2020 18:22
Consistently convert any string into a color hex
def colorize(input):
# convert string to base36 and then scientific notation
a = '%E' % float(int(input, 36))
scinot = a.split('E')[0].rstrip('0').rstrip('.') + 'E' + a.split('E')[1]
# convert decimal portion of scientific notation back to hex and pad to 6 values
return "#" + "{0:x}".format(int(scinot[2:-5]) & 0xFFFFFF)[-6:].zfill(6)
@neilgupta
neilgupta / configuration.yml
Last active September 10, 2022 04:31
Home Assistant Hiome Configuration
# connect to Hiome Core
# if your OS cannot resolve hiome.local, install mDNS (Bonjour) support
# or use Hiome Core's IP address
mqtt:
broker: hiome.local
port: 1883
client_id: home-assistant
keepalive: 60
# add each room as a sensor
@neilgupta
neilgupta / docker-compose.yml
Last active July 30, 2019 21:57
Grafana + Statsd docker-compose
version: "3"
services:
grafana:
image: grafana/grafana
container_name: grafana
restart: always
ports:
- 80:3000
networks:
- grafana-net
@neilgupta
neilgupta / smooth-scroll.js
Created June 24, 2015 16:29
Smooth Scroll
function backToTop() {
var x1 = x2 = x3 = 0;
var y1 = y2 = y3 = 0;
if (document.documentElement) {
x1 = document.documentElement.scrollLeft || 0;
y1 = document.documentElement.scrollTop || 0;
}
if (document.body) {
@neilgupta
neilgupta / SGEmail.java
Created July 28, 2012 18:48
Send emails via SMTP & SendGrid
package com.tabuleapp.SendGrid;
import javax.mail.Authenticator;
import javax.mail.BodyPart;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Multipart;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
@neilgupta
neilgupta / substr.js
Created December 4, 2011 09:46
Implement substr using regex in javascript... This gist is equivalent to str = str.substr(0,87)+"...";
str = str.replace(/^([\s\S]{0,87})[\s\S]*$/, "$1...");