Skip to content

Instantly share code, notes, and snippets.

View BenjaminAdams's full-sized avatar
🤠
wrangling up the codes at the wild west corral

Benjamin Adams BenjaminAdams

🤠
wrangling up the codes at the wild west corral
  • Austin, Tx
View GitHub Profile
@BenjaminAdams
BenjaminAdams / gist:5258272
Created March 27, 2013 21:40
Problem, we need to trim strings in javascript but its not implemented in all browsers Since new Browsers (IE9+) have trim() already implemented, you should only implement trim() if it is not already available on the Prototype-Object (overriding it is a huge performance hit). This is generally recommended when extending Native Objects! Note that…
if (!String.prototype.trim) {
String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g, '');};
}
@BenjaminAdams
BenjaminAdams / index.html
Created May 31, 2013 17:16
The iframe upload trick - How to upload files without refreshing the page by submitting the file through a hidden iframe.
<div id='status'></div>
<form id="file-upload-form" name="file-upload-form">
<input type="file" id="upload-doc-file" name="upload-doc-file">
</form>
<iframe id="postiframe" name="postiframe"></iframe>
@BenjaminAdams
BenjaminAdams / Split string on words.php
Last active December 19, 2015 17:29
Splitting a string between multiple lines. When you are splitting a string to go on multiple lines we want to split the string where it does not break a word onto different lines. This to to make the string easier to read. In this example I was generating a PDF and needed to split a title of something onto 3 different lines so the text did not s…
public function split_title($title,$maxStr)
{
$newStr = Array();
$maxLines=3;
$lineNum = 1; //to be line 1,2, or 3
$split = explode ( " ", $title);
foreach($split as $str)
{
@BenjaminAdams
BenjaminAdams / main.js
Created September 29, 2013 20:04
How to properly serialize a form into a javascript object
var data = {};
$(".form-selector").serializeArray().map(function(x){data[x.name] = x.value;})
@BenjaminAdams
BenjaminAdams / upload.js
Created October 1, 2013 07:15
Upload image and/or a file with Javascript
uploadImg: function(file, imgPreview, imgUrl) {
var self = this
console.log('file=', file)
imgPreview.html('<i class="icon-spinner icon-spin"></i>')
imgUrl.val('')
reader = new FileReader();
reader.onload = (function(tFile) {
return function(evt, response) {
@BenjaminAdams
BenjaminAdams / css-nav-tabs.html
Last active August 29, 2015 14:01
Pure CSS tabs with checkbox hack
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US">
<head></head><body>
<style>
.tab-area p {
font-size: 11px;
color: #666;
}
@BenjaminAdams
BenjaminAdams / dyamicGroupBy
Last active August 14, 2019 00:12
c# doing dynamic GroupBy clause with Linq to SQL
using System.Linq;
using System.Linq.Dynamic;
using System.Linq.Expressions;
ParameterExpression p = Expression.Parameter(typeof(SomeEfClass), "p");
var selector = Expression.Lambda < Func < SomeEfClass,
string >> (Expression.Property(p, input.requestedField), p);
@BenjaminAdams
BenjaminAdams / creditCard.sql
Last active March 1, 2022 19:04
Search a SQL server field for a creditcard number
SET ROWCOUNT 10000
SELECT SomeField
FROM tablename
WHERE patindex('%[3|4|5|6][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]%',SomeField) > 0
or to get the unique numbers
SET ROWCOUNT 50
SELECT distinct SUBSTRING (SomeField ,patindex('%[3|4|5|6][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]%',SomeField) , 12 )
@BenjaminAdams
BenjaminAdams / FemaleNames.js
Created July 7, 2015 21:31
Male and female names in an array
var femaleNames = ["Emily","Hannah","Madison","Ashley","Sarah","Alexis","Samantha","Jessica","Elizabeth","Taylor","Lauren","Alyssa","Kayla","Abigail","Brianna","Olivia","Emma","Megan","Grace","Victoria","Rachel","Anna","Sydney","Destiny","Morgan","Jennifer","Jasmine","Haley","Julia","Kaitlyn","Nicole","Amanda","Katherine","Natalie","Hailey","Alexandra","Savannah","Chloe","Rebecca","Stephanie","Maria","Sophia","Mackenzie","Allison","Isabella","Amber","Mary","Danielle","Gabrielle","Jordan","Brooke","Michelle","Sierra","Katelyn","Andrea","Madeline","Sara","Kimberly","Courtney","Erin","Brittany","Vanessa","Jenna","Jacqueline","Caroline","Faith","Makayla","Bailey","Paige","Shelby","Melissa","Kaylee","Christina","Trinity","Mariah","Caitlin","Autumn","Marissa","Breanna","Angela","Catherine","Zoe","Briana","Jada","Laura","Claire","Alexa","Kelsey","Kathryn","Leslie","Alexandria","Sabrina","Mia","Isabel","Molly","Leah","Katie","Gabriella","Cheyenne","Cassandra","Tiffany","Erica","Lindsey","Kylie","Amy","Diana","Cassidy
using System;
using Moq;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Linq.Expressions;
namespace SuperImportantNamespace.Tests.Data
{
public static class EntityFrameworkMockHelper