Setting a cookie to expire in javascript

cookietimeAdding and setting a cookie via javascript is pretty simple. Sometimes you want the cookie to expire in a certain amount of time, below is the method is use to calculate an expiration:

//create a date object
var date = new Date();
//add the current date + some seconds 
//(below I add 300 seconds or 5 minutes). 
//The 1000 is milliseconds
 date.setTime(date.getTime() + (300 * 1000));
//convert the future date to universal time
var expires = date.toUTCString();
//set the cookie using whatever method / function you choose.
setCookie('cookiename', 'cookievalue', expires);

For the fun of it, below is the function I use to set cookies:

function setCookie(cname, cvalue, expires) {
 document.cookie = cname + "=" + escape(cvalue) +
 ((expires) ? "; expires=" + expires : "");
}

And since we’re talking about cookies, here is a collection of great cookies recipes you can actually eat!

Setting a cookie to expire in javascript

WordPress Multisite Windows / IIS Login Redirect / Loop Issue

wp_logoIf you have WordPress installed on Windows (2008 / IIS) with multisite + sub domains enabled you may have run into the issue of login loops / redirects when  accessing /wp-admin. Below are a few spots you may want to confirm you have the correct URLs:

In the database:

Table / Field

wp_blogs / domain
wp_options / siteurl
wp_options / home
wp_sitemeta / siteurl    (don't forget this one!)

Also check these tables in any additional sites (ie: wp_2_options).

Config Files
wp-config.php:

define('DOMAIN_CURRENT_SITE', 'www.yourdomain.com');

I also have this in my wp-config.php:

define('ADMIN_COOKIE_PATH', '/');
define('COOKIE_DOMAIN', '');
define('COOKIEPATH', '');
define('SITECOOKIEPATH', '');

Web Config
Below is my successful web.config

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="WordPress Rule 1" stopProcessing="true">
          <match url="^index\.php$" ignoreCase="false" />
          <action type="None" />
        </rule>
        <rule name="WordPress Rule 2" stopProcessing="true">
          <match url="^([_0-9a-zA-Z-]+/)?wp-admin$" ignoreCase="false" />
          <action type="Redirect" url="{R:1}wp-admin/" redirectType="Permanent" />
        </rule>
        <rule name="WordPress Rule 3" stopProcessing="true">
          <match url="^" ignoreCase="false" />
          <conditions logicalGrouping="MatchAny">
            <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" />
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" />
          </conditions>
          <action type="None" />
        </rule>
        <rule name="WordPress Rule 4" stopProcessing="true">
          <match url="^" ignoreCase="false" />
          <conditions logicalGrouping="MatchAny">
            <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" />
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" />
            <add input="{URL}" pattern="([a-zA-Z0-9\./_-]+)\.axd" />
          </conditions>
          <action type="None" />
        </rule>
        <rule name="WordPress Rule 5" stopProcessing="true">
          <match url="^[_0-9a-zA-Z-]+/(wp-(content|admin|includes).*)" ignoreCase="false" />
          <action type="Rewrite" url="{R:1}" />
        </rule>
        <rule name="WordPress Rule 6" stopProcessing="true">
          <match url="." ignoreCase="false" />
          <action type="Rewrite" url="index.php" />
        </rule>
      </rules>
    </rewrite>
    <httpRedirect enabled="false" destination="http://www.yourdomain.com" />
  </system.webServer>
</configuration>
WordPress Multisite Windows / IIS Login Redirect / Loop Issue

Google Analytics Custom Report Filters – RegEx

google_analytics_logoIf you’ve noticed, Google Analytics doesn’t seem to allow you to filter on standard reports using multiple dimensions if you’re only showing one. You can easily create a custom report and add your filters using multiple dimensions and only show one. However, many users get scared by the RegEx option under Filters (the only other choice is Exact). It’s not that complex, below is a simple example showing multiple filters using a simple RegEx ‘contains’. Continue reading “Google Analytics Custom Report Filters – RegEx”

Google Analytics Custom Report Filters – RegEx

Disable ‘Compatibility Mode’ in Internet Explorer (IE) 8 / 9

compatibilty-modeOver the past few months you put tons of time and effort into your awesome new site. However, your roll it live and find out that someone accidentally has Compatibility Mode mode in IE turned on. Now your scripts don’t function exactly how you imagined and your layout is acting funky. There are some Meta tags that apparently take care of this if you add them to your page (<meta http-equiv=”X-UA-Compatible” content=”IE=edge,chrome=1″ />) but personally I haven’t had great success with these. Below is the way I found best in .net to disable and turn off Compatibility Mode in IE:

On your page (preferably master page in web forms or mvc) add this line:

<% Response.AddHeader(“X-UA-Compatible”, “IE=edge,chrome=1”); %>

In my case I’m adding it below the <%@ Master Language=”C#” … line before the start of content (doctype).

Update: You can also easily add the header in IIS (no need to update your code) by going to ‘http response headers’ and choosing ‘add’:

iis_comp-view

 

 

 

Disable ‘Compatibility Mode’ in Internet Explorer (IE) 8 / 9

Twilio SMS Messages In Non-web .net Application with Twilio REST API (c#)

cell-phoneTwilio is a great SMS (text message) gateway to use for sending and receiving SMS messages. The process is super simple and flexible to get started using (the Twilio REST API helper library is great). However, in my case, I wanted to access the API through a “windows form” application, but the API needs a little something extra to get this to function. In my experience, a proxy. Below are the steps from start to finish to retrieve messages from your Twilio account: Continue reading “Twilio SMS Messages In Non-web .net Application with Twilio REST API (c#)”

Twilio SMS Messages In Non-web .net Application with Twilio REST API (c#)

Retrieving and Sending Email using Exchange Web Services Managed API 2.0 (c#)

exlogoIf you haven’t already had the need, I’m sure you will at some point, to either retrieve email or send email through Exchange (not just relay or connect to Outlook) using .net. Since Microsoft introduced the Microsoft Exchange Web Services Managed API 2.0 this task has become much more efficient No more clunky 2.0 type web service references etc. Below is a complete chuck of code with a few samples. One sample function sends an email, the other retrieves email messages from an inbox with the option of filters.

Continue reading “Retrieving and Sending Email using Exchange Web Services Managed API 2.0 (c#)”

Retrieving and Sending Email using Exchange Web Services Managed API 2.0 (c#)

Windows Drive Compression – Reducing Image Size of VMWare Workstation Virtual Machines

If you’re like me, I’m sure you have more than one virtual machine setup and running Windows (in my case, 4 VM’s running Windows Server 2008 R2 – on a laptop [yes an older laptop]). As you already know, Windows Server 2008, besides being AWESOME, is also DISK HOG. Sure, you could install only the Core, but that’s no fun!

One solution to reduce the amount of disk space is the use the Windows drive compression for large files and directories. Of course this takes a small performance hit (in my case, about 10% probably, but it’s for development anyhow) – (read the Microsoft best practices for compression), but you’ll be able to regain space, and better utilize your VM’s!

I compressed some major folders, and was able to regain a few gigs!

Enhanced by Zemanta
Windows Drive Compression – Reducing Image Size of VMWare Workstation Virtual Machines

Corona Cider – Corona IDE

Just a heads up, if you’re running 64 bit Windows and only have the 64 bit java sdk installed, you’ll get an error when running the IDE. To cure, download the 32 bit version of the java sdk (1.6) and install. Seems good now!

Java download:

http://www.oracle.com/technetwork/java/javase/downloads/jdk-6u32-downloads-1594644.html

Corona Cider IDE:

http://www.mydevelopersgames.com/CIDER/

 

More Cider info to follow shortly!

Corona Cider – Corona IDE

Setting up port forwarding in VMWare Workstation 8

To setup port forwarding (maybe you have IIS or Apache running in a VM and want to access from other machines or the host).

If you vm is setup with NAT like this:

…You can go to “Edit > Virtual Network Editor”, this brings up this:

If you choose “NAT” network type, and click “NAT Settings”, you can configure port forwarding like this:

Enter your port, VM IP, etc. Click “OK” a bunch of times and you should be good. Don’t forget about firewalls on the host and VM.

 

Setting up port forwarding in VMWare Workstation 8