Skip to content

Instantly share code, notes, and snippets.

Cameron camt

  • Tru-Test
  • Auckland, New Zealand
View GitHub Profile
@camt
camt / dirtyreset.txt
Last active Apr 21, 2016
dirty dirty dirty
View dirtyreset.txt
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);
}
}
@camt
camt / WordifyNumbers.js
Created Apr 20, 2016
Convert numbers from 0-999 into english words
View WordifyNumbers.js
// 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 / BasicProxy.cs
Created Jan 27, 2016
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.
View BasicProxy.cs
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");
View cookies.js
/*
three functions to manage cookies via javascript
*/
function createCookie(name, value, days) {
var expires;
if (days) {
var date = new Date();
@camt
camt / FormatStringBreaks
Created Aug 12, 2013
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.
View FormatStringBreaks
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(" ");
@camt
camt / distance.php
Created Jan 31, 2012
Calculate distance between coordinates
View distance.php
function distance($lat1, $lon1, $lat2, $lon2, $unit) {
$theta = $lon1 - $lon2;
$dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) + cos(deg2rad($lat1)) *
cos(deg2rad($lat2)) * cos(deg2rad($theta));
$dist = acos($dist);
$dist = rad2deg($dist);
$miles = $dist * 60 * 1.1515;
$unit = strtoupper($unit);
@camt
camt / removeChars.php
Created Jan 31, 2012
Strip 'X' end characters from a string with PHP. This is faster for longer strings, as it does not need to count it's way to the end of the string first.
View removeChars.php
$string = strrev(substr(strrev($string), 2));
@camt
camt / clientSide.php
Created Jan 31, 2012
Client-side time with PHP and JS
View clientSide.php
if(!$_REQUEST["client_time"])
{
$vars = "?";
foreach($_REQUEST as $key => $val) {
$vars .= $key."=".$val."&";
}
echo "<script type=\"text/javascript\">";
echo "localtime = new Date();";
echo "document.location.href = '".$PHP_SELF.$vars."client_time='
+ localtime.getTime();";
@camt
camt / checkClose.js
Created Jan 31, 2012
Prevent window close with JS
View checkClose.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 / RandomAlphaString.cs
Created Jan 31, 2012
simple random alpha char string variable in C#
View RandomAlphaString.cs
private const int _length = 15;
private static string RandomAlphaString {
get {
var ret = "";
var random = new Random();
while (ret.Length < _length)
if (random.Next(1, 9) % 2 == 0)
ret = ret + Convert.ToChar(random.Next(65, 90));
else
ret = ret + Convert.ToChar(random.Next(97, 122));
You can’t perform that action at this time.