Skip to content

Instantly share code, notes, and snippets.

View cilerler's full-sized avatar
:octocat:

Cengiz Ilerler cilerler

:octocat:
View GitHub Profile
// resource https://raw.github.com/padolsey/prettyPrint.js/master/prettyprint.js
var Debug = {
Setup: function() {
var debugDivId = "debug";
if (document.getElementById(debugDivId) === null || document.getElementById(debugDivId) === 'undefined') {
var div = document.createElement('div');
div.id = debugDivId;
div.style.position = "absolute";
div.style.zIndex = "9999";
@cilerler
cilerler / ci-helpers-date.js
Created November 1, 2012 13:14
ToOADate and FromOADate
var oaDate = new Date(1899, 11, 30);
var millisecondsOfaDay = 24 * 60 * 60 * 1000;
Date.prototype.ToOADate = function() {
var result = (Date.parse(this) - Date.parse(oaDate)) / millisecondsOfaDay;
return result;
};
Number.prototype.FromOADate = function() {
var result = new Date();
@cilerler
cilerler / hg-helpers-svg.js
Created November 1, 2012 14:38
SVG to PNG and fix for Raphael SVG
// resource http://www.phpied.com/rgb-color-parser-in-javascript/
// resource http://code.google.com/p/canvg/
// resource http://www.nihilogic.dk/labs/canvas2image/
String.prototype.FixForRaphael = function() {
// based on http://goo.gl/KZDII strip off all spaces between tags
var svgXmlNoSpace = this.replace(/>\s+/g, ">").replace(/\s+</g, "<");
// based on gabelerner added xmlns:xlink="http://www.w3.org/1999/xlink" into svg xlmns
var svgXmlFixNamespace = svgXmlNoSpace.replace('xmlns="http://www.w3.org/2000/svg"', 'xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"');
@cilerler
cilerler / StringConverters.cs
Created November 5, 2012 13:50
ToBase64 and FromBase64
using System;
public static class StringConverters
{
public static string ToBase64(this string value, Encoding encoding)
{
byte[] encbuff = encoding.GetBytes(value);
return Convert.ToBase64String(encbuff);
}
@cilerler
cilerler / ControlChars.cs
Created November 5, 2012 15:32
ControlChars
public sealed class ControlChars
{
/// <summary>
/// Chr(8)
/// </summary>
public const char BackSpace = '\b'; // #8
/// <summary>
/// Chr(13)
/// </summary>
public const char CarriageReturn = '\r'; // #13
@cilerler
cilerler / Enumerations.cs
Created November 5, 2012 16:04
Enumeration Extentions
using System;
using System.Reflection;
using System.ComponentModel;
public static class Enumerations
{
/// <summary>
/// Retrieves the enumeration's description based on given value
/// </summary>
public static string GetDescription(this Enum value)
@cilerler
cilerler / gist:4018009
Created November 5, 2012 16:08
Get Object Size as Byte
public long GetSize(object value)
{
long result;
using (var stream = new System.IO.MemoryStream())
{
var serializer = new System.Runtime.Serialization.NetDataContractSerializer();
serializer.WriteObject(stream, value);
stream.Flush();
result = stream.Length;
}
@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);
@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: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);
}