Skip to content

Instantly share code, notes, and snippets.

View satr's full-sized avatar

Sergey Smolnikov satr

View GitHub Profile
@satr
satr / MainWindow.xaml
Created August 31, 2018 06:51
WPF ComboBox with a title in the popup
<Window x:Class="WpfApp1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Window.Resources>
<Style TargetType="ComboBox">
<Setter Property="Template">
@satr
satr / flutter_snakbar.dart
Last active December 3, 2018 19:29
Flutter SnakBar
var text = "some text";
final snackBar = SnackBar(
content: Text("Snack: $text"),
action: SnackBarAction(
label: 'Undo',
onPressed: () {
// Some code to undo the change!
},
),
);
GlobalKey<ScaffoldState> scaffoldKey = new GlobalKey();
@override
Widget build(BuildContext context) {
return Scaffold(
key: scaffoldKey,
...
scaffoldKey.currentState.showSnackBar(SnackBar(content: Text("some text")));
@satr
satr / mnist-fashion-example.py
Created May 4, 2019 08:18
Learn image recognition with fashion_mnist
# Based on https://www.coursera.org/learn/introduction-tensorflow/home/welcome
# Course 1 - Part 4 - Lesson 2 - Notebook
#https://github.com/zalandoresearch/fashion-mnist
import tensorflow as tf
from tensorflow import keras
mnist = keras.datasets.fashion_mnist
(training_images, training_labels), (test_images, test_labels) = mnist.load_data()
import matplotlib.pyplot as plt
@satr
satr / TensorFlowCallbacks.py
Created May 15, 2019 13:52
Usage of TensorFlow callbacks
import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt
from tensorflow import keras
mnist = keras.datasets.mnist
(training_images, training_labels), (test_images, test_labels) = mnist.load_data()
#plt.imshow(test_images[0])
class FitCallback(tf.keras.callbacks.Callback):
@satr
satr / LambdaRequestHandlerWithLoggerTest.java
Created May 15, 2019 18:52
Mock Lambda Context and Logger while testing AWS Lambda RequestHandler (with JUnit4)
//In the test class
import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.LambdaLogger;
import org.junit.runner.RunWith;
import org.mockito.junit.MockitoJUnitRunner;
import org.mockito.Mock;
import org.junit.Before;
import org.junit.Test;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.doAnswer;
@satr
satr / json-content-example.js
Created May 16, 2019 05:36
JSON content example
{
"string_value": "some text",
"int_value": "123",
"float_value":"12.345",
"bool_value": "true",
"date_value": "2019-05-10T10:20:35.000+0",
"array_value": [1,2,3,4,5],
"object_value": {
"int_field": "789",
"string_field": "object's text"
@satr
satr / JacksonDeserializeObject.java
Created May 17, 2019 09:53
Deserialize an object from JSON with Jackson lib
/*
https://github.com/FasterXML/jackson
Grade.build
dependencies {
compile group:'com.fasterxml.jackson', name:'jackson-bom', version: '2.9.8'
}
Input:
{ "first_name" : "John", "last_name" : "Smith" }
{ "first_name" : "John" }
@satr
satr / build.gradle
Created June 9, 2019 05:34
Dependencies and jar-task in build.gradle for AWS Lambda function on Java for Amazon Alexa Skill
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
compile group: 'com.amazon.alexa', name: 'ask-sdk', version:'2.17.2'
compile group: 'com.amazonaws', name: 'aws-lambda-java-log4j2', version:'1.1.0'
}
jar {
from {
configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
}
}
@satr
satr / alexa-proactive-event-property-in-alexa-skill-manifest.js
Last active June 9, 2019 05:41
Alexa Proactive event property in Alexa Skill manifest
"events": {
"publications": [
{ "eventName": "AMAZON.OrderStatus.Updated" },
{ "eventName": "AMAZON.MediaContent.Available" }
],
"endpoint": {
"uri": "YOUR-AWS-LAMBDA-FUNCTION-ARN"
}
}