Musings of Geekdom by Eric Newton

tail /var/log/thoughts
posts - 88 , comments - 41 , trackbacks - 68

Sunday, February 17, 2019

WSL, git, ssh keys, and a partridge in a pear tree

(Note post is first draft)
Just ran into this tonight, setting up a new machine to actually run Ubuntu Bash via WSL.  I was trying to use git in the WSL ubuntu shell and use ssh keys.  Also found that after running ssh-keygen, ssh was now complaining that the keys were too public.  Easy fix: chmod 400 .ssh/id_rsa right?

Ah yeah, not working!  Sigh.  Okay, so wtf?   So I start investigating and to make things more annoying, apparently WSL seems to setup two different home directories.  Arg!  Somebody didn't think this through and now I have a Windows home directory and a WSL Ubuntu home directory.

TBH, having a unified home directory for bash and Windows is actually a standard practice by MinGW (and cygwin too, I believe) and Git for Windows installations.  They basically merge the concept of your home directory (ie, "cd ~") between Windows/bash.  This is best too, especially for your ssh keys and other things like configurations you want backed up, etc.

Now I only tried this so far with Ubuntu bash under WSL, so not sure if the Debian distro or others have this problem but from the short bit of searching revealed they might be in the same boat for the time being until somebody managing the WSL installations of Ubuntu/Debian/etc finally realize that they shouldn't actually be separate.  (Note, there definitely was issues in the past, prior to DrvFS metadata sync with NTFS ACLs, however they have DrvFS properly syncronizing commands like chmod 400 with proper NTFS ACLs that match the intention.) 

For starters, make sure you have Windows Subsystem for Linux installed, and choose your favorite (available) distro.  In my case, I'm using the Ubuntu distro.

First off, you want to copy your bash profile config into your windows home directory:

cd %USERPROFILE%\AppData\Local\Packages\Canonical[tab]\LocalState\rootfs\home\{username}

For instance, mine looked like this:

C:\Users\Eric\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState\rootfs\home\eric>dir
 Volume in drive C has no label.
 Volume Serial Number is 4CE0-4086

 Directory of C:\Users\Eric\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState\rootfs\home\eric

02/17/2019  12:29 AM    <DIR>          .
02/17/2019  12:29 AM    <DIR>          ..
02/16/2019  02:16 AM             3,771 .bashrc
02/17/2019  12:38 AM               546 .bash_history
02/16/2019  02:16 AM               220 .bash_logout
02/17/2019  12:29 AM    <DIR>          .local
02/16/2019  02:16 AM               807 .profile
02/17/2019  12:29 AM    <DIR>          .ssh
02/16/2019  02:17 AM                 0 .sudo_as_admin_successful

Now you want to copy some of these files into your Windows home directory, under %USERPROFILE% which is usually C:\Users\{username}.  In my case, thats C:\Users\Eric

So now we copy .bashrc and .profile into Windows:
copy .bashrc %USERPROFILE%
copy .profile %USERPROFILE%

In my case, I had some ssh keys in .ssh that I definitely wanted syncronized between everything, so I copied the contents of that folder into my Windows home directory as well:  (Note xcopy /i makes it assume that .ssh is a directory at the destination if its not there already)
xcopy /s /i .ssh\* %USERPROFILE%\.ssh

But wait... there's more!

Remap Home Directory
[Remap home directory in WSL: link]

Ok, so the problem you'll have now, if you run bash, its that the login process isn't looking in your Windows home directory still, so you have to map that properly. This is just like the standard distros: simply edit the /etc/passwd file to map your login's home directory to /mnt/c/Users/{username}.

sudo nano /etc/passwd
(make changes/save/exit nano)
logout

Now you can reload the WSL bash again.  I usually just type "bash".

