405 error when POSTing to ASMX using jQuery?

The method has to be decorated with [WebInvoke] to enable POST method.

[WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest)]

If it is asmx, include the below protocols in web.config

        <add name="HttpGet"/>
        <add name="HttpPost"/>

in system.web

Also, decorate the web method with [scriptmethod] to be accessed from script

Fixing blank shared screen with Microsoft Lync

Perhaps you’re able to share your screen, but whenever you look at a shared screen all you see is a big block of white. If you are comfortable using powershell, run this command to enable the ActiveX control that is being blocked.

Set-ItemProperty -Path “HKLM:\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\ActiveX Compatibility\{00000000-0000-0000-0000-000000000000}” -Name “Compatibility Flags” -Value 8388608

How can I create a Cygwin shortcut that will open Cygwin at a specific folder?

When you install Cygwin (or if you’ve already installed it, download it again and start setup again to run an update), make sure that you select the chere package under the “Shells” category.

After Cygwin is launched, open up a command shell and type the command: chere -i.

Now you should have “Bash Prompt Here” in the Windows right-click context menu.

You can also specify the terminal you want to open using -t, e.g., to open mintty you use chere -i -t mintty

Via: https://stackoverflow.com/questions/9637601/open-cygwin-at-a-specific-folder

iframes and cross-domain access

Q: Can a page inside an iframe “see” cross domain to gather info about  the iframe element itself (e.g. is visible or not)?

A: If they are both on the same high level domain (e.g. foo.example.com and bar.example.com) you can set document.domain in JavaScript.

document.domain = 'example.com';

This will allow cross frame communication.

If they are on different domains you would need to use window.postMessage in order to communicate cross frame. Something like:

The page B (iframe content):

 top.postMessage('hello', 'A');


Note the use of top.postMessage or parent.postMessage not window.postMessage here

The page A:

 <iframe src="B"></iframe>
 window.addEventListener( "message",
 function (e) {
 if(e.origin !== 'B'){ return; } 

Q: Is there a foolproof way to detect if iframe is cross domain?

A: Yes.

function canAccessIFrame(iframe) {
 var html = null;
 try { 
 // deal with older browsers
 var doc = iframe.contentDocument || iframe.contentWindow.document;
 html = doc.body.innerHTML;
 } catch(err){
 // do nothing

 return(html !== null);

So something like:

var accessAllowed = canAccessIFrame(document.getElementsByTagName('iframe')[0]);

Add a User to the Sudoers File in Mac OS X

  • Launch Terminal and type the following command:
sudo visudo
  • Use the arrow keys to navigate down to the “#User privilege specification” section, it should look like this:
# User privilege specification
root ALL=(ALL) ALL
%admin ALL=(ALL) ALL
  • Put the cursor on the next empty line below the %admin entry and then press the “A” key to insert text, then type the following on a new line, replacing ‘username’ with the users short name of the account you wish to grant privilege to (hit tab between username and ALL):
username ALL=(ALL) ALL
  1. Now hit the “ESC” (escape) key to stop editing the file
  2. Hit the : key (colon) and then type “wq” followed by the Return key to save changes and exit vi

User added to the sudoers file in OS X

You should be good to go, check to be sure:

< /etc/sudoers

Or iff you don’t want to scan through the entire file:

grep username < /etc/sudoers

Collapsing directories

Often I get a handoff where there are single files (or a few files) I need from each of a collection of dozens or hundreds of folders. So I’ll often want to “collapse” a directory of subdirectories, isolating all contained files (or a subset) in the parent directory or a new subdirectory.

In bash:

find /foo -iname '*.txt' -exec cp \{\} /dest/ \;

find will find all the files under the path /foo matching the wildcard *.txt, case insensitively (That’s what -iname means). For each file, find will execute cp {} /dest/, with the found file in place of {}.

You can also do this with GNU find and GNU mv:

find /dir1 -mindepth 2 -type f -exec mv -t /dir1 -i '{}' +

Basically, the way that works if that find goes through the entire directory tree and for each file (-type f) that is not in the top-level directory (-mindepth 2), it runs a mv to move it to the directory you want (-exec mv … +). The -t argument to mv lets you specify the destination directory first, which is needed because the + form of -exec puts all the source locations at the end of the command.

Translating Programmer Speak

Doing some research on writing QA Test Cases at the erstwhile SoftwareQATest.com, and stumbled on this nugget:

(On the topic of “Why does software have bugs?”)

egos – people prefer to say things like:

  • ‘no problem’
  • ‘piece of cake’
  • ‘I can whip that out in a few hours’
  • ‘it should be easy to update that old code’

instead of:

  • ‘that adds a lot of complexity and we could end up making a lot of mistakes’
  • ‘we have no idea if we can do that; we’ll wing it’
  • ‘I can’t estimate how long it will take, until I take a close look at it’
  • ‘we can’t figure out what that old spaghetti code did in the first place’

If there are too many unrealistic ‘no problem’s’, the result is bugs.

Man, this is really too real, and how many times do I say these very things? Every project I think.

contains() method polyfill

The contains() method determines whether one string may be found within another string, returning true or false as appropriate. Currently, this is an experimental technology, part of the Harmony (EcmaScript 6) proposal, so syntax, functionality etc could very well change.

However, its a handy String Prototype to add, especially when you are trying to test if a URI contains another URI or URI part. You might well ask, why not just pass the directory string to the RegExp constructor? Yeah, have fun with that and all the wonderfull escaping and unescaping you’ll need to do with those backslashes, periods, etc.

Here ’tis;

if (!('contains' in String.prototype)) {
  String.prototype.contains = function(str, startIndex) {
    return -1 !== String.prototype.indexOf.call(this, str, startIndex);