Skip to content

Instantly share code, notes, and snippets.

View danielvlopes's full-sized avatar

Daniel Lopes danielvlopes

View GitHub Profile
const cmd = Ingredients.TextField.toLowerCase()
const supportedColors = [
'white', 'red', 'orange', 'yellow',
'cyan', 'green', 'blue', 'purple', 'pink'
]
const skipAllBut = (exception:string)=> {
const msg = "Unknown command"
if (exception != 'color') Lifx.color.skip(msg)
@danielvlopes
danielvlopes / applet-random-quote-button.js
Last active March 8, 2017 02:06
Applet Cookbook: Random motivational quote button
// Quotes by brainyquote.com
var data = [{"quote":"Life is 10% what happens to you and 90% how you react to it.","author":"Charles R. Swindoll"},{"quote":"Only I can change my life. No one can do it for me.","author":"Carol Burnett"},{"quote":"Infuse your life with action. Don't wait for it to happen. Make it happen. Make your own future. Make your own hope. Make your own love. And whatever your beliefs, honor your creator, not by passively waiting for grace to come down from upon high, but by doing what you can to make grace happen... yourself, right now, right down here on Earth.","author":"Bradley Whitford"},{"quote":"Optimism is the faith that leads to achievement. Nothing can be done without hope and confidence.","author":"Helen Keller"},{"quote":"Good, better, best. Never let it rest. 'Til your good is better and your better is best.","author":"St. Jerome"},{"quote":"Always do your best. What you plant now, you will harvest later.","author":"Og Mandino"},{"quote":"In order to succeed, we must first beli
@danielvlopes
danielvlopes / applet-daily-quote.js
Last active March 8, 2017 02:07
Applet Cookbook: Daily motivational quote
// quotes by brainyquote.com
var data = [{"quote":"Life is 10% what happens to you and 90% how you react to it.","author":"Charles R. Swindoll"},{"quote":"Only I can change my life. No one can do it for me.","author":"Carol Burnett"},{"quote":"Infuse your life with action. Don't wait for it to happen. Make it happen. Make your own future. Make your own hope. Make your own love. And whatever your beliefs, honor your creator, not by passively waiting for grace to come down from upon high, but by doing what you can to make grace happen... yourself, right now, right down here on Earth.","author":"Bradley Whitford"},{"quote":"Optimism is the faith that leads to achievement. Nothing can be done without hope and confidence.","author":"Helen Keller"}]
var day = Meta.currentTime.day()
var wday = Meta.currentTime.format('dddd')
var msg = data[day]['quote'] + 'by ' + data[day]['author']
IfNotifications.sendNotification.setMessage(msg)
EmailDigest.sendWeeklyEmail.setTitle(wday)
EmailDigest.sendWeeklyEmail.setMessage(
@danielvlopes
danielvlopes / applet-flight-deals.js
Last active March 8, 2017 02:07
Applet Cookbook: Flight deals from or to San Francisco
var txt = Ingredients.Text || ""
var price = parseInt((txt.match(/\s\$(\d+)\s/) || [])[1])
if (price > 400) {
EmailDigest.sendDailyEmail.skip("Too expensive")
}
@danielvlopes
danielvlopes / applet-time-color-change.js
Last active March 8, 2017 02:08
Applet Cookbook: Adjust your lights as it gets darker outside
var hour = Meta.currentTime.hour()
var colorKey = hour.toString()
var colors: {[key:string]:string} = {
"17":"#F3F2EB",
"18":"#F7F2E6",
"19":"#F9EFE0",
"20":"#FBEFDC",
"21":"#FBE5C6",
"22":"#FBE5C6"
@danielvlopes
danielvlopes / applet-shuffle-colors.js
Last active March 8, 2017 02:08
Applet Cookbook: Shuffle colors
var colors = ["#FF8400", "#FF0000", "#15FF00", "#FF00D4","#00D4FF","#003CFF"]
var index = Math.floor((Math.random() * colors.length))
Lifx.color.setAdvancedOptions('color: ' + colors[index] + '; brightness: 1; duration: 12')
ring, awair, something...
@danielvlopes
danielvlopes / hello_world.rb
Created January 26, 2017 16:21
Sample IFTTT service
IFTTT_CHANNEL_KEY = "REPLACE_ME"
require "bundler/inline"
gemfile do
source "https://rubygems.org"
gem "rails", "~> 5.0"
end
require "action_controller/railtie"
<activity android:name="your.package.name.to.DeepLinkActivity">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="yourscheme" android:host="yourhost" android:path="/yourpath"/>
</intent-filter>
</activity>
Uri uri = new Uri.Builder()
.scheme("https")
.authority("ifttt.com")
.appendPath("applets")
.appendPath("_YOUR_APPLET_ID_")
.appendPath("embed")
.appendQuery("redirect_uri", "yourscheme://yourhost/yourpath")
.build();
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
activity.startActivity(intent);