Skip to content

Instantly share code, notes, and snippets.

View koistya's full-sized avatar
🏠
Working from home

Konstantin Tarkus koistya

🏠
Working from home
View GitHub Profile
@koistya
koistya / gist:2336959
Created April 8, 2012 12:22
New programming language + self-interpreter
/* Bootstrap interpreter (program is bad, it can segfault) */
/* Written in: C */
/* From: Stack */
/* To: N/A (interpreter) */
/* Stack 0 - Output */
/* Stack 1 - Program */
/* Stack 2 - Working stack */
/* Other stacks - Whatever you want */
@koistya
koistya / Password.cs
Created June 16, 2012 23:37
Password Utility utilizing PKBDF2 algorithm; hash and verify passwords with PKBDF2 aka RFC2898
//-------------------------------------------------------------------------------
// <copyright file="Password.cs" company="KriaSoft LLC">
// Copyright © 2012 Konstantin Tarkus, KriaSoft LLC. All rights reserved.
// See License.md in the project root for license information.
// </copyright>
//-------------------------------------------------------------------------------
namespace App.Security
{
using System.Linq;
@koistya
koistya / AccountController.cs
Created June 19, 2012 20:30
Membership service usage sample inside ASP.NET MVC controller
public class AccountController : Controller
{
private readonly IMembershipService membershipService;
// service initialization is handled by IoC container
public AccountController(IMembershipService membershipService)
{
this.membershipService = membershipService;
}
@koistya
koistya / SampleActivity.cs
Created October 4, 2012 08:17
Service locator in Windows Workflow Foundation
public sealed class SampleActivity : CodeActivity
{
protected override void CacheMetadata(CodeActivityMetadata metadata)
{
// Require the IDatabaseContext extension to be defined in the workflow host application.
// The workflow will fail validation if an extension with this interface is not provided.
metadata.RequireExtension<IDatabaseContext>();
}
protected override void Execute(CodeActivityContext context)
@koistya
koistya / topunique.m
Last active December 10, 2015 03:38
Grabs top unique 'n' elements from a vector or matrix
function output = topunique(nums, n)
%TOPUNIQUE вытаскивает 'n' уникальных чисел сверху из списк
% вытащить уникальные числа
output = unique(nums(:), 'stable');
% ограничить их кол-во до 'n' элементов
output = output(1:min(n, length(output)));
end
@koistya
koistya / Web.config
Created November 27, 2013 09:47
Microsoft ASP.NET Web Pages configuration file
<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<configSections>
<sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
<section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
using System.Collections.Generic;
using System.Linq;
using System.Threading;
public class StringCollection
{
private List<string> collection;
public StringCollection()
{
using System;
public class Coin
{
public Coin(CoinType type, int volume, decimal amount)
{
if (volume <= 0)
{
throw new ArgumentOutOfRangeException("volume");
}
@koistya
koistya / Single-page Application (SPA) Project Structure.md
Created January 30, 2014 05:24
Directory Layout of a Single-page Application built with .NET / F#, AngularJS, TypeScript, LESS...

Single-page Application Project Structure

..with .NET / F# (or Node.js / Express), AngularJS (or Facebook React + RxJS), TypeScript, Gulp.js (or Grunt), NuGet...

Goals

  • Project structure should reflect application's logic (as opposed to regular MVC apps which all look the same)
  • Group assets by feature rather than by type (including views, scripts, documentation, tests etc.)
  • Allow developers to edit client-side and server-side code independently from each other
@koistya
koistya / ajax.js
Created February 1, 2014 21:07
Send Ajax request with vanilla JavaScript
var xhr = new XMLHttpRequest();
xhr.open('GET', '/api/sum?a=1&b=2', false);
xhr.send(null);
console.log(xhr.responseText); // prints 3