teleren/devto huggingface dataset:
DBUS for cross-machine screensaver locking
Published: 2017-10-31 19:52:01

---
title: "DBUS for cross-machine screensaver locking"
published: true
tags: 
canonical_url: https://michael.mior.ca/blog/dbus-screensaver-lock/
---

I typically work with two computers on a regular basis. When I bring my laptop into the office, that makes three. I have a habit of locking my computer(s) when I step out, but it gets to be a pain when I have three machines running at once. I decided that I wanted to be able to lock one machine, and have the rest follow suit. I discovered that this is possible using DBUS since gnome-screensaver emits a signal whenever locking status is changed. I turned to my trusty Python, and started hacking away.

Without further ado, here is the code:

```
#!/usr/bin/python

import dbus
from dbus.mainloop.glib import DBusGMainLoop
import gobject
import os

# Hosts which should be locked/unlocked
hosts = ['starks', 'mmior-laptop']
# Set to True to turn on displays of other
# hosts after unlocking
wake = False

def toggle_lock(x):
  if x == 0:
    for host in hosts:
      os.system('ssh ' + host + ' export DISPLAY=:0; gnome-screensaver-command -d')
      if wake:
        os.system('ssh ' + host + ' export DISPLAY=:0; xset dpms force on; gnome-screensaver-command -d')
  if x == 1:
    os.system('xset s activate')
    for host in hosts:
      os.system('ssh ' + host + ' export DISPLAY=:0; xset dpms force off; gnome-screensaver-command -l')

DBusGMainLoop(set_as_default=True)

# Connect to the session bus and
# install our signal handler
bus = dbus.SessionBus()
bus.add_signal_receiver(toggle_lock,
  'ActiveChanged',
  'org.gnome.ScreenSaver',
  path='/org/gnome/ScreenSaver')

# Start the loop and wait for the signal
gobject.MainLoop().run()

# Clean up by removing the signal handler
bus.remove_signal_receiver(toggle_lock,
  'ActiveChanged',
  'org.gnome.ScreenSaver',
  path='/org/gnome/ScreenSaver')
```

This needs to be run as a daemon in the background to watch for the signal. To use the script, just replace the hosts array with a list of hostnames you wish to lock/unlock. The wake variable controls whether or not the screens of the other machines should be turned on when unlocked. Of course you can add any actions you wish to take on lock/unlock.

For more information, check out the [Python DBUS tutorial](http://dbus.freedesktop.org/doc/dbus-python/doc/tutorial.html) or see how to use [`dbus-monitor`](http://linux.die.net/man/1/dbus-monitor) to watch for any signals going over the bus.

If you want to poke around and see what DBUS interfaces various programs you have installed, check out the Debian package `qt4-dev-tools`. It may be a little big since it requires installing lots of Qt libraries, but the included `qdbusviewer` tool is great for browsing signals and testing out message sending.

If you run into any problems or come up with a cool use case, let me know in the comments!
Detect printing with CSS & ASP.NET
Tags: aspnetwebforms, printing
Published: 2010-09-24 22:42:00

---
cover_image: https://dev-to-uploads.s3.amazonaws.com/i/y9hxcwi5y92j6zfcxbjx.jpg
title: Detect printing with CSS & ASP.NET
slug: detect-printing-with-css-asp-net
date: 2010-09-24 22:42
tags: 
 - asp-net-webforms
 - printing
---
So, as in my previous post, I had an awesome idea of how to detect people printing a page of a website. Basically, when they go to print from our site, they get a different layout, that doesn't have anything that looks like a site. So surely if I just put a little tracker file in between the CSS file and the request, that'd work like a charm, right?

Wrong. In order to protect peoples privacy, all css files are now downloaded at page load, so every view registered as a print. Naturally, I checked what the bearded men of Google had to say, which wasn't much. HTC files, printer drivers and one even suggested something about an intranet... 

So I posted on Dream.In.Code, asked the masses, and even RDC'd into my server to ask in #css on freenode irc.. then my own question gave me the answer.

To detect when someone prints a page on your site you just use CSS, it's really simple actually. Think, they will load the CSS when the page loads, but they won't process it unless someone prints, and you can use css to request images.. but .. how does CSS know if an image is an image or if it is a microwave meal? It doesn't until it requests it!

Don't forget to reference your stylesheet!

    <link rel="stylesheet" href="print.css" media="print" type="text/css" />

So you just put your script inside an url()!!

    body { background: url(PrintTracker.aspx); }

Works brilliantly, and the 'image' is requested every single time a page is printed, even the same one twice!

Awesome? I agree.

**Update:** It has been noted that print preview will fire this also. Bear that in mind.
Dynamic CSS with ASP.NET - in one line of code
Tags: csharp, aspnetwebforms
Published: 2010-09-24 22:41:00

---
cover_image: https://dev-to-uploads.s3.amazonaws.com/i/y9hxcwi5y92j6zfcxbjx.jpg
title: Dynamic CSS with ASP.NET - in one line of code
slug: dynamic-css-with-asp-net-in-one-line-of-code
date: 2010-09-24 22:41
tags:
 - csharp
 - asp-net-webforms
---
Whether you want a separate sheet for each browser, or you want to track when people print a page from your site (as is my case), how do you get code to run in a CSS file? You can't. How do you get an ASPX file to serve up CSS? Well, you can't. But like House MD, I have the answer and I'll tell you eventually.

What you want to do is create an ASPX file, and in the Page_Load event, write whatever tracking or logic code you want, then simply redirect the page without any output.

    protected void Page_Load(object sender, EventArgs e)
    {
        // code here
        Response.Redirect("style.css", true);
    }

And there you have it, Dynamic CSS with ASP.NET - in one line of code.
Simple abstract classes explained
Tags: abstract, abstractclass, csharp
Published: 2010-09-21 22:39:00

---
cover_image: https://dev-to-uploads.s3.amazonaws.com/i/y9hxcwi5y92j6zfcxbjx.jpg
title: Simple abstract classes explained
slug: simple-abstract-classes-explained
date: 2010-09-21 22:39
tags:
 - abstract
 - abstract-class
 - csharp
---
Blogular activity has suffered a little here; but setting up a workshop and devising plans to build steam engine in said workshop will do that to you. Today some simple code, written to simplify showing abstract classes. Every tutorial I see they throw in stupid code that isn't really needed to show the primal functionality of abstract classes. So here is an example that has nothing more than what it needs.

    class Program
    {
        static void Main()
        {
            // here we create a happy and pass it to print mood to screen
            // happy is of type happy but also of type mood
            Happy happy = new Happy();
            PrintMoodToScreen(happy);

            // again, we create a mood, this one is a sad mood but still
            // a mood nonetheless
            Sad sad = new Sad();
            PrintMoodToScreen(sad);

            Console.ReadKey();
        }

        // here we take an object of the type Mood, which means we don't require
        // one method for sad, one method for happy and one for all others
        // and it means we dont have to box them into objects either
        static void PrintMoodToScreen(Mood mood)
        {
            mood.PrintMood();
        }
    }

As you can see we pass the objects to a single method taking a Mood type, not Sad or Happy. Think about your local vets, you may have a GermanShepherd or a Poodle, but they are all derived from the Dog class. If that isn't enough, think about coffee, beautiful coffee, we have Coffee, then we have InstantCoffee and GroundCoffee, and then we have KenkoInstantCoffee and NescafeInstantCoffee, each would be a child of the other, Coffee -> InstantCoffee -> KenkoInstantCoffee etc. You could write a method to only accept instant coffee and then takes water and milk and makes a nice quick 'normal' brew.

    abstract class Mood
    {
        // protected means it's accessible to Mood, and to anything derived
        // from it, i.e. sad, happy, etc
        protected string CurrentMood { get; set; }

        // here we write a method to print the mood, we only need to code
        // it once, that's one reason why abstract classes exist
        public void PrintMood()
        {
            Console.WriteLine(CurrentMood);
        }
    }

    // we create the happy class and derive from mood
    class Happy : Mood
    {
        public Happy()
        {
            // we set the protected property, which is accessible to us
            // but not to anyone using a mood object
            CurrentMood = "Current Mood is Happy :)";
        }
    }

    class Sad : Mood
    {
        public Sad()
        {
            // cheer up Sad class!
            CurrentMood = "Current Mood is Sad :(";
        }
    }

If more explaining is needed, then I'm really not sure if there's any hope for you.

Good luck!
People are dumb (like me)... A person is smart (like me).
Tags: development, problemsolving, testing, troubleshooting
Published: 2018-09-18 02:44:32

---
title: People are dumb (like me)... A person is smart (like me).
published: true
tags: Development,Problem Solving,Testing,Troubleshooting
canonical_url: https://www.briannipper.com/2010/09/people-are-dumb-like-me-person-is-smart.html
---

[![](http://upload.wikimedia.org/wikipedia/en/f/fb/Men_in_Black_Poster.jpg)](http://upload.wikimedia.org/wikipedia/en/f/fb/Men_in_Black_Poster.jpg)In the 1997 summer blockbuster "Men in Black" the two main characters, played by Will Smith and Tommy Lee Jones, discussed the capabilities of groups of people and individuals.  
  
Will Smith's character suggested that it would be safe to tell the entire earth about Aliens, saying "people are smart..." they can handle it. Tommy Lee's character responds "a person is smart, people are dumb..." which implies that while a person is capable, but as a whole people are not.  
  
In general I tend to disagree with the idea that the majority of people are dumb, stupid or some other negative quality. I strongly believe that the vast majority of people are very capable and given the right circumstance they are able to surprise, delight and in general exceed most expectations. However, keeping in mind that the "squeaky wheel gets the oil" or in other words the most vocal people get the attention, it seems for some reason that the most vocal people also tend to be the "less" capable.  
  
I've noticed in my day job that often, with respect to software development, users who complain/list issues the most are often the lest capable of diagnosing an actual problem versus "user error" (a.ka. "it's their own fault).  
  
In my mind it would be simple to resolve this issue if I could simple get all users to learn the one principle that I always turn to when troubleshooting problems. "It's my fault" (meaning I probably caused this issue myself and not some other person/thing).  
  
Often when resolving problems in my software I first assume that it's something I did. Unfortunately, depending on how you look at it, I'm typically correct. I might fat finger an entry, produce an off-by-one error, or some other trivial mistake. Because this seems to be the case so often with developers they have devised a brilliant process to resolve these issues, it's called TESTING. This amazing, revolutionary and ground breaking process helps to eliminate most bugs/issues. So when a user (of an already TESTED system) reports a bug, most troubleshooting begins with attempting to recreate the issue reported, when this can't be accomplished it can indicate that the user who reported the bug/issue did something "different" than expected. While this could be considered an edge case (a topic for a different post) most often it comes down to basic user error.  
  
If only all users could be taught how first think "it's my fault" but then, people are dumb.
K.I.S.S.
Published: 2018-09-18 02:44:16

---
title: K.I.S.S.
published: true
tags: 
canonical_url: https://www.briannipper.com/2010/09/kiss.html
---

[![](http://upload.wikimedia.org/wikipedia/commons/e/e8/Crystal_Clear_app_kedit.svg)](http://upload.wikimedia.org/wikipedia/commons/e/e8/Crystal_Clear_app_kedit.svg)One principle in development that can NEVER be stated enough is "Keep It Stupid Simple" (or Keep It Simple Stupid or Keep It Super Simple). In any case, this development principle can be used in many aspects of life, but obviously it can be used when working with every day computer tasks.
  

One task that most people perform is keeping notes about various "things". Sometimes when people start to get lots of notes they think they should try and get some fancy program or a spreadsheet or even specialized software for keeping track of all these notes.

  

However, I've found that the simplest solution is still the best, Notepad.

  

Notepad has been around since the days of Windows 3.x and I'm sure that even in the DOS days people would keep notes using EDIT (a dos command to edit a file). Even as I being moving more and more of my electronic tasks onto my smartphone I've found that the simple "notepad" like app that came with my phone has become extremely valuable.

  

Some might say that notepad lacks features; however, the "lack of features" ensures that you stay on task. Instead of spending a lot of time formatting and inserting clip art you have to capture the important information with... TEXT.

  

At first a simple text app might seem "too simple" but with a few tips and ticks you can capture and convey a lot with these simple little notes.

  

A few tips I've found helpful:

- A healthy amount of white space will ensure that various sections stand apart.

- You can use any NONE alpha numeric character to indicate bullet/lists.

- You can "underline" with the use of the underscore.

 (i.e. this is a title)

        ------------

- You can "double underline" with the use of the equal sign.

 (i.e. this is important)

        ============

- You can use a tab space to create a point, sub-point.

 Main Point One

Sub-Point One

Sub-Point Two

 Main Point Two

Sub-Point One

  

After you start to use simple text notes, you'll also enjoy the fact that almost without exception they are transferable to almost any device with a modern OS, including many smart phones.

  

So as I've learned, KISS as much as possible.
Get Average using SQL
Tags: sql
Published: 2010-09-15 22:38:00

---
cover_image: https://dev-to-uploads.s3.amazonaws.com/i/y9hxcwi5y92j6zfcxbjx.jpg
title: Get Average using SQL
slug: get-average-using-sql
date: 2010-09-15 22:38
tags: 
 - sql
---
More SQL again today, to say I'm not a fan, I'm doing a lot of it lately.

Todays snippet is quite cool, I was inspired by this post:
http://www.dreamincode.net/forums/topic/190437-floating-point-division/

Basically, you return the average by counting up the price of every item in a table, then divide it by the number of rows in said table. All in SQL.

    SELECT (SELECT SUM(Price) FROM t_Items) /
        (SELECT COUNT(*) FROM t_Items)
            AS Expr1

Enjoy!
Sql threesomes.. Two foreign keys, one primary key
Tags: sql
Published: 2010-09-12 22:37:00

---
cover_image: https://dev-to-uploads.s3.amazonaws.com/i/y9hxcwi5y92j6zfcxbjx.jpg
title: Sql threesomes.. Two foreign keys, one primary key
slug: sql-threesomes-two-foreign-keys-one-primary-key
date: 2010-09-12 22:37
tags: 
 - sql
---
So here I am, coding my own business, being a law abiding coder, when out of the blue comes a rather bothersome little problem which really did one on me. I had laid out an awesome plan for my awesome top secret project, a truly awesomely smart database design with relationships to link a rows in a table to rows in the exact same table, one way relationships from A->B. All I needed was a way to cascade them on delete, in other words, make sure when a row is deleted, every relationship (in the relationship table) is deleted along with it.

Are things ever that simple? MSSQL decided to tell me that because one field had a foreign key (FK) to the primary key (PK), the other field couldn't also have an FK to the PK, and that's not okay (OK). That's !OK .. 

Luckily, SQL has things called triggers, and they're actually pretty useful. The below SQL creates a trigger that deletes any rows from the second table, that have the same id as the row being deleted from the first table:

    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    -- ==============================================
    -- Author: Adam K Dean
    -- Website: http://imdsm.blogspot.com/
    -- Create date: 12/09/10
    -- Description: Deletes relationships on deletion
    -- of row in the main database. Replaces the need
    -- for two foreign keys on the same primary key
    -- which is unfortunately impossible.
    -- ==============================================
    ALTER TRIGGER DeleteRelationships ON t_Sites AFTER DELETE
    AS
    BEGIN
      
     DELETE FROM t_Relationships 
     WHERE ReferrerId IN (SELECT Id FROM Deleted)
      OR TargetId IN (SELECT Id FROM Deleted)
     
    END
    GO

Somehow I managed to make this work, finding snippets and testing them, because lets face it, the SQL examples have so many options it's like a wall of text has just hit you at 150 pages per second, not really as easy to use as looking at some chinese hackers code and picking out the bits you need.

It seems the `Deleted` object refers to the deleted row, and well the rest is pretty simple.

Hope this helps you, or future me, if you're suffering the same Jeremy SQ-yle problems as I was!
The "Really Big" problem
Tags: bigpicture, businesssolutions, criticalthinking, problemsolving
Published: 2018-09-18 02:42:46

---
title: The "Really Big" problem
published: true
tags: Big Picture,Business Solutions,Critical Thinking,Problem Solving
canonical_url: https://www.briannipper.com/2010/09/really-big-problem.html
---

  

I had the opportunity to attend a meeting wherein the presenter discussed all of the amazing ways that SharePoint 2010 was going to solve all the problems of the company I work for.
  

I work at a company that is made up of 1,000s of employees across most of the globe, and as I listed to how facet search and managed metadata where going to resolve communication and collaboration problems I begin asking myself what is the underlying problem that plagues the company I work at and how is SharePoint going to resolve this problem.

  

Thinking of how most problems boil down to communication issues I realized that while the company I work at (a middle of the road financial institution) is not the "biggest" company by any means it does the the "big" problem, that is, the company is made up of a lot of people.

  

When ever you have an organization, be it government, company or even a family, as the organization grows the issues it faces in keeping everyone in the group "on the same page" also grows.

  

This can actually be expressed mathematically _(n<sup>2</sup>-n)/2_. This equation, which I discovered from Joel Spolsky's article in _Inc. Magazine_ ([http://www.inc.com/magazine/20100201/a-little-less-conversation.html](http://www.inc.com/magazine/20100201/a-little-less-conversation.html)) shows how every time you add another person to a group it becomes harder to keep the entire group on the same page. The table below (also borrowed from the _Inc. Magazine_ article) helps to illustrate this very well.

  

| People | Connections |
| --- | --- |
| 1 | 0 |
| 2 | 1 |
| 3 | 3 |
| 4 | 6 |
| 5 | 10 |
| 6 | 15 |
| 7 | 21 |
| 8 | 28 |
| 9 | 36 |
| 10 | 45 |

  

As it shows once you get to around 5 people the issue of keeping everyone up to speed get's very complicated. You might be inclined to think that if only one person makes any decisions that this helps limit the issue; however, would you want to work at a place where out of 5 people only 1 person has any real input? I know I wouldn't part of the reason to work in a group is so you can benefit from other people's ideas.

  

So how does SharePoint 2010 plan on solving this issue? Well it doesn't SharePoint 2010 is a tool just like any other tool and will only be as useful as the craftsmen who use it.

  

Hopefully as the rollout of SharePoint 2010 continues the "really big" problem will be on more people's mind and a focus on it will grow and less emphasis will be placed on the tools used to resolve it.
Remove annoying beep from pressing enter in textbox
Tags: csharp, winforms
Published: 2010-08-31 22:29:00

---
cover_image: https://dev-to-uploads.s3.amazonaws.com/i/y9hxcwi5y92j6zfcxbjx.jpg
title: Remove annoying beep from pressing enter in textbox
slug: remove-annoying-beep-from-pressing-enter-in-textbox
date: 2010-08-31 22:29
tags:
 - csharp
 - winforms
---
Continuing with useful snippets and methods, today I present you mighty readers with a very useful
and simple way to get rid of the annoying sound from pressing enter in a textbox. We've all had it, trying to make enter take us from the username, to the password, and then to the submit button.. but that sound.. must..claw..eyes..out... or ears.. but anyway, it's really easy, read and learn:

    private void txtInput_KeyUp(object sender, KeyEventArgs e)
    {
        if (e.KeyCode == Keys.Enter)
        {
            e.SuppressKeyPress = true;
        }
    }

    private void txtInput_KeyPress(object sender, KeyPressEventArgs e)
    {
        if (e.KeyChar == (char)Keys.Enter)
        {
            // any logic would go here
            e.Handled = true;
        }
    }

And there you have it. Very easy, very simple and very very useful.

Now for me, back to work, a friend of mine Mihn was talking to me about refactoring yesterday, little did he know he'd plant seeds that would grow into enormous fruitition* when I'd overhaul the whole administrator area of the new site at work and change it from web based to a desktop application.. damn you Mihner, damn you!

\* I hearby declare fruitition a real word.
Readable File Sizes
Tags: csharp
Published: 2010-08-29 22:28:00

---
cover_image: https://dev-to-uploads.s3.amazonaws.com/i/y9hxcwi5y92j6zfcxbjx.jpg
title: Readable File Sizes
slug: readable-file-sizes
date: 2010-08-29 22:28
tags:
 - csharp
---
In an effort to fill up this blog with code, I will over the next few weeks be looking back over my snippets, finding useful methods and posting them. Today's feature is a simple text formatter, which converts a long (representing bytes) into a string, giving you a nice readable file size.

So without further ado:

    private static string GetReadableBytes(long lSize)
    {
        double size = lSize;
        if (size >= 1024 && size < 1048576)
            return string.Format("{0:#,0.00} KB", (size / 1024));

        else if (size >= 1048576 && size < 1073741824)
            return string.Format("{0:#,0.00} MB", (size / 1048576));

        else if (size >= 1073741824 && size < 1099511627776)
            return string.Format("{0:#,0.00} GB", (size / 1073741824));

        else if (size >= 1099511627776)
            return string.Format("{0:#,0.00} TB", (size / 1099511627776));

        else return string.Format("{0} B", size);
    }

And here you can see the output.

    /* Bytes                    Readable Size
     * =====                    =============
     * 436                  ->  436 B
     * 2159                 ->  2.11 KB
     * 36236                ->  35.39 KB
     * 2362893              ->  2.25 MB
     * 276227272            ->  263.43 MB
     * 62367298764          ->  58.08 GB
     * 3623647473473        ->  3.30 TB
     * 352635208736296      ->  320.72 TB
     * 236363536873629626   ->  214,971.38 TB
     **/

Enjoy!