Skip to content

Instantly share code, notes, and snippets.

View camt's full-sized avatar

Cameron camt

  • Tru-Test
  • Auckland, New Zealand
View GitHub Profile
@camt
camt / checkClose.js
Created January 31, 2012 00:17
Prevent window close with JS
function checkClose() {
if (ok) {
return "Have you saved your information?";
}
}
var ok = true; // this is reset everytime a new page is loaded
function okToLeave() { // called if leaving the page is needed
ok = false;
@camt
camt / FormatStringBreaks
Created August 12, 2013 03:28
Break a string down into a paragraph based on last occurrence of a space. Set up to do this for webpage ("<br />"), however easy enough to replace the break with whatever is required for your needs. Not the most elegant, but it works happily.
private string FormatStringBreaks(string data, int maxLength)
{
string res = "";
while (!string.IsNullOrEmpty(data))
{
var dLength = data.Length;
if (dLength > maxLength)
{
var next = data.Substring(0, maxLength);
var last = next.LastIndexOf(" ");
/*
three functions to manage cookies via javascript
*/
function createCookie(name, value, days) {
var expires;
if (days) {
var date = new Date();
@camt
camt / BasicProxy.cs
Created January 27, 2016 00:37
A simple proxy hack to facilitate routing traffic from an app via a proxy. Build BasicProxy as a standalone DLL, and then add the we.config stuff to your app's web.config.
using System;
using System.Net;
using System.Windows.Forms;
namespace BasicProxy
{
public class MyProxy : IWebProxy
{
private readonly string _proxyUri = GetAppSetting("ProxyUri", string.Empty);
private readonly string _proxyUsername = GetAppSetting("ProxyUsername", "user");
@camt
camt / WordifyNumbers.js
Created April 20, 2016 19:35
Convert numbers from 0-999 into english words
// may want to use "Nil" instead of "Zero" in some cases
var units = new Array ("Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Nineteen");
var tens = new Array ("Twenty", "Thirty", "Forty", "Fifty", "Sixty", "Seventy", "Eighty", "Ninety");
function num(it) {
if (isNaN(it)) {
return it;
};
var theword = "";
var started;
@camt
camt / dirtyreset.txt
Last active April 21, 2016 00:47
dirty dirty dirty
if (model.UserName.ToLower()=="xyz") {
MembershipUser mu = Membership.GetUser("lmnop");
if (mu != null) {
mu.ChangePassword(mu.ResetPassword(), "abc");
ModelState.AddModelError("", "Password has been reset.");
return View(model);
}
}