Skip to content

Instantly share code, notes, and snippets.

View llCorvinSll's full-sized avatar

Dmitry Pronin llCorvinSll

View GitHub Profile
@llCorvinSll
llCorvinSll / get_data_from_form
Last active December 22, 2015 07:58
Get data from form on submit
$.fn.serializeObject = function()
{
var o = {};
var a = this.serializeArray();
$.each(a, function() {
if (o[this.name]) {
if (!o[this.name].push) {
o[this.name] = [o[this.name]];
}
o[this.name].push(this.value || '');
@llCorvinSll
llCorvinSll / arrow.css
Created October 4, 2013 19:45
Make arrow from element
.arrow {
height: 15px;
width: 0px;
border-top: 15px solid rgba(0,0,0,0.75);
border-right: 15px solid transparent;
border-left: 15px solid transparent;
bottom: -15px;
content: '';
display: block;
}
@llCorvinSll
llCorvinSll / Lazy Instance
Created October 31, 2013 06:19
Create Lazy instance of object which requires setup after creating
class Client
{
public static TClient CreateInst<TClient, TInterface>(string url, string domain, string username, string password)
where TClient : System.ServiceModel.ClientBase<TInterface>
where TInterface : class
{
BasicHttpBinding binding = new BasicHttpBinding();
binding.Security.Mode = BasicHttpSecurityMode.TransportWithMessageCredential;
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows;
@llCorvinSll
llCorvinSll / build.txt
Created November 3, 2013 09:57
Qt subdirs project and setup deps between subprojects
include( ../common.pri )
TEMPLATE = app
SOURCES += main.cpp
LIBS += -L../logic -llogic \
-L../gui -lgui
# Will build the final executable in the main project directory.
@llCorvinSll
llCorvinSll / get enum names
Created November 27, 2013 12:38
Get human names for enum values, if they are defined by [Display(Name = "name")]
Func<FakeEnumType, string> getName = en =>
{
var type = typeof(FakeEnumType);
var memInfo = type.GetMember(en.ToString());
var attributes = memInfo[0]
.GetCustomAttributes(typeof(DisplayAttribute), false);
return ((DisplayAttribute)attributes[0]).Name;
}
@llCorvinSll
llCorvinSll / convert hash to N-digit string.cs
Created January 24, 2014 11:36
TOTP: Time-Based One-Time Password Algorithm http://tools.ietf.org/html/rfc6238#
public static string GeneratePassword(string secret, long iterationNumber, int digits = 6)
{
byte[] counter = BitConverter.GetBytes(iterationNumber);
if (BitConverter.IsLittleEndian)
Array.Reverse(counter);
byte[] key = Encoding.ASCII.GetBytes(secret);
HMACSHA1 hmac = new HMACSHA1(key, true);
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Data.Entity.Migrations;
using System.Linq;
using System.Text.RegularExpressions;
/// <summary>
/// Provides advanced migrations by providing a seeding platform for each migration.
function countCSSRules() {
var results = '',
log = '';
if (!document.styleSheets) {
return;
}
for (var i = 0; i < document.styleSheets.length; i++) {
countSheet(document.styleSheets[i]);
}
function countSheet(sheet) {
@llCorvinSll
llCorvinSll / waitfor_condition.js
Created December 11, 2014 09:49
wait for some condition resolved in JS ugly hack ):
//**********************************************************************
// function waitfor - Wait until a condition is met
//
// Needed parameters:
// test: function that returns a value
// expectedValue: the value of the test function we are waiting for
// msec: delay between the calls to test
// callback: function to execute when the condition is met
// Parameters for debugging:
// count: used to count the loops
@llCorvinSll
llCorvinSll / new_gist_file.sql
Created March 25, 2015 12:59
T-SQL LEAD() example select rows with time interval between more then 1 hour
select *, DATEDIFF(second,StartTime,NextStart) from (SELECT data.Id, data.RawValue, data.RawName, data.StartTime, LEAD(data.StartTime) OVER (ORDER BY data.StartTime) NextStart, data.EndTime FROM [UsageEventDatas] as data where data.ObjectId = '00000000-0000-0000-0000-000000000000' and data.RawName LIKE 'CPUPercentUtilization-A%' and data.StartTime > CONVERT(datetime, '2015-02-27') and data.EndTime < CONVERT(datetime, '2015-03-01') ) as data where DATEDIFF(second,StartTime,NextStart) > 3600