At this point in time (2018-Feb-17), WSL doesn't seem to default to the correct DrvFS parameters to make sure chmod actually sets the underlying NTFS ACLs properly, so we have to make the WSL configure this correctly. You do this by create/edit of the file /etc/wsl.conf   Note, this file may not exist already, and TBH it didnt exist for me so I created it.

Note, I used the following article as a reference: Automatically Configuring WSL

bash #if not already running in bash
sudo nano /etc/wsl.conf

Add the following into that new file if just created (make appropriate edits if it already exists).  NOTE dont use the article's `root = /windir/` thats not a good thing unless you really want to start deviating from the "standard" WSL

#Let’s enable extra metadata options by default
[automount]
enabled = true
root = /mnt/
options = "metadata,umask=22,fmask=11"
mountFsTab = false

#Let’s enable DNS – even though these are turned on by default, we’ll specify here just to be explicit.
[network]
generateHosts = true
generateResolvConf = true

Now you save/exit nano and restart bash.

So in my case, my ssh keys can now be properly set to 400 via chmod and ssh will stop complaining about my private key being too public!

bash
cd ~/.ssh
chmod 400 id_rsa
ls -al ~/.ssh
total 8
drwxr-xr-x 1 eric eric  512 Feb 17 00:41 .
drwxr-xr-x 1 eric eric  512 Feb 17 00:58 ..
-r-xr--r-- 1 eric eric   46 Feb 17 00:29 config
-rwxr--r-- 1 eric eric  803 Feb 17 00:24 known_hosts
-r-------- 1 eric eric 1679 Feb 17 00:22 id_rsa
-r-------- 1 eric eric  394 Feb 17 00:22 id_rsa.pub
# worked! okay try ssh now:
ssh -vvv git@github.com
# (success!  ah yeah)


All right.  Hope that helps somebody else!

Posted On Sunday, February 17, 2019 1:51 AM | Comments (0) | Filed Under [ wsl windows-subsystem-for-linux ubuntu bash git git-for-windows ssh ]

Ajax Post on Safari 11.4 timing out for strange reasons? Check here

This was a little doozy.

We have a site that has ajax file upload fields that worked for all browsers, IE, Firefox, Chrome, Safari except for one instance: Safari on iPhones.

How strange!  The problem exhibited was that Safari would start the request but never seem to attempt to finish and no matter what timeout, would timeout after 60 seconds (the max I believe you can set).  Note that using a traditional POST would work fine, but who wants that in 2018/2019???

Turns out there's an odd little bug in Safari on iOS 11.4... if you have input type=file with no file selected, Safari sets up to upload zero bytes, and just does nothing.

The fix is a bit odd too... when you have an <input type=file> field with no file selected, you need to use new FormData() to remove it before submitting the request.

[sample code to come]
basically check the field via javascript before ajax post, examine the size property.  If its 0, you now know that there's no file selected, so you have to remove that field from the FormData collection.

Seems to have been fixed after iOS 11.4.


Posted On Sunday, February 17, 2019 1:10 AM | Comments (0) | Filed Under [ ios safari jQuery timeout ajax ]

Tuesday, June 26, 2018

Ajax Post on iOS Safari not working? Its the cache!

Not sure when this took effect, but a simple public facing web application we wrote using jQuery.ajax for doing our form posts nicely started not working on iOS devices.  The reports came in occasionally, but not with any fervor, so we chalked it up to user error.  

However, one day after the 10th report came in, I decided to check on my iPad Air, and... hmmm "Server didn't respond within the timeout".  I don't have a Mac so debugging Safari directly on iOS is virtually impossible for me, (Thanks Apple! Really!).  So I fired up Chrome on my Windows PC and the server responds just fine.  Sub 100ms responses for the exact same conditions.

I try other devices, other browsers, works just fine... can't test Safari on Windows though because Apple took their ball and went home.  (Boo hoo Apple)

So I finally borrow a friend's Mac and iPad for a few hours, and find out that iOS Safari just isnt even making the request... what the???

Looking at the jQuery ajax call we have something like this:

