Showing posts with label code. Show all posts
Showing posts with label code. Show all posts

Saturday, October 31, 2015

Microsoft Channel9 Addon for Kodi

To add to the my list of hobby projects, I created a fork of an addon for Kodi that provides browsing of videos on Microsoft Channel9. This was my first attempt at a Kodi addon, and really my first time working with writing python. I started out by just reading over the original code and tweaking it a bit because some things were not working. Then I started following the pattern that existed and implementing new features, like being able to browse Channel9 authors, and Channel9 events.

Once I got these features in place, I started doing some real refactoring of the original code base. There was a ton of code that was duplicated in multiple places. I spent a few hours of the day really rewriting the entire addon. As the project stands right now, it is basically a complete rewrite of the original addon.

The project is on Github and building on AppVeyor.

Download the latest Release

Monday, March 2, 2015

Amazon Echo Api

As I posted in my previous post, I recently bought an Amazon Echo. I saw some videos of people using their Echo to do home automation with a Raspberry Pi or Adriano. They did this by using something like Node, or python to monitor the tasks that are added to the Echo. To do the monitoring, they used the undocumented, unsupported, Api of the Echo.

I wanted to play around too. While I really don’t do anything related to home automation, I still wanted to explore the Echo Api and see if I could implement some type of wrapper for it in C#.

Here is what I found with the undocumented Api:

  • The desktop app connects to a WebSocket on the Echo device. I have not yet successfully connected to the socket, nor have I tried yet.
  • There is a url to get the latest “cards” - /api/cards?limit=N
  • Get the tasks - /api/todos?type=TASK
  • Get the shopping list - /api/todos?type=SHOPPING_ITEM
  • Get registered devices - /api/device
  • Get the media state for a device - /api/media/state?deviceSerialNumber={0}&deviceType={1}
  • Get the connected bluetooth devices - /api/bluetooth
  • Get music accounts - /api/music-account-details
  • logout - /logout
  • Get the capabilities of each provider - /api/media/provider-contenttype-capabilities

I also found that I should be able to send commands to Play, Stop, Next Track, Previous Track, Shuffle, Repeat, and set the Volume. The web app does this by first doing an HTTP/OPTIONS request, followed by an HTTP/POST. The post contains a JSON payload that contains the meta data of the device and what the volume is (if setting the volume). I have been unable to successfully POST these commands as there should be a CSRF token sent along with the POST. This token should be available in the cookies, but for some reason that I have not figured out yet, the token does not exist in the CookieContainer.

Currently, I have a working wrapper Api to Login, Logout, Get Tasks (TODO or SHOPPING), and update a task. I have posted my code on GitHub and I will push changes when I make them. This is just a little toy project that I decided to play with when bored. I will continue to work on it in free time, while I am interested in it. Feel free to fork it.

Amazon Echo Api

Happy Hacking of your Echo

Sunday, March 1, 2015

Amazon Echo Material Design Stylish Theme

echoI bought an Amazon Echo last week. I was looking for a Bluetooth speaker and for $100 (for Prime Members), it is a decent Bluetooth speaker, plus it integrates with Prime music, and other Amazon services. It allows you to purchase items from Amazon directly from the Echo. It also has other features like TuneIn radio, iHeartRadio, a timer, an alarm (seems like it should support more than one timer and alarm, hopefully they will add this functionality in the future), todo list, and a shopping list.

The Echo has a companion app for iOS and Android devices, and it has a web app for your desktop. I was playing around with the CSS the other day while I was off work and decided to re-theme all (or most) of the desktop app using Stylish (Chrome|Firefox).

 

Download Amazon Echo Material Theme

 

 

 

 

Here are screenshots of just about every page within the Echo desktop app. Some are pretty boring, but they do show some of the elements that have been changed on the page.

1 

2

3

4

5

6

7

8

9

10

Friday, April 4, 2014

Powershell Script to download //BUILD/ 2014 sessions

Here is a powershell script that downloads all the mp4 video sessions available on Channel9. It first pulls all the HD videos, then checks the normal quality videos. It names the videos based on the session title. It will only download the video if it does not exist in the destination directory.


Update: Blogger doesn't want to show my GIST, so here is a direct link to it.

Sunday, August 11, 2013

New open source tool: Fyles

Fyles is a tool that will gather all the icons for all the file types that are on a system. It then generates a sprite sheet and css for all of those extensions. Fyles only references unique icons, so if there are file types that share the same icon, it will only be in the sprite once. The exception to this is the “default” icon, to ensure that the default icon exists in the sprite, it may exist more than once.

Here is a sample of how the sprite is laid out:

fyles-sample

And here is a small block of what the css looks like:

