Category Archive: Code

Nov
01

Scan and automatically OCR receipts, bills, letters, etc. without turning on your computer

I was looking for a solution to digitally archive incoming (paper) bills, receipts, letters, etc. to make them easily searchable (OCR). Ideally, this solutions would be as simply as putting a document on your scanner and pressing a button—done: the digitized document would be stored on a network drive. I really don’t like having to …

Continue reading »

Aug
02

Sending Emails with Attachement for New S3 Objects

Use Case and Solution Notify users about a new object (e.g., an image or log file) being added to an S3 bucket by sending an email that contains the new object as attachement. The solution presented here uses AWS Lambda (with S3 as event source), mailcomposer (a Node.JS module) to compose, and finally Amazon’s Simple …

Continue reading »

Jul
24

Installing SciKits’ Bootstrap using Python 3.3

Installing scikits.bootstrap (version 0.3.1) using easy install (Python 3.3 on Windows 7) ran through, despite reporting a syntax error (referring to line “except TypeError, e”). However, importing failed (“ImportError: No module named ‘bootstrap’”). The following few things have to be fixed for bootstrap to run under Python 3.3: scikits\bootstrap\__init.py__ line 1: from .bootstrap import * …

Continue reading »

Jul
19

Simple Moving Average Filter in Python

Just a simple moving average filter implementation as Python class, nothing more. class MovingAverageFilter: """Simple moving average filter"""   @property def avg(self): """Returns current moving average value""" return self.__avg   def __init__(self, n = 8, initial_value = 0): """Inits filter with window size n and initial value""" self.__n = n self.__buffer = [initial_value/n]*n self.__avg = …

Continue reading »

Mar
18

Filtering Microsoft Surface Finger Touches for ScatterViewItems

By default, Microsoft Surface responds to any touch, including non-finger touches for example caused by a hovering hand or a sleeve touching the table. While they can be ignored using the GetIsFingerRecognized() method and setting the Handled flag of TouchEventArgs in preview touch handlers, the ScatterView seems to be somewhat special. Although you cannot move it ScatterViewItems …

Continue reading »

Mar
06

.NET/C# Prism InteractionRequests in WPF

Using Prism’s InteractionRequests, view models can make interaction requests (such as notifications or confirmations) to the view. It seems that WPF support and documentation lacks behind Silverlight, though. Therefore, I compiled a quick example using InteractionRequests in WPF to trigger a message. View Model using Microsoft.Practices.Prism.ViewModel; using Microsoft.Practices.Prism.Interactivity.InteractionRequest;   public class MyViewModel : NotificationObject { …

Continue reading »

Jan
05

.NET/C# First Visible Item (ListBox) Attached Behavior

I improved and refactored my previous code to get and set a ListBox’s first visible item. It is now realized as attached behavior and supports two-way binding: ListBoxExtensions ListBoxExtensions adds some methods to the ListBox class to get and set its first visible item. It expects the ListBox to use a VirtualizingStackPanel to hold its …

Continue reading »

Dec
20

.NET/C# Binding Custom DependencyProperty to ViewModel Property

Consider the following scenario: UserControl with a custom DependencyProperty ViewModel with an exposed property (using INotifyPropertyChanged) Goal: create two-way data binding between these two properties (i.e., ViewModel property gets updated if DependencyProperty changes and vice versa) ViewModel (implements INotifyPropertyChanged): private string _someProperty;   public string SomeProperty { get { return _someProperty; } set { _someProperty …

Continue reading »

Dec
19

.NET/C# Get First Visible Item of a ListBox

This is some code to get the first visible item in a WPF ListBox whenever the user scrolled. In XAML: <ListBox Name="MyListBox" ItemsSource="{Binding SomeCollection}" ScrollViewer.ScrollChanged="ScrollChanged"/> In the code-behind: private void ScrollChanged(object sender, ScrollChangedEventArgs e) { VirtualizingStackPanel panel = FindVisualChild<VirtualizingStackPanel>(MyListBox); if (MyListBox.Items.Count > 0 && Panel != null) { int offset = (panel.Orientation == Orientation.Horizontal) ? …

Continue reading »

Dec
17

.NET/C# MVVM RelayCommand with Parameters

I am using the MVVM Light Toolkit here to implement a RelayCommand with parameters. In this example, the command adds a value (entered by the user) to a number (held in the view model). A TextBox is used to enter the value. I did not like the idea of binding its value to a property …

Continue reading »

Older posts «