Skip to content

Instantly share code, notes, and snippets.

View forcewake's full-sized avatar

Pavel Nasovich forcewake

View GitHub Profile
public class Upload
{
public string Name { get; set; }
[FileSize(655360)]
[FileTypes("jpg,jpeg,png")]
public HttpPostedFileBase File { get; set; }
}
[HttpPost]
[Authorize]
@forcewake
forcewake / Wat.js
Created February 20, 2013 07:50
Что в итоге? :)
var a = 1, b = 4, c = 2;
c+=a++ + +b.toString() + ++a;
namespace MvcBootest.Helpers
{
public class TagsHelper
{
public IList<string> GetTags(string message)
{
return
message.Split(' ').Where(word => word.StartsWith("#")).Select(word => word.Substring(1)).Select(
newTagValue => new Tag
{
@forcewake
forcewake / InMemoryCache.cs
Created February 28, 2013 21:48
Usage: cacheProvider.Get("cache id", (delegate method if cache is empty)); Cache provider will check if there's anything by the name of "cache id" in the cache, and if there's not, it will call a delegate method to fetch data and store it in cache. Example: var products=cacheService.Get("catalog.products", ()=>productRepository.GetAll())
public class InMemoryCache: ICacheService
{
public T Get<T>(string cacheID, Func<T> getItemCallback) where T : class
{
T item = HttpRuntime.Cache.Get(cacheID) as T;
if (item == null)
{
item = getItemCallback();
HttpContext.Current.Cache.Insert(cacheID,item);
}
using Mvc4SampleApplication.Filters;
using System.Web;
using System.Web.Security;
using WebMatrix.WebData;
[assembly: PreApplicationStartMethod(typeof(PreApplicationTasks), "Initializer")]
public static class PreApplicationTasks
{
public static void Initializer()
<div class="span4 well">
<form accept-charset="UTF-8" action="" method="POST">
<textarea class="span4" id="new_message" name="new_message" placeholder="Type in your message" rows="5"></textarea>
<h6 class="pull-right">140 characters remaining</h6>
<p>
<button class="btn btn-primary btn-small" type="submit">
Post Message</button>
<a class="btn btn-small" id="addImage">Show add image</a>
</p>
<div class="fileupload fileupload-new" data-provides="fileupload" style="display: none;"
int length = strA.Length;
if (length != strB.Length)
return false;
fixed (char* chPtr1 = &strA.m_firstChar)
fixed (char* chPtr2 = &strB.m_firstChar)
{
char* chPtr3 = chPtr1;
char* chPtr4 = chPtr2;
while (length >= 10)
{
@forcewake
forcewake / Convertors.cs
Last active December 16, 2015 01:39
XML deserialiser
using System.Collections.Generic;
using System.IO;
using System.Xml;
using System.Xml.Serialization;
namespace ConvertorApplication
{
public class Convertors
{
/// <summary>
@forcewake
forcewake / DeleteFromRow.cs
Created May 29, 2013 09:35
Delete rows from the table from dataset
if (oDs.Tables.Count > 1)
{
oDs.Tables[1].Rows.Cast<DataRow>()
.Where(r =>
r["first"].ToString() == "0" ||
r["second"].ToString() == "5" ||
r["third"].ToString() == "000")
.ToList()
.ForEach(row =>
{
[SuppressUnmanagedCodeSecurity]
internal static class SafeNativeMethods
{
[DllImport("shlwapi.dll", CharSet = CharSet.Unicode)]
public static extern int StrCmpLogicalW(string psz1, string psz2);
}
public sealed class NaturalStringComparer : IComparer<string>
{
public int Compare(string a, string b)