Skip to content

Instantly share code, notes, and snippets.

View fredericbarthelet's full-sized avatar

Frédéric Barthelet fredericbarthelet

View GitHub Profile
const Service, Characteristic;
module.exports = function (homebridge) {
 Service = homebridge.hap.Service;
 Characteristic = homebridge.hap.Characteristic;
 homebridge.registerAccessory(“switch-plugin”, “MyAwesomeSwitch”, mySwitch);
};
mySwitch.prototype = {
 getServices: function () {
 let informationService = new Service.AccessoryInformation();
 informationService
 .setCharacteristic(Characteristic.Manufacturer, “My switch manufacturer”)
 .setCharacteristic(Characteristic.Model, “My switch model”)
 .setCharacteristic(Characteristic.SerialNumber, “123–456–789”);
let switchService = new Service.Switch(“My switch”);
 switchService
 .getCharacteristic(Characteristic.On)
const request = require(‘request’);
const url = require(‘url’);
function mySwitch(log, config) {
 this.log = log;
 this.getUrl = url.parse(config[‘getUrl’]);
 this.postUrl = url.parse(config[‘postUrl’]);
}
mySwitch.prototype = {
getSwitchOnCharacteristic: function (next) {
 const me = this;
namespace App\EventListener;
use App\Entity\Counting;
use App\Entity\User;
use Doctrine\ORM\Event\PrePersistEventArgs;
use Symfony\Component\Security\Core\Security;
class CountingEventListener
{
/**
@fredericbarthelet
fredericbarthelet / s3-bucket.yml
Created April 26, 2020 19:19
CloudFormation template
AWSTemplateFormatVersion: 2010-09-09
Resources:
S3Bucket:
Type: AWS::S3::Bucket
Properties:
AccessControl: PublicRead
WebsiteConfiguration:
IndexDocument: index.html
ErrorDocument: error.html
DeletionPolicy: Retain
@fredericbarthelet
fredericbarthelet / serverless.yml
Last active October 11, 2020 10:54
Serverless all-in-one definition
service: myServerlessService
provider:
name: aws
runtime: nodejs12.x
functions:
hello:
handler: index.hello
goodbye:
@fredericbarthelet
fredericbarthelet / functions.yml
Created October 11, 2020 10:57
Serverless.yml splitting
hello:
handler: index.hello
goodbye:
handler: index.goodbye
@fredericbarthelet
fredericbarthelet / functions.ts
Created October 11, 2020 11:07
Serverless.ts splitting
export default {
hello: {
handler: 'index.hello'
},
goodbye: {
handler: 'index.goodbye'
}
};
@fredericbarthelet
fredericbarthelet / functions.ts
Last active June 30, 2021 19:27
Serverless.ts complex project imports
export { default as hello } from './hello';
export { default as goodbye } from './goodbye';
@fredericbarthelet
fredericbarthelet / create.ts
Last active June 30, 2021 19:27
lambda with dynamo
import { DynamoDB } from 'aws-sdk';
export default {
handler:'create.main',
environment: {
TABLE_NAME: {
Ref: 'MyTable'
}
},
events: [