var formData;
formData = new FormData(form);
$.ajax({
url: $(form).attr("action"),
type: "POST",
data: formData,
processData: false,
contentType: false,
timeout: 15000,
success: function() {
$(".content-form__cta-item").find("a").trigger("click");
$(".form-validation-modal").remove();
return $("body").append(_self.openModelTemplate);
},
error: function(jqXHR, textStatus, errorThrown) {
console.log("error. textStatus: %s errorThrown: %s", textStatus, errorThrown);
return alert("There was an error handling your request please try again.");
},
complete: function(jqXHR, textStatus) {
return console.log("complete. textStatus: %s", textStatus);
}
});

I searched a little and there was mention of Safari's XmlHttpRequest shutting down any synchronous activities, so I added "async: true"   No dice.  

Went back to searching, and finally found something relevant, a fellow having the same problem, but the year is 2014 for the fix... I try anyways, and add "cache: false"

Turns out, iOS Safari will cache the post request, but will sit waiting for a response from a non-connection!  Um, wtf?

Searched some more, and finally found something that works:  setting the header Cache-Control to no-cache via headers: { "cache-control": "no-cache" } ends up telling the brain dead Safari XmlHttpRequest implementation to always hit the base server to get a response for the POST.

Here's the final code, working:

var formData;
formData = new FormData(form);
$.ajax({
url: $(form).attr("action"),
type: "POST",
data: formData,
cache: false,
processData: false,
contentType: false,
timeout: 15000,
async: true,
headers: {
"cache-control": "no-cache"
},
success: function() {
$(".content-form__cta-item").find("a").trigger("click");
$(".form-validation-modal").remove();
return $("body").append(_self.openModelTemplate);
},
error: function(jqXHR, textStatus, errorThrown) {
console.log("error. textStatus: %s errorThrown: %s", textStatus, errorThrown);
return alert("There was an error handling your request please try again.");
},
complete: function(jqXHR, textStatus) {
return console.log("complete. textStatus: %s", textStatus);
}
});

Posted On Tuesday, June 26, 2018 6:34 PM | Comments (0) | Filed Under [ ios safari post jQuery ]

Tuesday, February 26, 2013

HttpSecureCookie

A while back, I wrote an article on codeproject.com about being able to encrypt the value of an HttpCookie.  Adam Tibi wrote a follow up article regarding this, but the original code still works great as written.

I've since refreshed that code a little and presented it on nuget.org/httpsecurecookie

Enjoy!

