Skip to content

Instantly share code, notes, and snippets.

@dmix
Created March 28, 2012 02:25
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmix/2222990 to your computer and use it in GitHub Desktop.
Save dmix/2222990 to your computer and use it in GitHub Desktop.
coffeescript to read/write to cookies
App.Functions.readCookie = (name) ->
nameEQ = name + "="
ca = document.cookie.split(";")
i = 0
while i < ca.length
c = ca[i]
c = c.substring(1, c.length) while c.charAt(0) is " "
return c.substring(nameEQ.length, c.length).replace(/"/g, '') if c.indexOf(nameEQ) is 0
i++
ca
App.Functions.setCookie = (cookieName, cookieValue) ->
today = new Date()
expire = new Date("2015-01-01 12:00:00")
document.cookie = cookieName + "=" + escape(cookieValue) + ";expires=" + expire.toGMTString();
@sampsakuronen
Copy link

Did you forget a semicolon to the end on line 15?

@scottillogical
Copy link

aren't semicolons optional in coffeescript? :p

@strindhaug
Copy link

Why did you hardcode the expiration to expire a week ago?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment