Skip to main content

Posts

C#: Using WebClient on CSV Formatted Stock Data

In this example I wrote a program to pull historic stock data from the ticker “DIS” over the past 10 days from the current date (it will be less than 10 results because weekends don’t have data). I used the .NET Framework WebClient object to request and return the data as a string that I parse into a generic Dictionary. It pulls the data from Google’s finance website as well as Yahoo’s finance site. Of course, check out their terms of use before doing anything with the code. Here is the code that I wrote on my GitHub. I created a class to handle communication with Google’s and Yahoo’s CSV export links. It handles constructing proper links as well as requesting the data and parsing it into a Dictionary that is structured by date. From that point, you could build an application around the use of that data, but for this example we just translate it back into strings for display in text boxes. public class WebClientForStockFinanceHistory { WebClient webConnector; // See Google...

A simple classic VB code counter made in C#

I made this simple application a while back when I needed to quote a project where I was tasked with converting a sizeable amount of classic Visual Basic code into the .NET Framework. This application I wrote allowed me to start my estimation so that I could tie a dollar amount to the work. There is a lot more I could have done to the project, but when you are doing contracted work on a per project basis, it’s important to be efficient. While I did some browsing through the projects that was equally important, this code counter did make a difference in my estimations thereby allowing for a properly researched quote. Now that I’m basically done with the project, I felt that I was relatively close to my estimation. Here is the code for my VB code counter on my GitHub. Here is the important code for my counter tool: public IEnumerable<string> FilterFiles(string path, params string[] exts) { return exts.Select(x => "*." + x) .SelectMany(x => Directo...

Android: Using the CountDownTimer class

In this article I go over the Android SDK CountDownTimer class. It’s easy to use and gives you the ability to count for projects like a workout timer. In this case we are extending that class so that we can access the methods we need to make it work. Here is the code on GitHub. Here is our SimpleCountDownTimer: public class SimpleCountdownTimer extends CountDownTimer { public static int oneSecond = 1000; TextView textViewTimeLeftDisplay; public SimpleCountdownTimer(long millisInFuture, long countDownInterval, TextView textViewTimeLeftDisplay) { super(millisInFuture, countDownInterval); this.textViewTimeLeftDisplay = textViewTimeLeftDisplay; } @Override public void onFinish() { textViewTimeLeftDisplay.setText("Finished"); } @Override public void onTick(long millisUntilFinished) { textViewTimeLeftDisplay.setText(String.valueOf(millisUntilFinished / oneSecond)); } } The extended timer class takes in the...

C#: Using the Background Worker to thread your application processing.

In this article I go over using the background worker control in C# .NET Framework (Visual Studio 2015). This control allows you to easily do processing intensive tasks without locking up your interface thread. I use this a lot in winforms applications where I expect code to take any amount of time that the user would notice the interface being locked up while processing. This control gives you the ability to send progress updates to the interface thread as well as cancel processing any any time. The code for this example is on my GitHub here. Here is the important code from the main form: public enum CurrentStatus { None, Reset, Loading, Cancelled, Success, Busy } public class MainForm : Form { private BackgroundWorker bwInstance; private Button btnStartWorker; private Button btnStopWorker; private Label lblLoadingStatus; private ProgressBar prgLoadingProgress; private CurrentStatus processingStatus = CurrentStatus.None; public Ma...

Android: Working with Preferences and Settings

In this article I go over using the built-in Android settings and preference system. I have a settings class as well as an activity that manages user input. A spinner is assigned the task of letting the user turn on or off a vibration feature. When the application is started again, the setting is accessed and assigned to the spinner. It also enables or disables the vibrator based on our saved preference. The code is available on GitHub here. Here is our Settings class: public class Settings { public static final String PREFS_NAME = "twoc_settings_example"; public static final String KEY_SETTINGS_AVAILABLE = "settingsavailable"; // your custom settings in the application public static final String KEY_STATE_VIBRATION = "vibrationstate"; // the object used to access settings for this application stored in a predefined setting area SharedPreferences prefAccessor; public Settings(Context parentContext) { prefAccessor = par...

Javascript and HTML: Async Communication Prototype

In this article I go over an asynchronous communication prototype I had made in straight Javascript that you use to POST to a server script and pass along the response to a Javascript function specified by the initial call to the prototype. The main benefit here is that you don’t need a full page refresh, which is great for implementing web interfaces that have an application feel to them. It doesn’t use any bulky libraries and should work on all browsers. An ideal use case for this would be websites hosted in an internal network that you wanted to act like an application. Though, with extensive modification you could add security features or just run it through https with proper verification code in the PHP script. The example code is located on GitHub. In my example I have four files: example.html = the html page that gives the user two buttons that fire off asynchronous calls to a server side script. AsyncManager.js = The prototype (aka. class) that handles communication and respons...

Android: Basic game loop with scaled graphics.

In this article I go over implementing a simple game loop with a custom view. The standard draw method is used with some timing checks so that we can get an approximately consistent refresh rate. This is a somewhat simple way to get started without having to use something OpenGL. The full source code is on GitHub. The main activity handles the creation of our custom view and passes along screen size information once it’s available. This is a key step because it allows us to get that screen information before the view actually starts being displayed. I have a previous tutorial on just that here so I am going to omit the main activity code and the related xml layout file. If you want an exact game update loop structure, you might need further restrict any numeric changes in your game specifically by time rather than having them in the middle of the draw loop that is approximately updated on a given time frame. I haven’t done any testing to verify if that’s needed or not. Also, read up o...

Android: Get the size of a custom view before display.

When developing applications or simple games for Android where you are drawing or writing to a view, an issue arises upon startup of the view. In my case I had a game where I wanted to calculate screen tile size before the game view starts, but with most tutorials I had seen everything happened after the view was fully running. That turned into a chicken and the egg scenario. I needed some key information before I could start the game view, but the default techniques didn’t allow for that. Here is the code on GitHub for this article. I was able to get around the issue with a few techniques. Have my main Activity linked with an xml layout file that has two empty nested linear layouts that fill the screen. Make a custom view that houses the main draw code. For this example, all I do is fill the screen with black and display the available screen size. Attach a ViewTreeObserver.OnGlobalLayoutListener in the Activity that will be the boot code upon getting the screen’s view size. I’m not sh...

Raspberry Pi GIT Server Notes

Edit: I updated my RP GIT server and made more notes in a later article. Here are my notes for setting up GIT on Raspberry Pi and using a Windows client (TortoiseGit). I’ve been using this little thing as a GIT server for around 5 months now and I love it. Here is the quick notes I took while getting things setup. It’s probably really disjointed, but you might find some helpful tips in here. www.raspberrypi.org http://www.raspberrypi.org/downloads NOOBS (offline and network install) http://downloads.raspberrypi.org/NOOBS_latest Format your SD card using the SD Card Association’s formatting tool. https://www.sdcard.org/downloads/formatter_4/ Install Raspbian (GIT seemed to be pre-installed on the version I used): The defaults: username: pi password: raspberry When greeted with the post install program, find the advanced option to enable SSH. You can also change your password from there. 2017 Edit: I’m in the process of installing it on a larger SD card. Anything over 32GB will probably ...

FXAA Shader Anti-aliasing in XNA 4.0 Winforms

I had the challenge of trying to get some type of anti-aliasing in a project that uses the winforms method of XNA 4 that was being run on a laptop in REACH mode. My first step was figuring out a method to use. I found quite a few shader based methods available, but I could get none of them to work. FXAA written by a engineer at NVIDIA seemed like the best option, so I went with that. I wrote up a question on Stack Overflow to see if anyone could help. Eventually with enough research and …playing around… with the code I have it functioning. Here is an example to help anyone who might be interested in doing the same thing. —————————————————- I’m using this example project’s XNA 4.0 form control in an application I’m writing: http://creators.xna.com/en-US/sample/winforms_series1 If you are unfamiliar with FXAA, check out the creator’s site: http://timothylottes.blogspot.com/2011/03/nvidia-fxaa.html I’ve spent quite a bit of time so far trying to figure out to use it without any luck...