Skip to content

Instantly share code, notes, and snippets.

View oscarb's full-sized avatar

Oscar Björkman oscarb

View GitHub Profile
@domenic
domenic / promises.md
Last active June 24, 2024 03:11
You're Missing the Point of Promises

This article has been given a more permanent home on my blog. Also, since it was first written, the development of the Promises/A+ specification has made the original emphasis on Promises/A seem somewhat outdated.

You're Missing the Point of Promises

Promises are a software abstraction that makes working with asynchronous operations much more pleasant. In the most basic definition, your code will move from continuation-passing style:

getTweetsFor("domenic", function (err, results) {
 // the rest of your code goes here.
@skyfishjy
skyfishjy / CursorRecyclerViewAdapter.java
Last active December 16, 2023 08:55
CursorRecyclerViewAdapter
/*
* Copyright (C) 2014 skyfish.jy@gmail.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
var mediaJSON = { "categories" : [ { "name" : "Movies",
"videos" : [
{ "description" : "Big Buck Bunny tells the story of a giant rabbit with a heart bigger than himself. When one sunny day three rodents rudely harass him, something snaps... and the rabbit ain't no bunny anymore! In the typical cartoon tradition he prepares the nasty rodents a comical revenge.\n\nLicensed under the Creative Commons Attribution license\nhttp://www.bigbuckbunny.org",
"sources" : [ "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4" ],
"subtitle" : "By Blender Foundation",
"thumb" : "images/BigBuckBunny.jpg",
"title" : "Big Buck Bunny"
},
{ "description" : "The first Blender Open Movie from 2006",
"sources" : [ "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ElephantsDream.mp4" ],
@hordurk
hordurk / grouped_light.py
Last active January 28, 2024 15:46 — forked from evelant/grouped_light.py
Grouped light platform for Home Assistant
import logging
# Import the device class from the component that you want to support
from homeassistant.components import light
from homeassistant.const import (STATE_OFF, STATE_ON, SERVICE_TURN_ON, SERVICE_TURN_OFF, ATTR_ENTITY_ID)
CONF_NAME = 'name'
CONF_ENTITIES = 'entities'
_LOGGER = logging.getLogger(__name__)
@timvisee
timvisee / falsehoods-programming-time-list.md
Last active July 27, 2024 18:55
Falsehoods programmers believe about time, in a single list

Falsehoods programmers believe about time

This is a compiled list of falsehoods programmers tend to believe about working with time.

Don't re-invent a date time library yourself. If you think you understand everything about time, you're probably doing it wrong.

Falsehoods

  • There are always 24 hours in a day.
  • February is always 28 days long.
  • Any 24-hour period will always begin and end in the same day (or week, or month).
@hjbotha
hjbotha / free_ports.sh
Last active July 10, 2024 17:33
Free ports 80 and 443 on Synology NAS
#! /bin/bash
# NEWLY ADDED BACKUP FUNCTIONALITY IS NOT FULLY TESTED YET, USE WITH CARE, ESPECIALLY DELETION
# Developed for DSM 6 - 7.0.1. Not tested on other versions.
# Steps to install
# Save this script in one of your shares
# Edit it according to your requirements
# Backup /usr/syno/share/nginx/ as follows:
# # cd /usr/syno/share/
# # tar cvf ~/nginx.tar nginx
@dale3h
dale3h / automations.yaml
Created May 15, 2019 04:45
[Home Assistant] Webhook Debugger
# Webhook URL: https://[your-hass-domain]/api/webhook/2qDFuSEBA7jU2sNjaK6JD5ac3FxnGfVTSF
- id: webhook_debugger
alias: "Webhook Debugger"
trigger:
- platform: webhook
webhook_id: 2qDFuSEBA7jU2sNjaK6JD5ac3FxnGfVTSF
action:
- service: persistent_notification.create
data_template:
http://www.gstatic.com/images/icons/material/apps/weather/2x/wintry_mix_rain_snow_light_color_96dp.png
http://www.gstatic.com/images/icons/material/apps/weather/2x/haze_fog_dust_smoke_light_color_96dp.png
http://www.gstatic.com/images/icons/material/apps/weather/2x/cloudy_light_color_96dp.png
http://www.gstatic.com/images/icons/material/apps/weather/2x/snow_showers_snow_light_color_96dp.png
http://www.gstatic.com/images/icons/material/apps/weather/2x/flurries_light_color_96dp.png
@iurysza
iurysza / ktlint.gradle
Last active April 22, 2024 11:14
Gradle task that runs ktlint only over changed files
configurations { ktlint }
dependencies { ktlint "com.pinterest:ktlint:$ktlintVersion" }
task ktlintCi(type: JavaExec, group: "verification") {
description = "Run Kotlin linter on changed files."
group = "CI"
main = "com.pinterest.ktlint.Main"
classpath = configurations.ktlint
doFirst {
@HarvsG
HarvsG / tradfriZHAhowtos.md
Last active July 20, 2024 15:21
Adding IKEA Tradfri Devices with ZHA on Home Assistant

Shortcut and On/Off switches

  1. Remove back cover with philips scredriver and instert provided battery
  2. In home assistant select a ZHA always-on zigbee device - such as a powered light or signal repeater in the same room the shortcut button will end up in
  3. Select "Add device via this device"
  4. Press the pair button 4 times on the back of the shortcut button
  5. Wait
  6. If using an On/Off switch and you want to bind it to a bulb for non-controller dependant control (i.e will work if home assistant is down)

Pairing On/Off Switches to IKEA Bulbs