Skip to content

Instantly share code, notes, and snippets.

Avatar

Frédéric Barthelet fredericbarthelet

View GitHub Profile
View index.js
const Service, Characteristic;
module.exports = function (homebridge) {
 Service = homebridge.hap.Service;
 Characteristic = homebridge.hap.Characteristic;
 homebridge.registerAccessory(“switch-plugin”, “MyAwesomeSwitch”, mySwitch);
};
View index.js
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)
View index.js
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;
View CountingEventListener.php
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 Apr 26, 2020
CloudFormation template
View s3-bucket.yml
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 Oct 11, 2020
Serverless all-in-one definition
View serverless.yml
service: myServerlessService
provider:
name: aws
runtime: nodejs12.x
functions:
hello:
handler: index.hello
goodbye:
@fredericbarthelet
fredericbarthelet / functions.yml
Created Oct 11, 2020
Serverless.yml splitting
View functions.yml
hello:
handler: index.hello
goodbye:
handler: index.goodbye
@fredericbarthelet
fredericbarthelet / functions.ts
Created Oct 11, 2020
Serverless.ts splitting
View functions.ts
export default {
hello: {
handler: 'index.hello'
},
goodbye: {
handler: 'index.goodbye'
}
};
@fredericbarthelet
fredericbarthelet / functions.ts
Last active Jun 30, 2021
Serverless.ts complex project imports
View functions.ts
export { default as hello } from './hello';
export { default as goodbye } from './goodbye';
@fredericbarthelet
fredericbarthelet / create.ts
Last active Jun 30, 2021
lambda with dynamo
View create.ts
import { DynamoDB } from 'aws-sdk';
export default {
handler:'create.main',
environment: {
TABLE_NAME: {
Ref: 'MyTable'
}
},
events: [