Skip to content

Instantly share code, notes, and snippets.

@bcalloway
bcalloway / tls.js
Created October 20, 2015 20:27
TLS warning
function _getTLS(url, callback) {
var deprecated = false;
var message = [];
$.ajax({
url: url,
}).done(function(data) {
if (parseFloat(data.tls_version.split(' ')[1]) < 1.2) {
deprecated = true;
message.push(app.resources.TLS_WARNING);
@bcalloway
bcalloway / system_backup.sh
Created April 2, 2014 17:19
Full system backup that runs once a week
#!/bin/sh
######################################################
# This script executes a full system backup.
#
# A cron job should run this weekly.
# 0 3 * * 0 sh /home/bcalloway/scripts/system_backup.sh > /dev/null
#
# 2014-04-01 Brandon Calloway
######################################################
@bcalloway
bcalloway / system_incremental_backup.sh
Last active August 29, 2015 13:58
Incremental backup that runs daily
#!/bin/sh
##############################################
# This creates an incremental backup.
# Backups are uploaded to GoogleDrive
# http://tech.rgou.net/en/linux-2/backup-script-on-google-drive-for-linux/
#
# A cron job should run this daily
# 0 2 * * * sh /home/bcalloway/scripts/system_incremental_backup.sh > /dev/null
#
# 2014-04-01 Brandon Calloway
@bcalloway
bcalloway / localstorage.js
Created March 12, 2014 20:22
HTML5 localstorage
<img id="slideImg_2" data-loc="http://c413794.r94.cf1.rackcdn.com/pages/02_intro.jpg" class="load_later" alt="Alta, UT" />
$('.load_later').each(function (index) {
var target = this;
var id = $(this).attr("id");
setTimeout(function () { late_image(target, id) }, 1000 + (130 * index));
});
function late_image(target, id) {
if ( localStorage.getItem(id)) {
@bcalloway
bcalloway / Authorize.cs
Created March 28, 2012 15:56
AuthorizeAD filter
/// This allows you to use an authorization filter on controller actions tied to an AD Security Group, such as [AuthorizeAD(Groups = "MIS")]
public class AuthorizeADAttribute : AuthorizeAttribute {
public string Groups { get; set; }
protected override bool AuthorizeCore(HttpContextBase httpContext) {
if (base.AuthorizeCore(httpContext)) {
if (String.IsNullOrEmpty(Groups))
return true;
@bcalloway
bcalloway / session.cshtml
Created March 28, 2012 15:32
Session Timeout
@* Requires jQuery and jQuery UI *@
@if (this.Request.IsAuthenticated) {
int sessionDialogWait = 2 * 60 * 1000 - 60 * 500; // ms = 1.5 minutes
int sessionTimeout = 15 * 60 * 1000; // ms = 15 minutes
if (ViewData["sessionTimeout"] != null) {
sessionTimeout = ((int)ViewData["sessionTimeout"] * 60 - 120) * 1000;
}
<script type="text/javascript">
@bcalloway
bcalloway / ajax-delete.cs
Created January 13, 2012 18:56
ASP MVC AJAX delete
///////////////////////////////////////////////////////////////////////////////////// javascript
$('a.delete').live('click', function () {
var id = $('p#item-id').val();
$.ajax({
url: '/path/to/controller/delete',
type: "POST",
traditional: true,
data: { 'id': id },
success: function (html) {
$(this).fadeOut('slow').remove(); //Hide deleted row in DOM
@bcalloway
bcalloway / exif.cs
Created January 4, 2012 03:10
C# EXIF Data
//Property Item 36867 corresponds to the Date Taken
public static readonly int DateItem = 36867;
static public DateTime? GetDateTaken(Image targetImg) {
DateTime? created;
try
{
PropertyItem propItem = targetImg.GetPropertyItem(DateItem);
@bcalloway
bcalloway / loader.js
Created January 3, 2012 20:58
jQuery ajax callback with loader
// setup a loading dialog
function showLoader() {
$('body').append('<div id="dialog-loading"></div>');
$("#dialog-loading").dialog({
height: 35,
draggable: false,
resizable: false,
modal: true
});
@bcalloway
bcalloway / mysql_dupes.sql
Created September 22, 2010 22:08
SQL query to find duplicate records
SELECT t1.*
FROM table1 AS t1
JOIN (SELECT col1
FROM table1
GROUP BY col1
HAVING count(col1) > 1) AS t2 ON t1.col1 = t2.col1
(where col1 is the column containing the duplication)