Skip to content

Instantly share code, notes, and snippets.

@cprieto
cprieto / Autoreleasepool.m
Last active August 29, 2015 13:57
Samples for retain/release structure
int main(int argc, const char *argv[]) {
// First way, using the language
@autoreleasepool {
// A new pool is created and released outside this, we can nest pools as well
}
// Using the class
NSAutoreleasePool *pool;
pool = [NSAutoreleasePool new];
@cprieto
cprieto / capture.cpp
Last active August 29, 2015 13:57
Sometimes closures are kind of different....
#include "stdafx.h"
#include <stdio.h>
int _tmain(int argc, _TCHAR* argv[])
{
auto banana = 1;
auto func1 = [banana](int i) -> int { return i + banana; };
banana = 5;
auto result = func1(3);
[AcceptVerbs(HttpVerbs.Post)]
public ViewResult Register(Member member, PasswordEntryForm password_entry)
{
Validate(member);
Validate(password_entry);
if (ModelState.IsValid) {
registrationService.RegisterCandidate(member, password_entry.Password);
ControllerContext.HttpContext.Session["candidate_username"] = member.Username;
[ActionName("FirstAction")]
public ActionResult DoSomething(string someValue)
{
}
[ActionName("SecondAction")]
public ActionResult DoOther(string someValue)
{
using System.Collections.Generic;
using System.Web.Mvc;
using Rioshu.Educa.Extensions;
using Rioshu.Educa.Forms;
using Rioshu.Educa.Model;
using Rioshu.Educa.Services;
using Rioshu.Utils;
using Rioshu.Utils.Dbc;
namespace Rioshu.Educa.Controllers
<%@ Page Language="C#" Inherits="MvcContrib.FluentHtml.ModelViewPage<MemberEntryForm>" Culture="auto" %>
<%@ Import Namespace="Rioshu.Educa.HtmlHelpers"%>
<%@ Import Namespace="Rioshu.Educa.Controllers"%>
<%@ Import Namespace="Rioshu.Educa.Forms"%>
<%@ Import Namespace="MvcContrib.FluentHtml" %>
<%@ Import Namespace="Microsoft.Web.Mvc" %>
<!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" >
<head runat="server">
var resizedImage = origImage.ToSize(260);
var jpegEncoder = GetEncoder(ImageFormat.Jpeg);
var qualityEncoder = Encoder.Quality;
var qualityParam = new EncoderParameter(qualityEncoder, 100L);
var parameters = new EncoderParameters(1);
parameters.Param[0] = qualityParam;
// Cambiamos la calidad del jpeg
context.Response.ContentType = "image/jpeg";
public static Image ToSize(this Image image, int width, int height)
{
var resizedImage = new Bitmap(width, height);
using (var graphics = Graphics.FromImage(resizedImage))
{
graphics.DrawImage(image, 0, 0, width, height);
}
return resizedImage;
}
private static ImageCodecInfo GetEncoder(ImageFormat format)
{
var codecs = ImageCodecInfo.GetImageEncoders();
foreach (var codec in codecs) {
if (codec.FormatID == format.Guid) {
return codec;
}
}
return null;
}
public static Image ToSize(this Image image, int width, int height)
{
var resizedImage = new Bitmap(width, height);
using (var graphics = Graphics.FromImage(resizedImage))
{
graphics.SmoothingMode = SmoothingMode.HighQuality;
graphics.CompositingQuality = CompositingQuality.HighQuality;
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
graphics.DrawImage(image, 0, 0, width, height);
}