// This code is just for my reference
public static void main(String[] args) {
Logger mongoLogger = Logger.getLogger( "org.mongodb.driver" );
mongoLogger.setLevel(Level.SEVERE);
MongoClient mongoClient = MongoClients.create();
MongoDatabase database = mongoClient.getDatabase("testdb");
GridFSBucket gridFSFilesBucket = GridFSBuckets.create(database);
ObjectId fileId = new ObjectId();
try {
InputStream streamToUploadFrom = new FileInputStream(new File("d:\\200mb.mkv"));
// GridFSUploadOptions options = new GridFSUploadOptions()
// .chunkSizeBytes(1000)
// .metadata(new Document("type", "presentation"));
fileId = gridFSFilesBucket.uploadFromStream("myfile", streamToUploadFrom);
System.out.println("ObjectID" + fileId);
} catch(FileNotFoundException ex) {
System.out.println("Error" + ex.getMessage());
}
try {
FileOutputStream streamToDownloadTo = new FileOutputStream("d:/out.mkv");
gridFSFilesBucket.downloadToStream(fileId , streamToDownloadTo);
streamToDownloadTo.close();
System.out.println("Finished!");
} catch (IOException e) {
// handle exception
}
}
Bookmark: Raise event from a WPF User control
This blog is just for sample code keeping.
// UserControl1.xaml
<UserControl x:Class=”WpfApp1.UserControl1″
xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation”
xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml”
xmlns:mc=”http://schemas.openxmlformats.org/markup-compatibility/2006″
xmlns:d=”http://schemas.microsoft.com/expression/blend/2008″
xmlns:local=”clr-namespace:WpfApp1″
mc:Ignorable=”d” Background=”Red” Height=”186.646″ Width=”411.693″>
<Grid>
<Button Content=”Button” HorizontalAlignment=”Left” Margin=”80,72,0,0″ VerticalAlignment=”Top” Width=”75″ Click=”Button_Click”/>
</Grid>
</UserControl>
// UserControl1.xaml.cs
namespace WpfApp1
{
/// <summary>
/// Interaction logic for UserControl1.xaml
/// </summary>
public partial class UserControl1 : UserControl
{
public event EventHandler MyButtonClick;
public UserControl1()
{
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
this.MyButtonClick(this, new EventArgs());
}
}
}
// UserControl2.xaml
<UserControl x:Class=”WpfApp1.UserControl2″
xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation”
xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml”
xmlns:mc=”http://schemas.openxmlformats.org/markup-compatibility/2006″
xmlns:d=”http://schemas.microsoft.com/expression/blend/2008″
xmlns:local=”clr-namespace:WpfApp1″
mc:Ignorable=”d”
d:DesignHeight=”450″ d:DesignWidth=”800″ Background=”Green”>
<Grid>
</Grid>
</UserControl>
// MainWindow.xaml
<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″
xmlns:local=”clr-namespace:WpfApp1″
mc:Ignorable=”d”
Title=”MainWindow” Height=”450″ Width=”800″>
<Grid x:Name=”MyGrid”>
<local:UserControl1 x:Name=”userControl1″ HorizontalAlignment=”Left” Height=”100″ Margin=”99,62,0,0″ VerticalAlignment=”Top” Width=”242″ MyButtonClick=”UserControl1_MyButtonClick” />
</Grid>
</Window>
// MainWindow.xaml.cs
namespace WpfApp1
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
private void UserControl1_MyButtonClick(object sender, EventArgs e)
{
}
}
}
Python Programming series in Malayalam–Part 3 | How computers think
I am Automation Anywhere Business Analyst Certified now!
Automation Anywhere is a developer of robotic process automation software, which employs software bots to complete processes.
Verify my credential here.
“Units” in Cloud Platforms and Services
When it comes to costing/pricing on cloud based platforms such as Azure or AWS, it is always a confusion especially for beginners what various units mean. Let us have a look at some such common unit terminologies.
- SKU – Stock Keeping Unit – A purchasable units in a platform. Ref – https://en.wikipedia.org/wiki/Stock_keeping_unit
- ACU – Azure Compute Unit – A unit used to compare compute performance across Azure SKUs. Ref – https://docs.microsoft.com/en-us/azure/virtual-machines/acu
- TU – Transaction Unit – Usually 10K transactions = 1 Transaction Unit
- DTU – Database Transaction Unit – Ref – https://docs.microsoft.com/en-us/azure/azure-sql/database/purchasing-models#understanding-dtus
- eDTU – elastic DTU – Ref – https://docs.microsoft.com/en-us/azure/azure-sql/database/purchasing-models#dtu-based-purchasing-model
- RU – Request Unit – Ref – https://docs.microsoft.com/en-us/azure/cosmos-db/request-units
- DBCU – Databricks Commit Unit – Ref – https://azure.microsoft.com/en-in/pricing/details/databricks/
- DBU – Databricks Unit – Ref – https://docs.databricks.com/administration-guide/capacity-planning/cmbp.html
- DPU – Database Processing Unit – Ref – https://aws.amazon.com/glue/pricing/
This list will be updated regularly.
Few useful slides from today’s “AWS Data, Databases & Analytics online series” Day-2 opening session
Starting a Python Programming learning series in Malayalam
I am starting a new articles series, but this time in my regional language – Malayalam. Please find the link to the Part-01 of series below. Please read, support, send feedback and suggestions regularly.
A useful slide from today’s “AWS Data, Databases & Analytics online series” opening session.
Bookmark: Netflix fast.com Architecture
fast.com is an internet bandwidth speed test service from Netflix. Read its implementation architecture in their tech blog.
Coding for fun: JavaScript based simple doodle
Here is a pure JavaScript based, basic drawing tool. It supports both mouse and tap.
Demo URL: https://ninethsense.github.io/code-share/Doodle/
002 <head>
003 <meta http-equiv="content-type" content="text/html; charset=utf-8">
004 <style>
005 body {
006 margin: 0 0;
007 overflow:hidden;
008 cursor:url(pencil1.cur), auto;
009 touch-action: none;
010 }
011 #d {
012 display: flex;
013 }
014 #sb {
015 background-color: #ddd;
016 box-shadow: 2px 2px 5px;
017 padding: 2 2;
018 position:absolute;
019 top:0;
020 left:0;
021 }
022 #sb input {
023 min-width:100px;
024 min-height:70px;
025 }
026 #sb input {
027 font-family: Arial, Helvetica, sans-serif;
028 font-size: 13pt;
029 font-weight:bold;
030 cursor: pointer;
031 }
032 </style>
033 </head>
034 <body>
035 <div id="sb">
036 <input type="button" value="C L E A R" id="clear" />
037 </div>
038 <canvas id="d"></div>
039
040 <script>
041 var d = document.getElementById("d");
042 d.width = window.innerWidth;
043 d.height = window.innerHeight;
044 var ctx = d.getContext("2d");
045 ctx.lineWidth = 3;
046 px=0, py=0;clk=false;
047
048
049
050 startdraw = function(e) {
051 px = e.clientX - d.offsetLeft;
052 py = e.clientY - d.offsetTop;
053 clk = true;
054 }
055
056 draw = function(e) {
057
058 if (clk) {
059 e = e.touches?e.touches[0]:e;
060 ctx.beginPath();
061 ctx.moveTo(px,py);
062 px = e.clientX - d.offsetLeft;
063 py = e.clientY - d.offsetTop;
064 ctx.lineTo(px,py);
065 ctx.strokeStyle = '#ff0000';
066 ctx.stroke();
067 ctx.closePath();
068 }
069 }
070
071 document.getElementById("clear").addEventListener("click", function() {
072 if (confirm("Clear the whiteboard?")) {
073 ctx.clearRect(0,0,d.width,d.height);
074 }
075 });
076
077 d.addEventListener("touchstart", startdraw);
078 d.addEventListener("mousemove", draw, false);
079 d.addEventListener("mousedown", startdraw, false);
080 d.addEventListener("touchmove", draw, false);
081 d.addEventListener("mouseup", function() { clk = false });
082 d.addEventListener("touchend", function() { clk = false });
083
084 </script>
085 </body>
086 </html>