Posted On Tuesday, February 26, 2013 1:26 PM | Comments (0) | Filed Under [ C# .NET Development ASP.NET ]

Google Maps Web services API wrapper for C#

Just released a new version of my gmaps-api-net (Google Maps Web Services API) for c# due to some bugs in the building of urls in the previous version, v0.10.0.  Go snag it from http://nuget.org/packages/gmaps-api-net/.

The next release, v0.11.0 will have some pretty big changes in the c# api due to some restructuring that I feel is necessary:
- JSON serialization classes are directly exposed as the domain objects, will be abstracting them into a separate namespace and present better controlled domain objects. This will make creating actual domain objects easier that can adjust to situations easier without mucking up the JSON deserialization
- XML de/serialization, not currently available but will be in the future.

In addition, a big feature addition for v0.11.0 will be:
- Signing for Enterprise customers that have a Client ID and Private key generated by Google, giving the business customers many more requests. See Google Maps API for Business FAQ written up by Google.

In the future, I'm planning on trying to abstract out even the mapping technology in use:
- Use Google Maps, or Bing, or MapQuest, etc via providers on a Common mapping provider framework.

Keep tabs on the project at: https://github.com/ericnewton76/gmaps-api-net

Posted On Tuesday, February 26, 2013 1:15 PM | Comments (0) | Filed Under [ C# .NET Development Google Maps ]

Sunday, February 24, 2013

That darn WinSXS black hole!

As you may know, every Windows installation starting with Vista has a winsxs directory that takes up a lot of space... not a problem when you have a 500GB volume... but a big problem when you have a VPS with only 40GB of space and the winsxs is taking up 12GB!

Just ran across a post on HelpDeskGeek.com that finally actually works for reducing the winsxs directory.

dism /online /cleanup-image /spsuperseded /hidesp 

I can verify that this command works Windows Server 2008R2 and Windows 7.  I don't have a Windows 8 installation yet.  

When I ran this command on my Windows VPS, the server's winsxs directory reduced from 12GB to about 8.5GB now... 

Whew... space feels good!

Posted On Sunday, February 24, 2013 2:47 PM | Comments (0) | Filed Under [ winsxs windows service pack vps hosting ]

Tuesday, January 17, 2012

Style sheet strong arm: Reset.css versus Normalization.css

I have a pet peeve: designers that always start with reset.css stylesheet.  

There are so many flaws with this approach:
  • all styles... all elements, everything, is reset to padding 0, margin 0, font-size: 100% (whatever that means) and so forth.  So utilizing an h1 requires "restyling" an h1 to be somewhat bigger, somewhat bolder than the average text.  And make that bigger and bolder than h2, and likewise h3, and likewise h4, h5, and h6.
  • the css inheritance chain is difficult to navigate.   Since the reset.css touches every single element, and after you've spent time "restyling" every element to have their semantic meaning reflect their visual cues, you end up with many overrides to every style.  IMO this makes it more difficult to hone in on what style is not correct.
The advantages of a reset.css:
  • every element is consistently lame, lacking the visual cue of the semantics of the text
ENTER THE SAVIOR, Normalize.css...
  • It normalizes all elements to reasonable settings.  For example, I've personally noticed that the <abbr> element is displayed differently in Chrome, IE, and Firefox.  Normalize.css effectively makes the <abbr> tag consistent across all the browsers... winning!
  • It tackles bigger problems that were out-of-scope for reset.css, like old browser handling of styles
I would suggest all developers, designers, and HTML gurus to rethink using that reset.css, and look into getting normalize.css and put down that reset.css, reset.css is for losers.

Posted On Tuesday, January 17, 2012 10:32 AM | Comments (0) |

Rejuvenate the blog

Time to rejuvenate the blog.  Many things afoot in the world of developement.

Of note,
  • MVC 4 RC is coming out soon.  Eh, I don't really see much new there.  A couple of interesting additions but like I said... eh.
  • Umbraco 5 RC2 was released.  You can get it at http://umbraco.codeplex.com/.  Umbraco is a very nice CMS that runs on top of ASP.Net, and version 5 has been signifigantly rewritten to run on the MVC framework.  The existing Umbraco 4.7.1 is still a respectable CMS, and there's lots of community-built plugins.

Posted On Tuesday, January 17, 2012 10:21 AM | Comments (1) |

Monday, August 20, 2007

OR/Mappers, your thoughts and NHibernate

Any body using NHibernate?  So far I like it, but it honestly doesn't feel stable.  When running tests, sometimes (sometimes!) the queries that ran fine just before bomb out with

Message: expected in: <end-of-text>

The query executed was "from prf_ProfileSection"... not much else to screw up here, yet the parser fails.  Then, I recompile the DLLs and run and it works again...

Anyhow, the main question for this blog post is what's your favorite OR/M and how flexible and stable is it?

Posted On Monday, August 20, 2007 1:02 PM | Comments (2) |

Monday, July 30, 2007

Edit and Continue annoyance

So now I'm faced with a change that I realize can't be applied... but I really don't want to restart!   Reasons are that to get to this point, I had to step through a lot of code line by line, and I needed to make one slight adjustment...  and I want to save that adjustment, but continue debugging.

I'm surprised many others haven't been annoyed by this...

Register your view on this feedback item:
https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=110163

Posted On Monday, July 30, 2007 12:37 PM | Comments (2) |

Wednesday, July 25, 2007

Can't wait for VSOrcas Beta 2.

Counting the days (til when??) that I will be able to get my hands on the new Beta 2 bits of VS Orcas.

I look forward to actually being able to use LINQ, the split view for ASP.Net designing, and a few other things...  Initializers, lambda's, etc.

Posted On Wednesday, July 25, 2007 2:46 PM | Comments (0) |

CodeSmith NHibernate templates

...Are spitting out invalid markup...  For instance, nhibernate's schema has moved to a version 2.2. whereas CodeSmith's NHibernate templates are still spitting out 2.0...

Anybody worked with them?

Posted On Wednesday, July 25, 2007 2:44 PM | Comments (2) |

Wednesday, July 18, 2007

LINQ's role in the Data Access layer.

After reading this post about LINQ, I think a few people are missing the point of LINQ... LINQ *replaces* any "Data Access layers" that have been created. 

When you build methods in your data access layer, like "GetCustomersByCity," you're actually creating a wierd separation between the data and business layers.  In a sense, you're defining business logic in your data layer.  The important thing to remember, is that your business layer RELIES on the data layer to retrieve and persist entities so the business layer can process them.

LINQ's future

I see the future where LINQ augments our current Data Access layers and eventually most of the hand written code (call into very specificly created stored procedures for data optimization) will become obsolete.

Moving forward, a project would simply use SqlMetal (or any other code-gen engine for that matter) and build the Linq-supporting types into your current Data Access layer.  Then, when you add new business logic components, and upgrade existing business logic code, add the newer LINQ-style access into the business layer. 

Eventually, you'll find that most of the data access handling will be through the LINQ-execution engine, and less and less custom developed code.  

Performance

Of course, there's always a case where a specific method is written to short-circuit some code path for maximum speed... Those particular instances may be better, but frankly, to quote ScottGu's post on LINQ: "LINQ is fast... very fast"

Some other articles about performance with LINQ:

- blogs.msdn.com/mattwar/archive/2007/07/05/linq-to-sql-rico-drops-the-other-shoe.aspx

More to come...

Posted On Wednesday, July 18, 2007 9:42 AM | Comments (3) |

ScottGu and LINQ in VS "Orcas" B2

ScottGu has been busy writing some articles about some of the new features contained in the new Beta 2 bits of Visual Studio "Orcas":

- Part 1: Introduction to LINQ to SQL
- Part 2: Defining our Data Model Classes
- Part 3: Querying our Database
- Part 4: Updating our Database
- Part 5: Binding UI using the ASP:LinqDataSource control

So far, its an interesting read... In particular I like the idea of the <asp:LinqDataSource> control, but I'm not so sure the implementation was correct... 

At first glance, having a "TableName" property for the control seems counter-intuitive to LINQ, since I question how many times would I only use 1 table...?

However, I'd like to reserve judgement until we get our hands on it and can check out the LinqDataSource control for ourselves.

In the mean time, we all have a lot of cool stuff to look forward to!

Posted On Wednesday, July 18, 2007 9:42 AM | Comments (0) |

Thursday, March 1, 2007

BoundField's and domain objects as a data source.

An update to the post about BoundFields not able to bind to nested properties. Hero ScottGu answered back and brought one of the developers into the question. So at least now we've got a ear that can filter through the feedback parsing your words (not to mention that its difficult to use the feedback site... I typically get frustrated with it, and don't even bother to leave a comment) Hopefully I can steer the ASP.Net team into fixing this (ironically probably easy to fix) and yet so basic. ...On another note, I'm rapidly (or as fast as my cable modem can download) pulling down the new VS Orcas Mar 2007 ctp release... supposedly this is the one WITH the new LINQ bits... can't wait

Posted On Thursday, March 1, 2007 5:06 PM | Comments (1) |

Powered by: