Skip to content

Instantly share code, notes, and snippets.

View Crocmagnon's full-sized avatar
👋

Gabriel Augendre Crocmagnon

👋
View GitHub Profile
ampoule_entree_motion:
module: timed_light
class: TimedLight
controller_ids:
- 14:b4:57:ff:fe:69:54:66
- d0:cf:5e:ff:fe:f2:98:e6
light_id: light.ampoule_entree
timer_duration: 120
before: 09:00:00
after: sunset
import hassapi as hass
class TimedLight(hass.Hass):
def initialize(self):
self.timer_duration = self.args["timer_duration"]
self.light_id = self.args["light_id"]
self.before = self.get_time_boundary("before")
self.after = self.get_time_boundary("after")
@Crocmagnon
Crocmagnon / delete_images.gs
Created December 18, 2019 07:27
Delete all images in a Google Spreadsheet
function deleteImages() {
var images = SpreadsheetApp.getActive().getImages();
for (var i = 0; i < images.length; i++) {
var image = images[i];
image.remove();
}
}
WEEKDAYS = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
def day_of_week_offset(day, offset):
return WEEKDAYS[(WEEKDAYS.index(day) + offset) % 7]
def main():
assert day_of_week_offset("Monday", 0) == "Monday", "Same day"
assert day_of_week_offset("Monday", 1) == "Tuesday", "Next day same week"
assert day_of_week_offset("Tuesday", 3) == "Friday", "Several days later same week"
@Crocmagnon
Crocmagnon / rockpaperscissorslizardspock.py
Last active November 25, 2019 15:07
A game of rock papers scissors lizard spock
import argparse
import random
ROCK = "rock"
PAPER = "paper"
SCISSORS = "scissors"
LIZARD = "lizard"
SPOCK = "spock"
QUIT = "quit"
COMPUTER_CHOICES = [ROCK, PAPER, SCISSORS, LIZARD, SPOCK]
from typing import List, Set
def missing_ints(numbers: List[int]) -> Set[int]:
if not numbers:
return set()
first = numbers[0]
last = numbers[-1]
whole_range = set(range(first, last + 1))
existing = set(numbers)
def sub_length(arr):
"""
Given an array of n integers, find the length of the longest increasing subsequence
:param arr: The array to parse
:return: the length of the longest increasing subsequence
"""
if not arr:
return 0
longest_streak = 1
@Crocmagnon
Crocmagnon / scrape.py
Created November 9, 2018 07:41
Extract videos from YT
from bs4 import BeautifulSoup
import sys
import requests
from http.client import RemoteDisconnected
from urllib3.exceptions import ProtocolError
from requests.exceptions import ConnectionError
BASE_URL = "https://www.youtube.com"
first_id = sys.argv[1]
suffix = "/watch?v=" + first_id
@Crocmagnon
Crocmagnon / crappy_check_email.js
Last active August 14, 2018 08:24
Crappy email check. Don't do this at home !
var regexEmail = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
if(email == '' || !regexEmail.test(email)){
$('.edit_data input[name="customer[email]').after("<p class='form-error'>Merci de renseigner un email correct</p>");
return false;
}