Posts

Disabling the Lenovo Yoga Touchpad and Keyboard In Fedora

I can't find an easy way to disable the mouse and keyboard on screen flip of the Yoga in Fedora however an easy enough approach is to disable them by hand using xinput. Issue an: xinput --list [richie@localhost ~]$ xinput --list ⎡ Virtual core pointer id=2 [master pointer (3)] ⎜ ↳ Virtual core XTEST pointer id=4 [slave pointer (2)] ⎜ ↳ Logitech Unifying Device. Wireless PID:1028 id=9 [slave pointer (2)] ⎜ ↳ ELAN Touchscreen id=10 [slave pointer (2)] ⎜ ↳ SynPS/2 Synaptics TouchPad id=14 [slave pointer (2)] ⎜ ↳ Microsoft Natural® Ergonomic Keyboard 4000 id=15 [slave pointer (2)] ⎣ Virtual core keyboard id=3 [master keyboard (2)] ↳ Virtual core XTEST keyboard id=5 [slave keyboard (3)] ↳ Power Button id=6 [slave keyboard (3)] ↳ Video Bus ...

MythTV transcoding user job

For some reason I was having trouble with existing online MythTV transcoding jobs. Specifically this and MythBrake were nice but after many attempts I couldn't get HandbrakeCLI to output a decent quality video and opted to write my own using ffmpeg . Please be aware this script will automatically cut out commercials even if mythcommflag is inaccurate. To get started copy the script into a file on your mythbackend box. In the example below it is called transcode.sh. Then `chmod +x` and review the contents of the `./transcode.sh -h` help command like so: [richie@localhost mythtv]$ chmod +x transcode.sh [richie@localhost mythtv]$ ./transcode.sh -h Transcodes a video to .mkv auto cutting commercials. User job example: /home/richie/mythtv/transcode.sh -c %CHANID% -s %STARTTIMEUTC% -v show version -h show usage -l limit CPU usage -s [arg] starttime from mythtv. In user job %STARTTIMEUTC% -c [arg] chanid from mythtv. In user job %CHANID% -u [arg] ...

.Net Listing Classes or Methods With A Particular Attribute.

Whenever I build a website I always like to build an admin section and expose information such as which actions are cached, which controllers require authorization and which fields are required etc. Luckily in .Net MVC most of these things are implemented as attributes. Here is an example of scanning an assembly and listing all the classes and methods with a particular attribute on them. I chose two random attributes for this example: [Obsolete] public class Program { public static void Main(string[] args) { var program = new Program(); var types = program.GetAttributesOnClasses (); foreach (var t in types) { Console.WriteLine("Class: {0} - Attribute: {1}", t.Type.Name, t.Attributes); } var methods = program.GetAttributesOnMethods (); foreach (var method in methods) { Console.WriteLine("Method Name: {0} - Attribute: {1}", method.MethodInfo.Name, method.Attributes);...

Why don't more people use the .Net Settings as opposed to Config settings.

I see a lot of people putting key-value pairs in web.config/app.config files and then using them in their applications via var someConfigKey = ConfigurationManager.AppSettings["someConfigKey"]; int count; if (int.TryParse(someConfigKey, out count)) { //// Do Something } However I rarely see people using application settings. I won't go into depth on what application settings are as the Microsoft website has a pretty good explanation of them here however Settings are strongly typed and so the above lines of code can all be replaced with: var count = Properties.Settings.Default.Count; I might be missing something here but it seems like the latter is much more convenient to use if you are simply using the appSettings section of the .config file. Of course it is a different story if you are using .config sections which are serialized into objects but for the most part what I can figure is that many people don't know about .net Settings. Take this or this s...

VB.Net Gotchas

VB.NET is a very user friendly language however I find its user friendliness to be quite confusing and error prone, especially when switching back and forth between C# and VB. Simple things like VB's handling of null or concatenation can lead to bugs if your not careful. For example: Sub Main() Console.WriteLine("The value of Nothing is also the value of the default type: " & (Nothing = False)) Console.WriteLine("The value of Nothing is also the value of the default type: " & (Nothing = 0)) Console.WriteLine("The value of Nothing is also the value of the default type: " & (Nothing = String.Empty)) Console.WriteLine("The & operator with two integers concats both: " & (3 & 4)) Console.WriteLine("The + operator with two integers adds both: " & (3 + 4)) Console.WriteLine(...

.Net Winforms Basic BackgroundWorker Example

I use a BackgroundWorker a lot when working with WinForms in order to perform database or webservice calls without freezing the UI thread. Of course web services can be called using their built in asynchronously methods however when you have a separate data access or model layer, these asynchronous methods are not readily available.  On a new project I was working on, I was looking for a basic example online for quick reference but there wasn't one amongst the top search results so I thought I'd post one. using System.ComponentModel; using System.Threading; using System.Windows.Forms; public partial class MainForm : Form { private readonly BackgroundWorker backgroundWorker = new BackgroundWorker(); public MainForm() { this.InitializeComponent(); this.backgroundWorker.DoWork += this.BackgroundWorkerDoWork; this.backgroundWorker.RunWorkerCompleted += this.BackgroundWorkerCompleted; t...

Easy .NET MVC Active Directory Attribute Based Authorization

Active Directory based authorization in .NET is fairly easy. Just throw an attribute on a controller as follows: [Authorize (Roles="MyAdGroup")] public class SettingsController : Controller Sometimes though you do not want to hard code a role in an attribute as you may want to add or remove roles at will. You may also want to change the roles based on whether you are in production or not. I like to keep my Active Directory roles either in a database or a web.config file so that others can change authorization on the fly. In order to have greater control over your authorization roles you need to extend the AuthorizeAttribute and override AuthorizationCore. You also need to override HandleUnauthorizedRequest in order to have a custom redirect page. /// <summary> /// Redirects to the unauthorized page. /// </summary> public class AuthorizeSiteRedirect : AuthorizeAttribute { /// <summary> /// Authorization based on roles in...