And here is how you would include an icon on your page:

Saturday, December 31, 2011

Html5 Unobtrusive Form Validation for ASP.NET MVC

I have a project that I was able to make use of modern browsers HTML5 form validation. But I wanted to include the validation that also takes place from within aspnet mvc so there is a unified experience with the validating the form. I took the jquery.unobtrusive-validation.js and made some modifications to it to hook in to the aspnet mvc validation. It is not yet 100%, the “Required” aspnet mvc validation doesn’t seem to “trigger” unless the field is filled out, then attempted to be submitted, and then cleared again, but the default html5 “required” validation message still shows initially. Either way, I figured I would share this and maybe someone could build on it and improve it. Enjoy.

Here are some screenshots of the results.

Failed Regex Validation
image 

Failed Minimum String Length Validation
image 

Failed Remote Password Strength Validation
image

Failed Compare to Password Field Validation
image


Download from Skydrive

Tuesday, November 15, 2011

Eclipse Color Theme

To go along with the other themes that I have posted here in the past based on Coding Instinct, here is a Coding Instinct theme for Eclipse Color Theme. The site also has a download in EPF format (Eclipse Preferences).

java-codinginstinct

Eclipse Color Theme (XML) – for Eclipse Color Theme Plugin
Eclipse Preferences (EPF) – for Eclipse Import

Monday, January 10, 2011

Check if the user is running AdBlock

A lot of applications on the android market use admob, or some other advertising method to keep the application free but still be able to generate some revenue. The ads are good for both the developer and the user. It generates revenue for the developer, and gives the user relevant advertising.

There is an application, which was recently pulled off the android market, called AdBlock that blocks these advertisers from displaying ads. This application can be a thorn in the side of the developers, as it is hindering income that the developer could be receiving.

Now you could probably argue that these people that run AdBlock wouldn’t click on the ads any how, and for the most part, that is probably true. But at the same time, a lot of applications on the market offer a license key or some other way to remove the ads from the application buy paying the developer a small fee. If the user is running AdBlock, they are circumventing this licensing model and in a way, stealing the application.

One of the great things about android is the ability to launch other intents. And by having this ability, we can check if the user has AdBlock installed. If they have it installed, we can then render the application useless until they remove AdBlock, or purchase the license.

This code block below will check if the user is running AdBlock, if they are, it will display an alert dialog and launch the market to purchase a license, or they can close the application.

private static void performCheck ( final Activity activity ) {
PackageManager pm
= activity.getPackageManager ();
Intent intent
= pm.getLaunchIntentForPackage ( "de.ub0r.android.adBlock" );
if ( Reflection.isPackageInstalled ( activity, intent ) ) {
new AlertDialog.Builder ( activity )
.setTitle (
"License Required" )
.setMessage (
"Since you are running software to "
+ "block the ads that keep this software free, you must purchase a "
+ "license to use this software from "
+ "the android market." )
.setPositiveButton ( android.R.
string.ok, new DialogInterface.OnClickListener () {
@Override
public void onClick ( DialogInterface dialog, int which ) {
Reflection.launchMarketDetails ( activity, Reflection.getPackageName ( activity )
+ ".license" );
activity.finish ();
}
} ).setNegativeButton ( android.R.
string.cancel, new DialogInterface.OnClickListener () {
@Override
public void onClick ( DialogInterface dialog, int which ) {
Toast
.makeText (
activity,
"You will not be able to use this application until a license is purchased or the ad "
+ "blocking is removed.",
Toast.LENGTH_LONG ).show ();
activity.finish ();
}
} ).show ();
}
}

Friday, August 27, 2010

Closing an activity by touching outside

I have been working on an application that I want to close an Activity when the user touches outside the activity. Like how you can set the setCanceledOnTouchOutside(boolean cancel) in the android.app.Dialog. The activity I want to close is themed like a dialog so there is an area around the activity that is not “active”.

I was able to achieve the desired effect by overriding the activity’s onTouchEvent(MotionEvent event). This method is called when a screen touch event is not handled by any views.

@Override
public boolean onTouchEvent ( MotionEvent event ) {
// I only care if the event is an UP action
if ( event.getAction () == MotionEvent.ACTION_UP ) {
// create a rect for storing the window rect
Rect r = new Rect ( 0, 0, 0, 0 );
// retrieve the windows rect
this.getWindow ().getDecorView ().getHitRect ( r );
// check if the event position is inside the window rect
boolean intersects = r.contains ( (int) event.getX (), (int) event.getY () );
// if the event is not inside then we can close the activity
if ( !intersects ) {
// close the activity
this.finish ();
// notify that we consumed this event
return true;
}
}
// let the system handle the event
return super.onTouchEvent ( event );
}

Now with that code in place, if the user touches anywhere outside of the dialog style activity, it will close.


Showing posts with label code. Show all posts
Showing posts with label code. Show all posts

Microsoft Channel9 Addon for Kodi

To add to the my list of hobby projects, I created a fork of an addon for Kodi that provides browsing of videos on Microsoft Channel9. This was my first attempt at a Kodi addon, and really my first time working with writing python. I started out by just reading over the original code and tweaking it a bit because some things were not working. Then I started following the pattern that existed and implementing new features, like being able to browse Channel9 authors, and Channel9 events.

Once I got these features in place, I started doing some real refactoring of the original code base. There was a ton of code that was duplicated in multiple places. I spent a few hours of the day really rewriting the entire addon. As the project stands right now, it is basically a complete rewrite of the original addon.

The project is on Github and building on AppVeyor.

Download the latest Release

Amazon Echo Api

As I posted in my previous post, I recently bought an Amazon Echo. I saw some videos of people using their Echo to do home automation with a Raspberry Pi or Adriano. They did this by using something like Node, or python to monitor the tasks that are added to the Echo. To do the monitoring, they used the undocumented, unsupported, Api of the Echo.

I wanted to play around too. While I really don’t do anything related to home automation, I still wanted to explore the Echo Api and see if I could implement some type of wrapper for it in C#.

Here is what I found with the undocumented Api:

  • The desktop app connects to a WebSocket on the Echo device. I have not yet successfully connected to the socket, nor have I tried yet.
  • There is a url to get the latest “cards” - /api/cards?limit=N
  • Get the tasks - /api/todos?type=TASK
  • Get the shopping list - /api/todos?type=SHOPPING_ITEM
  • Get registered devices - /api/device
  • Get the media state for a device - /api/media/state?deviceSerialNumber={0}&deviceType={1}
  • Get the connected bluetooth devices - /api/bluetooth
  • Get music accounts - /api/music-account-details
  • logout - /logout
  • Get the capabilities of each provider - /api/media/provider-contenttype-capabilities

I also found that I should be able to send commands to Play, Stop, Next Track, Previous Track, Shuffle, Repeat, and set the Volume. The web app does this by first doing an HTTP/OPTIONS request, followed by an HTTP/POST. The post contains a JSON payload that contains the meta data of the device and what the volume is (if setting the volume). I have been unable to successfully POST these commands as there should be a CSRF token sent along with the POST. This token should be available in the cookies, but for some reason that I have not figured out yet, the token does not exist in the CookieContainer.

Currently, I have a working wrapper Api to Login, Logout, Get Tasks (TODO or SHOPPING), and update a task. I have posted my code on GitHub and I will push changes when I make them. This is just a little toy project that I decided to play with when bored. I will continue to work on it in free time, while I am interested in it. Feel free to fork it.

Amazon Echo Api

Happy Hacking of your Echo

Amazon Echo Material Design Stylish Theme

echoI bought an Amazon Echo last week. I was looking for a Bluetooth speaker and for $100 (for Prime Members), it is a decent Bluetooth speaker, plus it integrates with Prime music, and other Amazon services. It allows you to purchase items from Amazon directly from the Echo. It also has other features like TuneIn radio, iHeartRadio, a timer, an alarm (seems like it should support more than one timer and alarm, hopefully they will add this functionality in the future), todo list, and a shopping list.

The Echo has a companion app for iOS and Android devices, and it has a web app for your desktop. I was playing around with the CSS the other day while I was off work and decided to re-theme all (or most) of the desktop app using Stylish (Chrome|Firefox).

 

Download Amazon Echo Material Theme

 

 

 

 

Here are screenshots of just about every page within the Echo desktop app. Some are pretty boring, but they do show some of the elements that have been changed on the page.

1 

2

3

4

5

6

7

8

9

10

Powershell Script to download //BUILD/ 2014 sessions

Here is a powershell script that downloads all the mp4 video sessions available on Channel9. It first pulls all the HD videos, then checks the normal quality videos. It names the videos based on the session title. It will only download the video if it does not exist in the destination directory.


Update: Blogger doesn't want to show my GIST, so here is a direct link to it.

New open source tool: Fyles

Fyles is a tool that will gather all the icons for all the file types that are on a system. It then generates a sprite sheet and css for all of those extensions. Fyles only references unique icons, so if there are file types that share the same icon, it will only be in the sprite once. The exception to this is the “default” icon, to ensure that the default icon exists in the sprite, it may exist more than once.

Here is a sample of how the sprite is laid out:

fyles-sample

And here is a small block of what the css looks like:

