05 Dec 2018
These are the the steps to generating a new SSH key and testing Bitbucket ssh keys on Windows.
This set up will allow you to use a custom ssh key specifically for Bitbucket, without having to change your id_rsa key.
- Run ssh-keygen to create a new ssh key
- Use bitbucket_rsa for key name
- Don’t specify a password, if you don’t want to enter it every time.
-
Add the public key to the ssh-keys section inside of Bitbucket (use the file with the .pub extension)
-
Create ssh config file with the following settings for bitbucket.org
FileName: ~.\ssh\config
Host bitbucket.org
IdentityFile ~/.ssh/bitbucket_rsa
IdentitiesOnly yes
-
Test your new key against Bitbucket to see if it uses the correct file
ssh -T git@bitbucket.org
-
Verify you’ve successfully logged in.
logged in as <UserName>.
You can use git or hg to connect to Bitbucket. Shell access is disabled.
Now, you should be able to push / pull from Bitbucket without needing to specify your ssh key:
SSH will use the correct key when connecting to bitbucket.org.
09 May 2018
There’s a tremendous amount of text manipulation you can do with notepad++ such as transforming SQL table output to markdown tables
and auto generating code instead of having to type it by hand.
I ran into a problem recently where I accidentally created some interacting unit tests.
The Config class is a singleton with a global access point refernced in 99+ places.
Since everything in the program uses this class, if the SUT references this class,
then there’s a chance that another test will change a value on this classes causing an unrelated test to fail for no reason.
As a temporary solution, I came up with the idea of introducing a ProxyConfig class in front of the global config class.
This will limit direct access to the singleton config, and will allow consumers to hold a reference to ProxyConfig instead of Config.
That way, I can give each test its very own ProxyConfig, and the tests will no longer interact with each other.
public class Config
{
public static Config Instance { get; set; } = new Config();
public bool AggroFilter = false;
}
public class ProxyConfig : IConfig
{
public bool AggroFilter
{
get => Config.Instance.AggroFilter;
set => Config.Instance.AggroFilter = value;
}
}
Now we can create a new TestConfig for testing purposes.
public class TestConfig : IConfig
{
// Simple getter / setter for easy testing.
// Will not interact through Config.Instance with other tests!
public bool AggroFilter { get; set; }
}
Sadly, Config has 15+ fields that need to be converted to properties for use in the IConfig interface and on the ProxyConfig class.
Luckly, we can use notpad++ to do this text manipulation with ease!
Here’s the complete list of fields on the config class:
Config fields
bool AggroFilter
BattleLists BattleLists
bool ClaimedFilter
double DetectionDistance
int GlobalCooldown
double HeightThreshold
int HighHealth
int HighMagic
ObservableCollection<string> IgnoredMobs
string IgnoredName
bool IsApproachEnabled
bool IsEngageEnabled
bool IsHealthEnabled
bool IsMagicEnabled
int LowHealth
int LowMagic
double MeleeDistance
bool PartyFilter
ObservableCollection<string> TargetedMobs
string TargetName
bool UnclaimedFilter
double WanderDistance
bool StraightRoute
bool MinimizeToTray
int TrustPartySize
bool HomePointOnDeath
bool EnableTabTargeting
bool IsObjectAvoidanceEnabled
double FollowDistance
string FollowedPlayer
Now, with notepad++ you can use the following regex and replace to create getters and setters for all of the fields:
- Pattern:
(.*) (.*) (.*)
- Replace:
public $1 $2 {\r\nget => Config.Instance.$2;\r\nset => Config.Instance.$2 = value;\r\n}
You’ll end up with the following as a result.
public bool AggroFilter {
get => Config.Instance.AggroFilter;
set => Config.Instance.AggroFilter = value;
}
public BattleLists BattleLists {
get => Config.Instance.BattleLists;
set => Config.Instance.BattleLists = value;
}
public bool ClaimedFilter {
get => Config.Instance.ClaimedFilter;
set => Config.Instance.ClaimedFilter = value;
}
public double DetectionDistance {
get => Config.Instance.DetectionDistance;
set => Config.Instance.DetectionDistance = value;
}
public int GlobalCooldown {
get => Config.Instance.GlobalCooldown;
set => Config.Instance.GlobalCooldown = value;
}
public double HeightThreshold {
get => Config.Instance.HeightThreshold;
set => Config.Instance.HeightThreshold = value;
}
public int HighHealth {
get => Config.Instance.HighHealth;
set => Config.Instance.HighHealth = value;
}
public int HighMagic {
get => Config.Instance.HighMagic;
set => Config.Instance.HighMagic = value;
}
public ObservableCollection<string> IgnoredMobs {
get => Config.Instance.IgnoredMobs;
set => Config.Instance.IgnoredMobs = value;
}
public string IgnoredName {
get => Config.Instance.IgnoredName;
set => Config.Instance.IgnoredName = value;
}
public bool IsApproachEnabled {
get => Config.Instance.IsApproachEnabled;
set => Config.Instance.IsApproachEnabled = value;
}
public bool IsEngageEnabled {
get => Config.Instance.IsEngageEnabled;
set => Config.Instance.IsEngageEnabled = value;
}
public bool IsHealthEnabled {
get => Config.Instance.IsHealthEnabled;
set => Config.Instance.IsHealthEnabled = value;
}
public bool IsMagicEnabled {
get => Config.Instance.IsMagicEnabled;
set => Config.Instance.IsMagicEnabled = value;
}
public int LowHealth {
get => Config.Instance.LowHealth;
set => Config.Instance.LowHealth = value;
}
public int LowMagic {
get => Config.Instance.LowMagic;
set => Config.Instance.LowMagic = value;
}
public double MeleeDistance {
get => Config.Instance.MeleeDistance;
set => Config.Instance.MeleeDistance = value;
}
public bool PartyFilter {
get => Config.Instance.PartyFilter;
set => Config.Instance.PartyFilter = value;
}
public ObservableCollection<string> TargetedMobs {
get => Config.Instance.TargetedMobs;
set => Config.Instance.TargetedMobs = value;
}
public string TargetName {
get => Config.Instance.TargetName;
set => Config.Instance.TargetName = value;
}
public bool UnclaimedFilter {
get => Config.Instance.UnclaimedFilter;
set => Config.Instance.UnclaimedFilter = value;
}
public double WanderDistance {
get => Config.Instance.WanderDistance;
set => Config.Instance.WanderDistance = value;
}
public bool StraightRoute {
get => Config.Instance.StraightRoute;
set => Config.Instance.StraightRoute = value;
}
public bool MinimizeToTray {
get => Config.Instance.MinimizeToTray;
set => Config.Instance.MinimizeToTray = value;
}
public int TrustPartySize {
get => Config.Instance.TrustPartySize;
set => Config.Instance.TrustPartySize = value;
}
public bool HomePointOnDeath {
get => Config.Instance.HomePointOnDeath;
set => Config.Instance.HomePointOnDeath = value;
}
public bool EnableTabTargeting {
get => Config.Instance.EnableTabTargeting;
set => Config.Instance.EnableTabTargeting = value;
}
public bool IsObjectAvoidanceEnabled {
get => Config.Instance.IsObjectAvoidanceEnabled;
set => Config.Instance.IsObjectAvoidanceEnabled = value;
}
public double FollowDistance {
get => Config.Instance.FollowDistance;
set => Config.Instance.FollowDistance = value;
}
public string FollowedPlayer {
get => Config.Instance.FollowedPlayer;
set => Config.Instance.FollowedPlayer = value;
}
It took me 2 minutes to come up with the pattern, but saved me 5 to 10 minutes of typing!
I would have hated to type all of that by hand. The only thing left to do is auto-format the text to make it look pretty ^^;
02 Jan 2018
Well, I finally got sick of seeing the same National Grid commercial on Funimation for the one-thousandth time so I’ve come up with a strategy for blocking ads on their site.
You’ll need the following chrome plugin to get this to work correct:
- Custom JavaScript for websites to inject custom javascript into the loading page.
Funimation will load a blockadblock.js file when it detects adblockplus which will place four black overlay divs over the video content.
At first, I attempted to block the blockadblock.js http get request, but the other funimation javascript code depends on it.
What we’ll do instead is to load a timer that looks specifically for those div elements and will remove them from the page.
Code Snippet and Example
Javascript
// Create interval to repeatedly remove 'funimation-error-screen' every half second.
setInterval(function(){ $("funimation-error-screen").remove() }, 500);
CJS Settings

The plugin should load this javascript before the page loads and will eliminate the black overlay when they pop up.
Pretty simple solution for what was looking like a complex problem.
Hopefully this helps!
**Edit: It appears that loading JQuery onto the page blocks the Pause button.
You can do the same with Vanilla javascript using the following code:
// Create interval to repeatedly remove 'funimation-error-screen' every half second.
var timer = window.setInterval(function(){
var elem = document.getElementById("funimation-error-screen");
if(elem === null) return;
elem.parentNode.removeChild(elem);
},100);
28 Oct 2017
I wasn’t expecting so much trouble resetting the root password for a mysql instance.
The documentation said to use the –skip-grant-tables option and to pass that when the service is restarted.
skip-grant-tables
The problem is systemd does not allow you to pass arguments to services upon restart.
Instead of overriding the startup parameters for the mysql systemd unit, you can edit the /etc/mysql/my.cnf for the same effect.
/etc/mysql/my.cnf
[mysqld]
skip-grant-tables
Now you should be able to log into your mysql instance without a password.
Just remember to remove that from your configuration file after reseting your password!
27 Mar 2017
Many applications these days are using relational databases as the data store for information (except for the projects I work on in my spare time ~.^). Today, I did a lot of thinking about SQL’s affect on application performance and design, and have come to a strange conclusion: domain logic in the database is for performance, and domain logic in the application is for correctness.
What I’m suggesting is that we keep the filtering in both places. In that way, there are less rows to process and I can sleep at night knowing that my application will work well. None of this will make sense without an example, so here’s one about sending customer’s abandoned cart emails.
ShoppingCarts
ID |
OrderNumber |
DateCreated |
DateUpdated |
1 |
NULL |
3/18/2017 |
3/20/2017 |
From this, we can see that the customer never finished the checkout process (OrderNumber is null) and the cart is abandoned (Today’s date is 3/27/2017, and a week has passed).
Now, we have a rule where the DateUpdated is only updated when shopping cart line items are modified. That way, we don’t have to worry about what the ShoppingCartLineItems table looks like in this example ^^;
In SQL, we can find the abandoned carts pretty easily like so:
SELECT * FROM ShoppingCarts sc
INNER JOIN ShoppingCartLineItems scli ON scli.ShoppingCartID = sc.ID
WHERE OrderNumber IS NULL AND DATEDIFF(DAY, sc.DateUpdated, GETDATE()) > 7
Basically, we check see if the shopping cart didn’t make it to checkout by checking the OrderNumber and DateUpdated fields.
That’s all and good, but now what’s the application part in this ordeal? Pretty much to call this query and, if results are returned, to send out an email to the customer with the shopping cart line items they left in their cart (I left out those details intentionally as well).
This is all and good except now is become incredibly hard to test this logic. In order to test it, I better have a good set of database migration scripts, and create a nice set of integration tests.
Instead of doing that, I’m thinking we can go another way with this: we’ll leave the domain logic in the database like it already is, but we’ll also add that logic to the application as well. WHAATT?!?!!!
This is what the application code could look like:
public class ShoppingCartModel
{
public int ID { get; set; }
public string OrderNumber { get; set; }
public DateTime DateUpdated { get;set; }
// The domain logic for abandoned carts
public bool IsAbandoned()
{
if(OrderNumber == null && DbFunctions.DateDiff(DateUpdated, DateTime.Now) > 7)
}
public void SendMessage()
{
// sends the email
}
}
public ShoppingCartAbandonmentNotifier
{
private IShoppingCartRepository repository;
public ShoppingCartAbandonmentNotifier(
IShoppingCartRepository repository)
{
this.repository = repository;
}
public void NotifyAbandonedCarts()
{
var shoppingCarts = repository.GetAbandonedShoppingCarts();
var abandonedCarts = shoppingCarts.Where(cart => cart.IsAbandoned()).ToList();
abandonedCarts.ForEach(cart => cart.SendMessage())
}
}
At this point, it would be right to question what the benefits to leaving the logic in both places. Mostly, we gain a whole lot of confidence in our code because, if designed right, we can still use TDD and a fast feedback loop to develop the code. This should result in high code coverage.
As a result of that confidence, we gain these two benefits as well.
The contents of the SQL query becomes more of a performance thing. Your DBA can rentlessly tear up this SQL script to tune the performance without worrying about wreacking havoc upon the application code. As long as the correct rows are still returned, everything is all good in the world.
In addition, we no longer have to concern ourselves with what database implementation we are using. The repository pattern will handle most of the transition since it doesn’t have any knowledge of the database engine. Since we ensure correctness in the application itself, it’s not too important what the new query will be or if we don’t come up with the optimal query at the time of transition; as long as that query is semi-performant, and returns the correct rows then everything will be fine.
Surely, I haven’t had the confidence to move forward this this approach in any applications, but the benefits are pretty sound in theory. I don’t think the database implementation would change all that often, but having the option to relentlessly refactor my database code just like my application code would be priceless.
Indeed, this is still just a crazy theory, but maybe …
Side note
Quick listing of possible reasons why this is a bad idea:
- Duplication of logic where only one place is changed, but not the other (hard to predict bugs)
- Takes more effort to TDD the logic in the application and codify the same thing in SQL
Both are symptoms of not keeping the code DRY enough. But when one lives in a swamp where things weren’t too dry to begin with, then maybe this wouldn’t be the worse of your worries.