How to Prevent .NET MVC Url.Action() Method from Inserting ID in a Route

Listen to this text

I had this issue that took me a solid two hours to debug. I thought I’d quickly write about it for the common good, in case it saves collective time for humanity: time that can be better wasted on other non-productive endeavors, like refreshing reddit, or reading some awful blog (not this one of course).

It appears that the Url.Action() method in MVC will take whatever current value is in the ID field on your browser, and sometimes plug this into a new route, even when you are explicitly not doing so.

For instance, Suppose you navigate to a route /User/Profile/855 where 855 is the ID. And you want a link to just /User/Profile/(no id). Well, if you use Url.Action() is will “helpfully”, put the 855 id in there for you, even if you ask nicely not to. It’s like a toddler trying to be helpful while you make coffee and so you let them hold the measuring cup with all the coffee grounds and then instead of putting it in the coffee maker, they miss and drop it all on the floor. But… I digress 🙂

So, the way to force MVC’s Url.Action() method to NOT do this, is quite simple, you just put in an empty string when constructing the action, so in this example it’s just:

@Url.Action("Profile", "User", new { id = "" })

7 ways to have no side effects after Covid Vaccine Dose 2

Listen to this text

It’s now 48 hours after my second Pfizer Covid vaccine. I’m happy to report that side-effects were incredibly mild. My arm did not feel sore until about 8-12 hours after my shot. At first, I questioned whether they gave me a placebo, since I was expecting — at minimum — some arm soreness. The soreness did arrive, but it was very mild. It didn’t affect me much; I was able to use my arm as I normally do with a little less bounce; I skipped on any heavy lifting or weight lifting. After about 12 hours after dose 2 I felt a little more tired than usual. Not debilatingly tired, but tired enough that I went to bed about an hour earlier than I normally do 9:30PM — probably the time I should bed (I usually go to bed at 11pm and wake up at 6:40AM).

The next day I think was the day my immune system was actually starting to activate and build up more antibodies. 24 hours after the shot, the side effects were mild enough that it didn’t affect my day, but I did feel a little more run-down than usual: I felt a touch light-headed at times, a touch more sluggish, and at times I felt a little warm (which was remedied by simply wearing a t-shirt). That’s it! That was all the side effects. I heard folks in my age group (I’m 38) feel really sick after the 2nd shot. But, I felt fine. There were side-effects but they were surprisingly milder than I anticipated. I took no advil or tylenol, but I did drink a ridiculous amount of water from an hour before through 48 hours after my shot.

So, in list fashion, here’s what I recommend you do to minimize side effects from 24 hours before your shot to 48 hours after:

  1. Drink Water

    Drink 32oz of water an hour before your shot. It’s a lot of water, and you should probably use the bathroom before your shot; and you’ll probably need to use it again right after. And then slowly drink 32 ounces of “extra” water than your normally do each day, for the next 48 hours. But drink it very slowly as in, 32 oz over the course of an hour or two, so as not to dilute the natural electrolytes in your body and overload your kidneys. Listen to your body, though. Drinking too much water can lead to hyponatremia, so just listen to your body. If you feel like your forcing yourself, stop. Take-in extra salted nuts to keep your sodium in-check. Being well-hydrated is probably the most important thing you can do.

  2. Sleep

    Get 8-9 hours of sleep the day of your shot, and the next 2 consecutive nights. Harder to do if you have little kids, but maybe your partner can help?

  3. Go Vegan

    Eat plant-based, with extra fresh fruits and vegetables, with extra emphasis on fruits with a higher concentration of vitamin-c (kiwis, oranges, grapefruits)

  4. Take Vitamin D & C

    Increase your vitamin-D through supplements or fortified milks. Vitamin-D and vitamin C is integral to the immune system. Vitamin-C is easy to get, but we are often deficient in Vitamin D, so do make sure your getting the daily recommended amount on that one.

  5. Eat light

    Eat very light meals (salads, oatmeal, vegetables, fruits). No processed foods or junk. Everything you consume should be high quality.

  6. No Alchohol

    This probably goes without saying but I’ll say it: don’t drink any alcohol!

  7. Skip the Gym

    Skip exercise during this period. Or, if you must, do something very light. I have often found that if I ever feel like I’m about to have a cold and I exercise the day before, I am almost sure the cold will get worse the next day. I think when your immune system is activated, it’s best to keep all external stressors you can control on the body to a bare minimum.

Covid-19 – Dose 2!

Listen to this text

I just got my second dose of Pfizer’s Covid shot today! I’m excited that I’m just 14 days away from hardcore immunity! I’m a little worried that the side effects, of which I’m anticipating, will knock me out for 24-48 hours. Everyone in my age-group seems to get them after the 2nd dose, due to youths’ more “robust immune response” (whatever that means). Right now, surprisingly I feel great! I had that shot at 10AM, and it’s now 2PM, and I feel nothing … not even arm soreness (which I had after my first dose).

Well, in my effort to do something to counteract the side effects I drank about 96 ounces of water since my shot. I’ve had to go to the bathroom, maybe 20 times now! Let’s see if the water and my vegan diet and general good fitness level will keep my afloat and on my A-game to keep up with my fierce little toddlers at home tonight.

[Review] Thank you for Being Late

Listen to this text

Last week I finished listening to Thank You For Being Late: An Optimist’s Guide to Thriving in the Age of Accelerations. Overall I liked the book. There’s a little lukewarmness in my feeling towards it, but that lukewarmness, is still pleasant: like perfect Nevada shower-water, the kind you can stay-in for hours.

Like the last book I read (Brain Maker), the title of this book was very misleading. I came into this book hoping (and believing) it would be a book with dire warnings of how we are moving way too fast in our modern impatient, techno-culture (what the book dubs, The Age of Acceleration). While it did do some of that, those parts simple book-ended the beginning and end of the book, while the bulk of this tome was simply a charting –in exhaustive detail– of the history of how we got to where we are today.

I must admit, I was still fascinating to hear how AirBnB was started by a RISD student barely scratching by in California, subletting his place with air-mattresses to make rent. I loved hearing things about technology that I hadn’t heard before, like Github and Hadoop’s origin story. There was an interesting notion that Friedman reiterates throughout the book about the Computational Supernova we are living in: the recent abundance of cloud-based processing power that is making complexity cheap in this new era.

If you are looking for a detailed charting through of recent technological innovations in a very readable, and well-written book, this is it. In fact I might dare gamble it’s the most comprehensive and most readable book on the shelf right now about this subject; the author, Thomas Friedman, being a former NY Times journalist is in a rare position to provide a ton of great first-hand anecdotes, and interviews with important figures that have been pioneers in our current track of exponential Moore’s Law growth. His journalist eye for important detail, and (perhaps, problematic) linear historical progression makes for a very pleasurable read.

Some of my takeaways (or more like extrapolations) from this book is that technology is moving faster than I even imagined. Human empathy is something that may be in short supply as complexity in technological innovations accelerates; technology is far outpacing our own social structures and inner psychic capacity to keep things in balance. As such, there is even greater value in the liberal arts and human relations now than ever before (regardless of the STEM or the Everyone should Code movement).

My advice: even if technology is running at full-steam at the 10 mile mark, stop at the water-stations, break sourdough bread with your family, breathe — in and out — and cherish moments with the ones you love. Life is an ultra-marathon not a sprint.

[Review] Brain Maker: The Power of Gut Microbes to Heal and Protect Your Brain–for Life

Ever since reading Michael Pollan’s The Omnivore’s Dilemma, I’ve been fascinated by books on food. To be sure, food is the most important thing in your life; it literally is “life”. Without food, life stops, period. Consequently, without good choices in food, your life and health will be affected profoundly. If you prepare most of the meals for your family (like I do), your responsibility of choice when it comes to food is multiplied. Given this, I always want to know as much as possible about nutrition as I can.

Yet, at this point in my mid-thirties, I have read a lot and I find that usually books on food do one of two things: (1) rehash the same information, often in list-form, or (2) present something new but so devoid of any scientific backing that their findings are worse than bad, they are dangerous (a la, Atkins, Paleo Diet, etc.) So it is always a pleasant surprise to find a book that is scientifically sound, offers something new, and is fascinating at the same time. Enter: Brain Maker: The Power of Gut Microbes to Heal and Protect Your Brain–for Life.

Brain Maker is a fascinating book. Don’t be put off from it because of the title — I almost was. At first I thought it was a book on how to improve my cognitive skills, and I’ve heard enough of that sort of thing that it doesn’t interest me. However, the book’s title should have been changed to something more akin to what it’s about, that is, the impressively complex legions of bacteria in your body that are quietly orchestrating basically everything about you.

Here are some takeaways from this book that I’ve already incorporated into my own life and I recommend you do the same (pardon the list-form):

1. Eat more Pro and Pre-biotic foods, such as fermented foods, like Kimchi and Sauerkraut. I never realized how important pro-biotics were to nutrition and have consequently incorporated them into my diet. As it happened, around the time I finished the book, I had a large organic cabbage in my fridge just waiting for me to do something with. I decided to made Sauerkraut with it one evening using the instructions on this site. It was super easy, and requires nothing but salt. Once made, it has a super-long shelf life in the fridge (10 months I hear) so I highly recommend having some stocked at all times. The taste will grow on you (excuse the pun). I also stocked some Kimchi in my fridge. The first time I went to Stop & Shop looking for it, I couldn’t find it and assumed they didn’t haveit, until one day I discovered it next to the mushrooms in the most random spot.

2. Stay Clear of Sugar. I generally avoid sugar in the obvious places, like my daily coffee and processed foods. But I stepped the avoidance up a notch and have really nixed it altogether from my diet. I generally don’t eat any sugar aside from the fructose I get from fruit, and the occasional — reluctant — pasta bowl or lasagna (in the form of carbs). I have a killer, oft-requested Vegetable Lasagna recipe that (shhhhh!) I stole from here. You can’t help but get sugar in things like Strawberry preserves, or even organic pasta sauce, so for me, just avoiding all deserts, cookies, and refined white flour have served me well. It is interesting how once you stop eating sugar for a certain period of time, your microbiome has adapted to this more friendly environment and any stray cookie afterwards, makes your stomach feel unpleasant — a good deterrent.

3. Exercise Often: I know, doh! But sweating apparently does affect your good bacteria in an extremely positive way, so you must exercise at least 20 minutes 4 times a week.

4. Drink Red Wine: This is one of the easy ones on the list (at least for me). It is easy to over-do it, so be moderate if possible.

Beating the Market Using a Server (and freezing your emotions)

I discovered a very conservative, but effective way to make money on the stock market that beats passive index investing by several notches. It took almost a year to refine the algorithms, along with a lot of false starts, bugs, and mistakes, but I feel really confident now that the methodology is somewhat sound and stable.

This sounds too good to be true right? Sounds like SPAM, right? One of those auto-bots on stock discussion boards, that almost sound like a real person. Perhaps. Well, I’m not SPAM, and I’m not an auto-bot (nor a Decepticon), and I can’t determine if this methodology will work if we fast-forward into the future. However, it’s based on some old fundamentals, uses historical data, and there are a few safety checks built in to help avoid the real risky equities (OTCs, etc). In fact, I actually think it can still work in a very bear market, or one that is grossly overvalued. All those sentiments are baked into the decision making of the software, and should allow one to stay clear of real dangerous / volatile securities.

The only time I have lost money on the market this year (which is too many) is only when I departed from using this algorithm. I start to let me emotions carry me and I used my gut. I sold when I should of held; or bought something on my own. Well, my gut seems to be as good as flipping a coin. I’m a software developer, and I know how to write code, calculate probabilities, and program a computer. I’m not an equities analyst, nor do I have any real business background. But, I found that as long as I slavishly follow the logic I developed and not let me emotions sway me, everything seems to work very well. In fact, YTD (9 months so far) if I followed this strategy, I would have seen a 120% gain in my portfolio. Of course, I didn’t follow it religiously, so I can’t boast that I had that type of gain this year. But, if I followed it to the letter, I would have — and I kick myself for it constantly.

They say that 84% of stock trading is done by computers. This is probably why this algorithm works — it thinks like a computer, because it is. It crunches historical data, measuring probabilities, finding trends, consumes analyst sentiment, and weighs target prices. If you follow the advice of my software slavishly, like an emotionless machine, you should see steady gains. Of course, investing any money in the market involves risks, so do so with common sense and discretion, and never follow the exclusive advise of one dope on the internet — use your own judgment.

This has been a really good year for the market in general. Some call it the Trump effect; that seems to be as good a reason as any for the huge gains over the broad market: especially since the double digit rise in the S&P aligns almost perfectly with the recent US election. Maybe this algorithm won’t work next year as the Trump effect seems to have cooled. That is yet to be determined.

I’m going to make the computer’s stock picks available on a daily basis to others as soon as I work through ways to do so without incurring too much load on my servers. Stay tuned!

Allowing Remote MySQL Connections on Amazon AWS and Windows Server 2016

I ran into one of those situations today where it took me forever to figure out why a MySQL database I spun up on Amazon AWS Windows Server 2016 wasn’t allowing remote connections. I finally figured it out on my own today — no thanks to the internet. Hopefully this helps you.

There are a few obvious things you need to check first and which you probably already know about to enable remote MySQL connections:

1. MySQL Account with Remote Access: First, you need a MySQL user on the database server that can connect from a host other than locally (a la “@localhost”). So, a user like “myUser@%”. The ‘%’ after the “@” is a wildcard that allows the user to connect to the server from any IP address in the world. Ideally, you would want to lock this done further than that, but it’s great to toss the wildcard in there for troubleshooting.

2. Amazon Security Groups: Ensure the Amazon security group your instance is attached to has a special inbound entry that allows TCP traffic on port 3306 from your IP address (or all IP addresses). This is easily done through the Amazon EC2 interface and there is a special type called “MySQL/Aurora” that you can select from the drop-down that will pre-fill the port-number .

3. Windows Firewall: Finally, and this is the gotcha that took me forever to figure out, you must check your server’s local inbound firewall rules. I saw a bunch of “allow” entries for MySQL already in there so I assumed it was fine. However, by default it creates these rules under the profiles “Domain” and “Private”. You have to explicitly add in another one within the profile “Public”, or edit one of the existing rules to also allow public, to finally enable remote connections.

After I did the final step, it worked like a charm.

Next Steps in a Donald Trump Presidency

HearWho Plugin Message: Object reference not set to an instance of an object.

Last night, my wife and I watched the election results as our newborn daughter slept in the crib next to us. Donald Trump is our next president. This much is now certain. What this means for our daughter’s future however, is less certain — like all futures.

Whether you voted for Hilary or whether you voted for Trump, all-in-all, it’s important not to overstate the importance of a single four-year presidential term of one person on your life. Yes, the President of the United States is like a Keystone species: with a disproportional large effect relative to size. Yet, still no one person is all-powerful. In fact, I think about some of the most notable individuals throughout history that have changed society for the better: those who have brought about social change, or have opened our eyes to new perspectives. Heroes like Dr. Martin Luther King, Rosa Parks, Susan B. Anthony, Ghandi, Mother Teresa, Nelson Mandela or Albert Einstein. None of those heroes were US Presidents. Additionally, all of these individuals suffered severe discrimination in their lifetimes: Einstein fled Germany from Adolf Hitler’s regime, Mandela was jailed for 27 years, Ghandi and King were assassinated. My point is that it’s not from a position of comfort that brings out the best in us — provoking society to change for the better — but significant change often comes from a position of discomfort and suffering: extraordinary achievements from seemingly ordinary individuals.

If you didn’t vote for Trump, and you don’t like the political trajectory of the nation in the upcoming years, four years is not a long time to wait for another election. I have many close friends who are both republicans and democrats. Even my family, although we share DNA, we don’t always share similar feelings on politics. Yet we still talk to one another, love and care for one another, all despite our politics. I think the same goodwill applies to the nation as a whole. Sure, there are gray dark spots on the fringes: those groups mired in exceptional hate. They will always exist in some form, but they are diminishing.

We all know John F. Kennedy famously remarked that the country is more about the individual’s endeavors rather than what an amorphous “country” might do for (or against) us. But another lesser known quote by JFK that I like even more, is that it is better to light a candle than to curse in the darkness. We can watch what happens in the next four years passively, or we can be an active participant of the future of our nation, and the future of our children. What candle will we light? What specific cause close to our hearts will we take up in the next four years and what passions will we inspire to that cause? That, my friends, is ultimately the thing that will matter most to our onlooking sons and daughters — that is, when they wake up in the morning.

How to Force a link to Download Instead of Play in Browser