And here is how you would include an icon on your page:

Html5 Unobtrusive Form Validation for ASP.NET MVC

I have a project that I was able to make use of modern browsers HTML5 form validation. But I wanted to include the validation that also takes place from within aspnet mvc so there is a unified experience with the validating the form. I took the jquery.unobtrusive-validation.js and made some modifications to it to hook in to the aspnet mvc validation. It is not yet 100%, the “Required” aspnet mvc validation doesn’t seem to “trigger” unless the field is filled out, then attempted to be submitted, and then cleared again, but the default html5 “required” validation message still shows initially. Either way, I figured I would share this and maybe someone could build on it and improve it. Enjoy.

Here are some screenshots of the results.

Failed Regex Validation
image 

Failed Minimum String Length Validation
image 

Failed Remote Password Strength Validation
image

Failed Compare to Password Field Validation
image


Download from Skydrive

Eclipse Color Theme

To go along with the other themes that I have posted here in the past based on Coding Instinct, here is a Coding Instinct theme for Eclipse Color Theme. The site also has a download in EPF format (Eclipse Preferences).

java-codinginstinct

Eclipse Color Theme (XML) – for Eclipse Color Theme Plugin
Eclipse Preferences (EPF) – for Eclipse Import

Check if the user is running AdBlock

A lot of applications on the android market use admob, or some other advertising method to keep the application free but still be able to generate some revenue. The ads are good for both the developer and the user. It generates revenue for the developer, and gives the user relevant advertising.

There is an application, which was recently pulled off the android market, called AdBlock that blocks these advertisers from displaying ads. This application can be a thorn in the side of the developers, as it is hindering income that the developer could be receiving.

Now you could probably argue that these people that run AdBlock wouldn’t click on the ads any how, and for the most part, that is probably true. But at the same time, a lot of applications on the market offer a license key or some other way to remove the ads from the application buy paying the developer a small fee. If the user is running AdBlock, they are circumventing this licensing model and in a way, stealing the application.

One of the great things about android is the ability to launch other intents. And by having this ability, we can check if the user has AdBlock installed. If they have it installed, we can then render the application useless until they remove AdBlock, or purchase the license.

This code block below will check if the user is running AdBlock, if they are, it will display an alert dialog and launch the market to purchase a license, or they can close the application.

private static void performCheck ( final Activity activity ) {
PackageManager pm
= activity.getPackageManager ();
Intent intent
= pm.getLaunchIntentForPackage ( "de.ub0r.android.adBlock" );
if ( Reflection.isPackageInstalled ( activity, intent ) ) {
new AlertDialog.Builder ( activity )
.setTitle (
"License Required" )
.setMessage (
"Since you are running software to "
+ "block the ads that keep this software free, you must purchase a "
+ "license to use this software from "
+ "the android market." )
.setPositiveButton ( android.R.
string.ok, new DialogInterface.OnClickListener () {
@Override
public void onClick ( DialogInterface dialog, int which ) {
Reflection.launchMarketDetails ( activity, Reflection.getPackageName ( activity )
+ ".license" );
activity.finish ();
}
} ).setNegativeButton ( android.R.
string.cancel, new DialogInterface.OnClickListener () {
@Override
public void onClick ( DialogInterface dialog, int which ) {
Toast
.makeText (
activity,
"You will not be able to use this application until a license is purchased or the ad "
+ "blocking is removed.",
Toast.LENGTH_LONG ).show ();
activity.finish ();
}
} ).show ();
}
}

Closing an activity by touching outside

I have been working on an application that I want to close an Activity when the user touches outside the activity. Like how you can set the setCanceledOnTouchOutside(boolean cancel) in the android.app.Dialog. The activity I want to close is themed like a dialog so there is an area around the activity that is not “active”.

I was able to achieve the desired effect by overriding the activity’s onTouchEvent(MotionEvent event). This method is called when a screen touch event is not handled by any views.

@Override
public boolean onTouchEvent ( MotionEvent event ) {
// I only care if the event is an UP action
if ( event.getAction () == MotionEvent.ACTION_UP ) {
// create a rect for storing the window rect
Rect r = new Rect ( 0, 0, 0, 0 );
// retrieve the windows rect
this.getWindow ().getDecorView ().getHitRect ( r );
// check if the event position is inside the window rect
boolean intersects = r.contains ( (int) event.getX (), (int) event.getY () );
// if the event is not inside then we can close the activity
if ( !intersects ) {
// close the activity
this.finish ();
// notify that we consumed this event
return true;
}
}
// let the system handle the event
return super.onTouchEvent ( event );
}

Now with that code in place, if the user touches anywhere outside of the dialog style activity, it will close.