Skip to content

Instantly share code, notes, and snippets.

View cilerler's full-sized avatar
:octocat:

Cengiz Ilerler cilerler

:octocat:
View GitHub Profile
public class UsingDisplayAttributeOnEnum
{
private void Main()
{
IEnumerable<SelectListItem> result = typeof (Genre).GetItems();
}
}
public enum Genre
{
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace Gists
{
public partial class Utilities
{
public void Main()
{
@cilerler
cilerler / aspMerger.cs
Created December 20, 2013 19:47
Searches for "#include virtual=" in ASP pages and merges into single output
static void Main(string[] args)
{
const string root = @"C:\aspProjects\";
const string path = @"Folder1\Page1.asp";
File.WriteAllText(@"C:\combined.asp", GetLines(root, path, true));
Console.WriteLine("{0} include files processed.", _counter);
}
private static int _counter;
private static string GetLines(string root, string path, bool includePath = false)
String.prototype.Trim = function(trimCharacter) {
var start = 0;
var end = this.length;
if (this.indexOf(trimCharacter) === 0) start = 1;
if (this.lastIndexOf(trimCharacter) == this.length - 1) end = this.length - 1;
var trimmedData = this.slice(start, end);
return trimmedData;
};
String.prototype.TrimStart = function trimStart(trimCharacter) {
CREATE FUNCTION [dbo].[Split] ( @delimiter VARCHAR(2), @string VARCHAR(max))
RETURNS @table TABLE ( value VARCHAR(max) )
BEGIN
DECLARE @nextString VARCHAR(max)
DECLARE @position INT, @nextPosition INT
SET @nextString = ''
SET @string = @string + @delimiter
SET @position = charindex(@delimiter, @string)
/*
RESULT
======
Adding two values: 16
Subtracting two values: 6
*/
void Main()
{
//creating the class which contains the methods
/*
RESULT
======
Received event. Shape area is now 10201.86
Drawing a circle
Received event. Shape area is now 49
Drawing a rectangle
Press enter to exit.
*/
@cilerler
cilerler / gist:4018138
Created November 5, 2012 16:32
ToJavaScript and FromJavaScript
using System;
public static class DateTimeConverters
{
public static long ToJavaScript(this DateTime value)
{
var epoch = new TimeSpan(new DateTime(1970, 1, 1, 0, 0, 0, 0).Ticks);
DateTime time = value.Subtract(epoch);
return (time.Ticks / 10000);
}
@cilerler
cilerler / gist:4018087
Created November 5, 2012 16:22
Combine Date and Time
using System;
public static class DateTimeConverters
{
public static DateTime CombineDateAndTime(DateTime dateValue, DateTime timeValue)
{
return new DateTime(dateValue.Year, dateValue.Month, dateValue.Day, timeValue.Hour, timeValue.Minute, timeValue.Second);
}
}
@cilerler
cilerler / gist:4018015
Created November 5, 2012 16:09
SplitCrLf via RegEx
// resource https://gist.github.com/4017806
using System;
using System.Text.RegularExpressions;
public static class StringConverters
{
public static string[] SplitCrLf(this string input)
{
return new Regex(string.Format("{0}?{1}", ControlChars.CarriageReturn, ControlChars.LineFeed)).Split(input);