Skip to content

Instantly share code, notes, and snippets.

View tvolodimir's full-sized avatar

Volodymyr tvolodimir

View GitHub Profile
@tvolodimir
tvolodimir / Proxy.cs
Created September 14, 2014 06:12
tcp proxy
using System;
using System.Net;
using System.Net.Sockets;
using System.Threading;
namespace Proxy
{
class Program
{
static void Main(string[] args)
/*
faster bind by http://jsperf.com/bind-vs-emulate/9
*/
(function () {
var slice = Array.prototype.slice;
Function.prototype.bind2 = function (context) {
var f = this;
var curriedArgs = slice.call(arguments, 1);
if (curriedArgs.length) {
(function () {
// IndexedDB
var indexedDB = window.indexedDB || window.webkitIndexedDB || window.mozIndexedDB || window.OIndexedDB || window.msIndexedDB,
IDBTransaction = window.IDBTransaction || window.webkitIDBTransaction || window.OIDBTransaction || window.msIDBTransaction,
dbVersion = 1.0;
// Create/open database
var request = indexedDB.open("elephantFiles", dbVersion),
db,
createObjectStore = function (dataBase) {
@tvolodimir
tvolodimir / invoke.js
Created March 19, 2013 13:23
compare call, apply, bind and (object,method name)
//http://jsperf.com/call-apply-bind-method
function targetCall(thisArg, func) {
return func.call(thisArg, 1, 2);
}
function targetApply(thisArg, func) {
return func.apply(thisArg, [1, 2]);
}
@tvolodimir
tvolodimir / Remote.cs
Created September 18, 2013 14:09
CreateProxy Instance in AppDomain
public sealed class Remote<T> where T : MarshalByRefObject
{
private readonly AppDomain domain;
private readonly T remoteObject;
private Remote(AppDomain domain, T remoteObject)
{
this.domain = domain;
this.remoteObject = remoteObject;
}
@tvolodimir
tvolodimir / CircleBuffer.js
Created January 10, 2014 08:55
CircleBuffer
// http://jsperf.com/circle-buffer-vc-array
var CircleBuffer = function (size) {
this._size = size; // max count of data
this._list = [];
this._cursorIndex = 0;
this._startIndex = 0;
this.length = 0; // actual data length
};
CircleBuffer.prototype = {
<!DOCTYPE html>
<html>
<head>
<title>abc abcd</title>
<script>
function ReplaceNode(textNode, eNode) {
textNode.parentNode.replaceChild(textNode, eNode);
}
function DecorateText(node, match, offset) {
@tvolodimir
tvolodimir / SortableBindingList.cs
Created September 13, 2013 08:59
SortableBindingList C#
public class SortableBindingList<T> : BindingList<T>
{
private readonly Dictionary<Type, PropertyComparer<T>> comparers;
private bool isSorted;
private ListSortDirection listSortDirection;
private PropertyDescriptor propertyDescriptor;
public SortableBindingList()
: base(new List<T>())
{
@tvolodimir
tvolodimir / TimeActionWrapper.cs
Created September 14, 2014 07:28
TimeAction Wrapper
using System;
using System.Threading;
using System.Threading.Tasks;
using System.Timers;
using Timer = System.Timers.Timer;
public class TimerAction
{
private readonly Action action;
private readonly Timer timer;
@tvolodimir
tvolodimir / serializer.cs
Last active February 17, 2016 06:32
serializers c#
public static T XmlDeserializeFromString<T>(string objectData)
{
return (T)XmlDeserializeFromString(objectData, typeof(T));
}
public static object XmlDeserializeFromString(string objectData, Type type)
{
var serializer = new XmlSerializer(type);
object result;