In an earlier post, I included a link to a large MP3 file on my server. I noticed that whenever I clicked on it in Chrome, the file would not download, but would simply play within my browser. That is not the behavior I wanted: playing in-browser like that over time might cause unnecessary bandwidth expenditure, but more importantly, I felt that playing in-browser would not be as convenient for some users that wanted to simply download the file. I wanted to give the user the option. Anyway, it’s really easy to force an HTML-5 enabled browser (like Chrome) to force a link to download a file instead of playing in-browser. All you need to do is include the word “download” anywhere in the anchor tag:

<a download href="yourfile.mp3">Download this File!</a>

Now if only all things were that easy.

How to Backup MySQL and FTP Scripting with PowerShell

Listen to this text

I’m a .NET developer, not a system admin. As such, I never properly learned how to write anything aside from “echo” this, “dir” that, and “ipconfig -toomuchinfo” to a command window. But now, since I manage my own server on Amazon AWS, I wanted a neat non-c# console-app way of backing up my MySQL Database and FTP-ing the resultant SQL file to another location. Because Amazon storage is expensive and my other hosting provider (HostGator) has almost unlimited storage space, I wanted to FTP things there, as a safe, inexpensive backup solution. This is the poor man’s disaster recovery, which like most poor-man solutions, works surprisingly well.

I challenged myself to do this whole task in just Powershell and windows commands on the task scheduler, and the solution I came up with seems to work really well. Here it is:

1. First, I backup my MySQL database. Create a backup directory, like: “c:\backup\”. Then, use the MySQL backup utility: this is a file called “mysqldump.exe”. If you installed MySQL on your computer/server, the exe is somewhere on your computer. Just find it and copy it into your shiny new backup folder. Open up Notepad or your favorite text-editor (like VIM if you still use that) and create a simple “.BAT” file that runs mysqldump on your database which spits out a SQL backup file in your backup folder. I name the file after the current date: so today’s file would be “backup.20161101.sql”. The backup script is really just one line of text that reads like the following:

mysqldump.exe --single-transaction -u[username] -p[password] [your_database_name] > "C:\backup\backup.%date:~10,4%%date:~7,2%%date:~4,2%.sql"

(Note: replace the contents in [brackets] with your actual situation. Don’t include the “[]” and don’t add any spaces. Notice, that username and password arguments strangely don’t have a space between the “-u” or “-p”).

2. Double-click the BAT file to make sure it works and creates a SQL file for you.

3. Next, prepare your Powershell file that will FTP your file away. Powershell files are plain-text files which end in a “.ps1” extension. Before you get started with Powershell, you need to change the execution policy of Powershell on the server. The execution policy is by default crippled for security reasons. To change this, open up Powershell command prompt as administrator and run this command:

PS C:\> Set-ExecutionPolicy -ExecutionPolicy RemoteSigned

This will allow you to run your own Powershell commands but still requires downloaded scripts to have a signed certificate to execute. You will likely get a scary warning when you change this. (Please read up more on execution policies before doing this.)

4. Finally, create your Powershell script that will FTP your SQL files to your FTP server. Because the file name scheme I have is predictable, I know what the name of the file is that I want uploaded each day. Here is the script I created; just copy this to a text file and replace the [brackets] with your situation and save the file. I called the file “FtpDataFile.ps1”:

#we specify the directory of the file we want to upload

#ftp server
$ftp = "ftp://[ftpUrl]"
$user = "[FTPusername]"
$pass = "[FTPPassword]"

$webclient = New-Object System.Net.WebClient
$webclient.Credentials = New-Object System.Net.NetworkCredential($user,$pass)
$item = "backup.$(Get-Date -Format 'yyyyddMM').sql"

"Uploading $($Dir + $item) ..."
$uri = New-Object System.Uri($ftp+$item)

$webclient.UploadFile($uri, $Dir + $item)

5. Set up another task that runs your Powershell file on the server (space it out at least 15 minutes after the MySQL backup task). In order to run Powershell on the command window, you need to essentially execute the “Powershell.exe” process and pass the script file as an argument. So it would look like this:

c:\> PowerShell -File .\FtpDataFile.ps1

(Note: The “.\” is a relative directory symbol meaning, “directory above this one”; you may need to adjust your path.)

You can easily consolidate all this to just one Powershell script. And if you do, be sure to put in a wait/sleep command in there between the two tasks to make sure the SQL file is finished building before FTP-ing it away.