Skip to content

Instantly share code, notes, and snippets.

View anaisbetts's full-sized avatar

Ani Betts anaisbetts

View GitHub Profile
namespace GlobalHotKey
{
public class GlobalKeyboardHookEventArgs : HandledEventArgs
{
public GlobalKeyboardHook.KeyboardState KeyboardState { get; private set; }
public GlobalKeyboardHook.LowLevelKeyboardInputEvent KeyboardData { get; private set; }
public GlobalKeyboardHookEventArgs(
GlobalKeyboardHook.LowLevelKeyboardInputEvent keyboardData,
GlobalKeyboardHook.KeyboardState keyboardState)
@anaisbetts
anaisbetts / example.ts
Last active January 20, 2019 04:37
always use function parameters
function Example() {
// Crap, we just made a Firebase query for each render instead of
// what we wanted, a query set up on mount, and cleaned up on unmount
const query = useQuery(db.collections('lots-of-stuff').limit(10000));
return <ul>query.docs.map(x => (<li>{x}</li>));
}
import { Model } from '@whenjs/when';
import { useState } from 'react';
import { useWhen } from '../src/when-react/use-helpers';
class ViewModel extends Model {
public foo: number;
constructor() {
super();
@anaisbetts
anaisbetts / example.tsx
Created January 13, 2019 04:49
RxJS + React Hooks
import { Model, when } from '@whenjs/when';
import { scan } from 'rxjs/operators';
import { useState } from 'react';
import { useObservable } from '../src/when-react/use-helpers';
class ViewModel extends Model {
public foo: number;
constructor() {
@anaisbetts
anaisbetts / example.ts
Created August 27, 2018 04:46
RxJS + Home Assistant using When
async function main() {
const sock = create('ws://localhost:8123');
sock.connect();
await sock.auth('sekrit code');
const ha = new HomeAssistant(sock);
const light = new Light(ha, 'hue_lamp_1');
// light.state will always give you the initial value on subscribe
light.state.subscribe(x => console.log(x));
@anaisbetts
anaisbetts / example.ts
Created August 26, 2018 20:44
RxJS + Home Assistant
import { create } from './websocket-ha';
const homeAssistant = create('http://localhost:8123');
homeAssistant.connect();
await homeAssistant.auth("my secret password");
// Make API calls
console.log(await homeAssistant.call({type: 'get_config'}));
/**
* @license
* Copyright 2018 Google LLC. All Rights Reserved.
* 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
#!/bin/bash
git branch --merged | while read line
do
# If the line is in the format '* master' (indicating the current branch),
# this will be effectively empty, so we don't somehow delete the current
# branch
BRANCH=`echo "$line" | awk -F '*' '{ print $1 }'`
if [ -z "$BRANCH" ]
@anaisbetts
anaisbetts / Example.cs
Created August 28, 2017 05:15
Observe changes to top-level windows
var watchThatWindow = new ObservableWindow();
watchThatWindow.WindowCreated
.Select(hwnd => NativeMethods.GetWindowTitle(hwnd))
.Subscribe(x => Console.WriteLine($"Say hello to '{x}'!"));
import android.app.Activity
import android.bluetooth.BluetoothGattCharacteristic
import android.os.Bundle
import android.util.Log
import com.github.ivbaranov.rxbluetooth.RxBluetooth
import com.polidea.rxandroidble.RxBleClient
import com.polidea.rxandroidble.RxBleConnection
import com.polidea.rxandroidble.RxBleDevice
import com.polidea.rxandroidble.scan.ScanSettings
import rx.Observable