Skip to content

Instantly share code, notes, and snippets.

@Boztown
Boztown / gist:6677666
Created September 23, 2013 22:11
jCrop center selection
var x = 50;
var y = 50;
var x1 = jQuery('#cropper img').width() - 100;
var y1 = jQuery('#cropper img').height() - 100;
jQuery('#cropper img').Jcrop({
aspectRatio: 1,
setSelect: [ x, y, x1, y1 ]
});
@Boztown
Boztown / gist:7740769
Created December 1, 2013 21:05
Wordpress: Delete attachments after a custom post type is deleted.
function handle_delete_listing( $post_id )
{
$cargs = array(
'post_type' => 'attachment',
'post_parent' => $post_id
);
$attachments = get_children($cargs);
if ($attachments) {
@model ViewModels.CollectionViewModel
@{
Layout = “~/Views/Shared/Layout.cshtml”;
}
@section AdditionalHeadContent {
<script>
$(document).ready(function () {});
@model ViewModels.CollectionViewModel
@{
string actionKeyword = ViewData["ActionKeyword"].ToString();
}
@using (Html.BeginForm("edit", "collection", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
<label class="control-label">Name:</label>
[HttpPost]
public ActionResult Edit(CollectionViewModel model)
{
if (ModelState.IsValid)
{
var id = _collectionModel.Save(model);
}
return View(model);
}
public int Save(CollectionViewModel collectionModel)
{
var collection = collectionModel.Id.HasValue ? _collectionRepository.Get(collectionModel.Id.Value) : new Collection();
collection.Name = collectionModel.Name;
collection.Published = collectionModel.Published;
collection.Featured = collectionModel.Featured;
collection.Description = collectionModel.Description;
_collectionRepository.Save(collection);
return collection.Id;
// if our viewmodel has an ID then grab that entity... otherwise create a new one
var collection = collectionDto.Id.HasValue ? _collectionRepository.Get(collectionDto.Id.Value) : new Collection();
@Boztown
Boztown / ImageProcessingUtility.cs
Last active July 19, 2019 10:47
Here's a little function in C# to resize an image with proportional constraints. Just specific the max width and max height and this method will return a bitmap all sized up for you. I have this snipped in the form of a static **Utilities** class because that's how I use it.
using System;
using System.Collections.Generic;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Linq;
using System.Web;
using System.Drawing;
namespace Utilities
{