Skip to content

Instantly share code, notes, and snippets.

View andreafalzetti's full-sized avatar

Andrea Falzetti andreafalzetti

View GitHub Profile
@andreafalzetti
andreafalzetti / Add an event in CalDAV with Node.js
Last active April 3, 2022 00:22
This is a basic function to add an event into a calendar using Node.js and the CalDAV protocol
/**
* On message callback, called when a message (of any type) is detected with the real time messaging API
* @param {object} event
* @param {string} url (CalDAV Server URL)
* @param {string} user (CalDAV Username/Email)
* @param {string} user (CalDAV Password)
* @param {function} cb (Callback function)
*
* The object event needs the following attributes:
* event.key - A random string which will be the unique ID of the event in CalDAV
/**
* Get a list of Events from a given Calendarurl
*
* @param {String} url
* @param {String} user
* @param {String} pass
* @param {String} date from which to start like 20140101T120000Z
* @param {String} date from which to stop like 20140102T120000Z, optional (can be undefined)
* @param {function} cb
*/
@andreafalzetti
andreafalzetti / randomize-variables-string.js
Last active October 21, 2016 12:16
Randomize variables in a string
Conversation.prototype.randomizeMessage = function(message) {
const pattern = /\[(.*?)\]/g;
const matches = message.match(pattern);
if(matches) {
matches.map((match) => {
const items = match.substring(1, match.length-1).split('|');
const randomItem = items[Math.floor(Math.random()*items.length)];
message = message.replace(match, randomItem);
});
}
@andreafalzetti
andreafalzetti / bot-script-example-hello.yml
Created December 14, 2016 22:42
Proof of concept for a YAML script for a Chat Bot
0:
messages:
- Hello!
- I'm a Bot!
next: 1
1:
messages:
- "What's your name?"
input:
ChatBot.prototype.run = function(tasks, data) {
if(typeof tasks === "undefined" || tasks === null) {
tasks = this.getNextAction();
}
async.forEachOfLimit(tasks, 1, this.resolveAction.bind(this), err => {
if(err) {
console.log("Error", err);
} else {
0:
messages:
- "Would you like to send me a picture?"
input:
type: buttons_single_select
key: picture_yes_no
options:
[Yes, sure]:
input:
type: image
<InteractiveBoxContainer>
<InteractiveBoxButton
title={'YES'}
text={'I want this'}
height={350}
value={'yes'}
/>
<InteractiveBoxButton
title='NO'
text={'I don\'t want this'}
@andreafalzetti
andreafalzetti / picasso_code.js
Last active October 31, 2017 14:48
Picasso Code Sample
const reactStringReplace = require('react-string-replace');
import PushNotification from 'react-native-push-notification';
var jwtDecode = require('jwt-decode');
const auth0 = new Auth0(constant.AuthDomainName);
import DateTimePicker from 'react-native-modal-datetime-picker';
class Example extends React.Component {
constructor(props) {
super(props);
this.state = {
@andreafalzetti
andreafalzetti / jks-to-pem.sh
Last active February 19, 2018 13:58
Extract the private key from a JSK repository
#!/bin/bash
# This script extracts the private key from a JKS repository
#
# Usage:
# ./jks-to-pem.sh keystore.jks
#
P12_KEYSTORE=./keystore.p12
ENCRYPTED_PRIVATE_KEY=./encrypted-private-key.pem

Keybase proof

I hereby claim:

  • I am andreafalzetti on github.
  • I am afalzetti (https://keybase.io/afalzetti) on keybase.
  • I have a public key ASArNRIFsi2Y0sEuSugr50H_E_gMK41QJhvrd6eVflMjbwo

To claim this, I am signing this object: