Monday, March 25, 2013

Notepad++ Time-Stamp

Kudos

I’ve been keeping some form of a work journal for years; I’d highly recommend it.  I recently got annoyed with creating timestamps in Notepad++, and ran across a helpful post in a forum.  It was so helpful that I thought I’d do my best to try to give it some additional street cred.

Here is the original link:
http://sourceforge.net/p/notepad-plus/discussion/331753/thread/3458d1da#62f2

What day of the week was 4/22/2006 anyway?

Before I start, if you have the TextFX plugin already setup in Notepad++, it provides 2 static methods of inserting a datetime stamp:
Menu: TextFX > TextFX Insert > I:Date & Time: short format: 3:56 PM 3/22/2013
Menu: TextFX > TextFX Insert > I:Date & Time: long format:  3:56 PM Friday, March 22, 2013
If these look good enough to you, you can skip to the section on how to map a keyboard shortcut to these.  However, in addition to the time and date, I also wanted the day of the week, like this:
03:36 PM 03/22/2013 (Friday)


Steps

It turns out this can easily be done with a simple Python script.  I don’t even know Python that well and I was able to do it.

1. Install the python plugin:
  • The plugin’s name is: Python Script
  • It’s recommend you do this via the NP++ Plugin Manger (Menu: Plugins > Plugin Manger)
  • Here’s a link to the project page:  http://npppythonscript.sourceforge.net/
  • The script includes some basic Python libraries, so you shouldn’t need to install Python or other 3rd party libraries

2. Setup script in Notepad++:
  • Menu:  Plugins > Python Script > New Python Script
  • It will ask you for a new file name, I choose: npp_timedate_stamp.py
  • A new tab will appear in NP++ for you to enter the script.
  • This is the script I used:
    
    # Add date/time stamp in Notepad++ 03:28 PM 03-22-2013 (Friday)
    import time
    editor.addText( time.strftime( '%I:%M %p %m/%d/%Y (%A) ' ) )
    
    
  • Here is a link to the Python documentation which shows what all the format string characters: http://docs.python.org/2/library/time.html
  • Save your script

3. Configure Notepad++ to use the script:
  • Menu: Plugins > Python Script > Configuration
  • You should see your script under the User Scripts section
  • Add it to Toolbar and/or Menu
  • I put it in both, but I only managed to find it under menu
  • It shows up as its own entry under Menu: Plugins > Python Script > npp_timedate_stamp

4. Create a keyboard shortcut (my preferred method):
  • Menu: Settings > Shortcut Mapper
  • Switch to Plugin
  • Scroll down until you see your script name (i.e. npp_timedate_stamp)
  • Click on it, choose Modify, and choose a key.  I used: CTRL + ;

Furthermore

This was exciting to me in more ways than one, because in the past I’ve looked for ways of modifying Notepad++, and plugins can be a daunting undertaking.  Apparently the Python plugin is mapped to all the Notepad++ features, so I might utilize it more in the future.

Friday, March 22, 2013

Future Phone, 7 plus or minus 2

I had this thought swirling around my head this morning that wouldn't go away.  What I usually do in such cases is write down enough to be satisfied and then continue on with whatever I was doing.  However, today involved building an image, so after quickly sketching it up in gimp I figured I might as well post it somewhere.

I was thinking about how we make phone calls. 
  1. Originally we called an operator and asked to be connected to a house address (i.e. using words)
  2. We switched to a 7 digit number
  3. There were so many phone numbers we had to add the area code every time you dialed, so it became a 10 digit number
  4. (I'm ignoring countries outside the US, sorry but you guys have a ton of numbers to dial)
  5. With the phone Address book it seems we're almost back to the original model of connecting using words
 * There shall be no implications what-so-ever that I know anything about the history of telecommunications from this list, although I did take a very interesting telecom class in college.

This got me to thinking: how else could we make calls other than using the number method?

The address book has pretty much eliminated the need for memorizing a phone number, although you could think of that number as being a good unique key into the world "database" of phones.

That's it.  Thanks for the ear internet.

Built this fairly quickly in gimp, I'm not sure why everyone complains about it being too confusing to use.









Thursday, March 21, 2013

Entry-Level Android Application

I've been taking a series of classes on Android development in my spare time via UW.  The final project for my 1st class was to build a simple 2-screen application and present it in front of the class.

Lucky for me the presentation was recorded.  Un-lucky for me it was recorded using Adobe Connect, which makes downloading and editing the video extremely annoying.  I figured a way around all the hurdles and you can watch the video below.  I've also posted the slides below with some notes.



Some quick notes:
  • Originally I was going to made a tip calculator, but was talked into this idea instead
  • The idea for this app came from an idea I had for a Greasemonkey script

The slides from the presentation:



Slide 1
  • The presentation was meant to be mostly verbal with just a few points made on the slides themselves.  However, I did modify a couple for this blog post.



Slide 2
  • A simple feature allows me to explore the entire end-to-end process



Slide 3
  • The first example is simple to allow the audience to quickly follow the gist of the calculation
  • The second example shows how the result can be useful: with a 5 month wait, I can plan to read something else while I'm waiting



Slide 4
  • The better looking app usually wins
  • I found this image of an old-style library checkout card to use as a guide (my apologies if this is your image)




Slide 5
  • For the actual presentation, I switched to using a separate overhead projector that displayed my phone on the wall.  I just inserted a screenshot for this version.



Slide 6
  • Process button wasn't needed, but works as a visual cue to the user
  • I used View elements in the XML layout, with a height/width of 1dip to make the lines
  • I repeated those lines at the bottom to complete the look I was trying to achieve
  • If I had to do this again, I would calculate the device's resolution and repeat those lines as many times as I needed.  It didn't matter for this project.




Slide 7
  • Changing Preferences wasn't supposed to overwrite the current values the user had entered, but upon testing this just confused the user.  I had to change it to just have the preferences always over-write the current values.
  • I originally had the result displayed in a TextView (read only), but decided to change it to a EditView so the user could select and copy the result
  • The font and background with smudges made a HUGE difference. Smudges were just in the background image I created in GIMP, the aspect ratio didn't matter.
  • I don't think anyone noticed, but I used that same background image in the app for this slide. I wanted to show that the image could be re-sized to fit just about anything and still look realistic.




Slide 8
  • If you didn't watch the video, the audience had a couple questions and comments about how I did a couple things
  • The comment that I remember most was when someone commented on the background image - he said at first he thought the screen on my phone was dirty! 

Thursday, March 14, 2013

Student Protests



When I was in the 5th grade, our students had a walk-out protest.  I can’t remember what the issue was, but I did know one thing – we weren’t the ones protesting. 

Sure the teachers told us we were protesting, and so did the news reporters, but it wasn’t the truth.  It was obvious we were just pawns for the teachers who were using us to make news about some school issue.  I don’t remember what it was all about, but I sure remember the feeling of how fake the entire situation felt.

When I was in high school, our school decided that my generation didn’t respect our elders, and decided to make changes to our dress code to reflect it.  Therefore we would no longer be allowed to wear baseball caps in class.

I didn’t care too much about it because I never wear baseball caps, they just don’t work well for me. There were even a few always-capped kids in school that I felt shouldn’t wear hats, because they had awesome hair.  So in some ways you could say I was in favor of the change.

As word got around school, the students who wore hats started talking about organizing a walk-out protest.  The rumors built up to the point where we actually had a date and time, and everyone knew about it, including the teachers.  Like I stated earlier, I really didn’t care about the hat rule, but I did feel it was silly – who cared if someone wore a hat in school?  I was planning on joining the protest.

The day before the protest there was an announcement on the intercom from the dean stating that anyone who walked out of school would be suspended.  This really angered me, because walking out would probably not change the rule, but the students could at least send a message that we felt the entire thing was stupid.  I even felt that if everyone walked out anyway they would probably not suspend the entire school.

The day of the protest came, and soon enough so did the time.  I remember it like it was yesterday.  I was in accounting.  The clock struck, the room was silent, and I felt an incredible urge to stand up and walk out of the room: but I didn’t – and no one else did either.  I remember peering into the hallway and it was completely empty - you could hear a pin drop.  Just then my teacher spoke up and said it looked like no one was stupid enough to go on any silly walk out.  This angered me even further, enough for me to review my school schedule in my head for the next week, but I still stayed in my seat and did nothing. 

As I sat there, the protest from 5th grade popped into my head.  I remembered being told how it was such a learning experience for us, and now that all felt like hogwash.  I have never forgotten that day in class, and even though I had no reason what-so-ever to walk out of that class room (I never wore a hat, I wasn’t popular, I’d just be laughed at), I still regret not doing so to this day.

This is why I have a hard time believing student protests.  True protests are supposed to be about people standing up for the things they believe in, and pointing out to the rule makers how silly they are acting.  It’s supposed to be a reality check that stands against black-and-white policies that fail the big picture test. 

It’s kind of sad to say, but I feel that the medium has been abused so much that I don’t believe people are serious unless there are consequences they are facing for having their say.

Monday, March 4, 2013

The Importance of Excel (commentary)



http://baselinescenario.com/2013/02/09/the-importance-of-excel/

This article is a nice summary of the advantages and pitfalls of Excel by James Kwak.  It focuses on the financial world, but the lessons could apply anywhere.  It’s not going to solve any problems, but it’s still a good reminder of things to look out for when using a tool like Microsoft Excel.  This article is part of my recent idea to save short articles for later when I have some quiet time.

I have to admit I use a spreadsheet all the time for various debugging needs.  I can store some calculated data, summaries, grouping, etc.  I recently used it to prototype a simple algorithm I needed to build an Android app.  It turned out that my original "this is perfect" algorithm fell flat on its face when I decided to piece it together in Excel and ran a bunch of numbers through it (Fill-Down is SO powerful).  I'm glad I decided to try it out there before discovering there was a problem after building the app itself.

I've also seen the dark side of using a spreadsheet for important work.  The article mentions it and I have to agree, I think every SAP project I've ever been on has some component of it dedicated to getting data out of SAP and into a spreadsheet. 

One SAP project I was on I had to create a long list of macros in Excel (VBA: Visual Basic for Applications) to achieve a task.  As I propped up more parts of the application, the more I had to rework the functionality into easy to digest functions with tons of in-line documentation.  You can find lots of articles stating your code should document itself without lots of comments, but I assure you when you are a consultant on a project who is going to hand an application to someone not as technically skillful, your only hope is that they will ramp-up slowly by reading your over-documented functions.

Anyway, my write-up is almost as long as the article itself!  If I were to say anything constructive, and really I'm nitpicking, but I feel he takes unnecessary stabs at Microsoft software as if trying to appease some underground software zealots.

http://baselinescenario.com/2013/02/09/the-importance-of-excel/



Sunday, March 3, 2013

SSRS Report - Last Modified ...

Sometimes you know all the pieces and never think to use them together in a different way.

I've always wanted to add some sort of easy version number/system to my SQL Server Reporting Services (SSRS) 2005 reports.  I thought it would be a nice thing to have for users, especially ones that get well-acquainted with a certain report and want to know if you've published a change they requested.

The solution I came up with isn't perfect, and it suffers from some of the same reasons I resisted rolling our own solution.  Perhaps it will be better addressed in future versions. 

I always knew SSRS keeps a lot of data about the reports in a ReportServer database. Heck, I even wrote my own custom report server as a project for a past ASP.Net class, and used the ReportServer as a guide.  What never occurred to me was that I could use that meta-data on the ReportServer database for the reports themselves.

On a SQL 2005 box with SSRS, there is database called [ReportServer] that contains all kinds of meta information about the server and reports  A table called ReportServer.dbo.Catalog contains a column named "Modifieddate".  Instead of a version number, I can write a query to show the last time the report was modified (i.e. deployed).

First and foremost, your users need to have read access to the ReportServer database.  If they do not, you can't do this because your users will not be authorized.

In the report:
Setup new Dataset:
Name: dsReportInternals
SQL:
SELECT
top 1
[name],
[Path],
Max(Modifieddate) as [Modifieddate]

FROM
ReportServer.dbo.Catalog

WHERE
[Name]=@ReportName
and [Type]=2

GROUP BY
[name],
[Path]
;

If you might have the same report in two different locations on the server, you will want to use the Path column as your guide, add something like this in your WHERE clause:
[Path] = @ReportPath +'/'+ @ReportName

To avoid having too many report parameters, I setup this parameter inside the dataset:
@ReportName =Globals!ReportName

For the report parameters, I setup a new parameter like this:
Name: Global_LastModifiedDate
Internal: true
Available Values: Non-queried (i.e. nothing set)
Default Values:
From query = true
Dataset = dsReportInternals (from above)
Value field: ModifiedDate

Hopefully this will be helpful to someone.  It still has the issue that it's not a dead simple thing to setup for each report, but it's better than nothing.