Skip to content

Instantly share code, notes, and snippets.

Dmitriy Vlasov DmitriyVlasov

Block or report user

Report or block DmitriyVlasov

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View The next ten Fridays 13.fs
let ``Next N Friday 13`` n =
Seq.initInfinite (fun i -> i |> float |> System.DateTime.Now.AddDays)
|> Seq.filter (fun date -> date.Day = 13 && date.DayOfWeek = System.DayOfWeek.Friday)
|> Seq.map (fun date -> date.ToShortDateString())
|> Seq.take n
|> Seq.toList
// Output:
// val ( Next N Friday 13 ) : n:int -> string list
// val it : string list =
@DmitriyVlasov
DmitriyVlasov / EventLogExample.fs
Last active Aug 29, 2015
Пример работы с логом событий на F#
View EventLogExample.fs
open System.Diagnostics
let sizeEventLog (el : EventLog) =
Microsoft.Win32.Registry.LocalMachine.OpenSubKey( @"System\CurrentControlSet\Services\EventLog\" + el.Log )
|> Option.ofNull
|> Option.bind ( fun registryKey -> registryKey.GetValue("FIle") |> Some )
|> Option.bind Option.ofNull
|> Option.bind ( fun x -> x.ToString() |> Some )
|> Option.bind ( fun filePath -> new FileInfo(filePath) |> Some )
|> Option.bind ( fun fi -> fi.Name |> Some )
@DmitriyVlasov
DmitriyVlasov / sample-regex-provider.fsx
Last active Aug 29, 2015
Примеры использования FSharp.Text.RegexProvider
View sample-regex-provider.fsx
(** # Примеры использования FSharp.Text.RegexProvider*)
(** ## Проверка ссылок на F#*)
(** Следующий скрипт выводит информацию о ссылках в html-коде, хранящемся в переменной html.
Скрипт портирован из примера в книге Д. Фридл, Регулярные выражения стр. 257 *)
open System.Text.RegularExpressions
open FSharp.Text.RegexProvider
[<Literal>]
let aTagPattern =
View System.DirectoryServices.AccountManagement.fs
#r "System.DirectoryServices.AccountManagement.dll"
open System.DirectoryServices.AccountManagement
let testSearch fullName =
let ctx = new PrincipalContext(ContextType.Domain)
let u = new UserPrincipal(ctx)
u.Surname <- fullName
use ps = new PrincipalSearcher(u)
ps.FindAll()
|> Seq.cast<System.DirectoryServices.AccountManagement.UserPrincipal>
@DmitriyVlasov
DmitriyVlasov / UpdatePowerShellHelpOverProxy.ps1
Created Aug 6, 2015
Обновление справки Powershell через прокси сервер
View UpdatePowerShellHelpOverProxy.ps1
$webclient = New-Object System.Net.WebClient
$creds = Get-Credential
$webclient.Proxy.Credentials = $creds
Update-Help -Credential $creds
@DmitriyVlasov
DmitriyVlasov / ExampleExportCsv.ps1
Created Aug 18, 2015
Корректный экспорт данных в CSV русскоязычных букв.
View ExampleExportCsv.ps1
# Выгружает в формате csv без вставки в заголовок файла описание типа, в кодировке Юникод.
export-csv -Path C:\temp\export.csv -Delimiter ';' -NoTypeInformation -Encoding Unicode
@DmitriyVlasov
DmitriyVlasov / Excel4.fs
Created Oct 2, 2015 — forked from mndrake/Excel4.fs
A F# wrapper class for the Excel4/Excel12 methods contained in Excel-DNA to mimic basic methods of the COM object model
View Excel4.fs
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
namespace Utility
@DmitriyVlasov
DmitriyVlasov / ianaMediaTypeTable.fs
Created Nov 1, 2015
Пример использования провайдера типа CsvProvider из библиотеки FSharp.Data на примере получения таблицы медиа типов официально предоставляемых консорциумом IANA.
View ianaMediaTypeTable.fs
#I @"../../packages/FSharp.Data/lib/net40"
#r @"FSharp.Data.dll"
open FSharp.Data
[<Literal>]
let ianaCsvSample = "Name,Template,Reference
1d-interleaved-parityfec,application/1d-interleaved-parityfec,[RFC6015]"
@DmitriyVlasov
DmitriyVlasov / paket-from-fsharp-repl.fsx
Last active Nov 7, 2015
Использование paket из интерактивной сессии F#
View paket-from-fsharp-repl.fsx
// Делаем текущий каталог рабочей директорией
System.Environment.CurrentDirectory <- __SOURCE_DIRECTORY__
// Если файл paket.exe не существует загружаем его
if not (System.IO.File.Exists "paket.exe") then
let url = "http://fsprojects.github.io/Paket/stable"
use wc = new System.Net.WebClient()
let tmp = System.IO.Path.GetTempFileName()
let stable = wc.DownloadString(url)
wc.DownloadFile(stable,tmp)
View gist:bd6ca0f08229af368116
//------------------------------------------
// Step 0. Boilerplate to get the paket.exe tool
open System
open System.IO
Environment.CurrentDirectory <- __SOURCE_DIRECTORY__
if not (File.Exists "paket.exe") then
let url = "http://fsprojects.github.io/Paket/stable"
You can’t perform that action at this time.