Skip to content

Instantly share code, notes, and snippets.

View llCorvinSll's full-sized avatar

Dmitry Pronin llCorvinSll

View GitHub Profile
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
@llCorvinSll
llCorvinSll / IPv6_full_string
Created May 5, 2015 15:10
IPv6 full string from IPAddress
void Main() { string str = "2a00:1450:4010:c04::71"; System.Net.IPAddress addr = System.Net.IPAddress.Parse(str); var bytes = addr.GetAddressBytes(); var preferredFormatString = string.Format("{0:x2}{1:x2}:{2:x2}{3:x2}:{4:x2}{5:x2}:{6:x2}{7:x2}:{8:x2}{9:x2}:{10:x2}{11:x2}:{12:x2}{13:x2}:{14:x2}{15:x2}", bytes [0], bytes [1], bytes [2], bytes [3], bytes [4], bytes [5], bytes [6], bytes [7], bytes [8], bytes [9], bytes [10], bytes [11], bytes [12], bytes [13], bytes [14], bytes [15]); Console.WriteLine (preferredFormatString); Console.Write(addr); } // Define other methods and classes here
@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 / 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 / README.md
Created May 25, 2016 09:12 — forked from jimothyGator/README.md
Nginx configuration for Mac OS X with Homebrew, using sites-enabled directory.
mkdir -p /usr/local/etc/nginx/sites-{enabled,available}
cd /usr/local/etc/nginx/sites-enabled
ln -s ../sites-available/default.conf
ln -s ../sites-available/default-ssl.conf

File locations:

  • nginx.conf to /usr/local/etc/nginx/
  • default.conf and default-ssl.conf to /usr/local/etc/nginx/sites-available
  • homebrew.mxcl.nginx.plist to /Library/LaunchDaemons/