Skip to content

Instantly share code, notes, and snippets.

glebov21 / OpenFileDialog.cs
Created Jun 16, 2022
C# OpenFileDialog with multiselect OFN_ALLOWMULTISELECT lpstrFile
View OpenFileDialog.cs
var ofn = new NativeMethods.OpenFileName();
ofn.lStructSize = Marshal.SizeOf(ofn);
if (Filter != null)
ofn.lpstrFilter = Filter.Replace('|', '\0') + "\0\0";
var maxFilePathLength = 250;
var maxFilesForMultiselect = 100;
ofn.nMaxFile = 1 * maxFilePathLength;
if (AllowMultiSelect)
ofn.Flags |= (
glebov21 / web.config
Last active Sep 9, 2021
Allow to download all files from iis folder (applicationHost.config -> allowSubDirConfig="false")
View web.config
<?xml version="1.0" encoding="UTF-8"?>
<location path="ForDownload" allowOverride="false" inheritInChildApplications="false">
<!-- Allow all users access to the Public folder -->
<remove users="*" roles="" verbs="" />
<add accessType="Allow" users="*" roles="" />
View SendMail.cs
using System;
using System.Text;
using System.Net.Mail;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Net;
using System.Threading;
using System.Net.Mime;
using System.Diagnostics;
glebov21 / App.config
Last active Sep 2, 2021
trace listeners
View App.config
var logSW = new StreamWriter("output.txt", false);
logSW.AutoFlush = true;
Trace.Listeners.Add(new TextWriterTraceListener(logSW));
Trace.Listeners.Add(new ConsoleTraceListener(true));
<trace autoflush="true" indentsize="4">
View gist:a8a110dc759e83e66966ee48dbcdedcd
using System;
using System.Net;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace Calibration {
public static class Server {
public delegate void ProgressDelegate(int percents, long bytesReceived, long totalBytesToReceive);
glebov21 / AppSettings.cs
Last active May 17, 2021
AppSettings read write
View AppSettings.cs
public static string GetSettings(string key)
return ConfigurationManager.AppSettings[key] ?? "";
public static void SetSetting(string key, string value)
Configuration configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
configuration.AppSettings.Settings[key].Value = value;
glebov21 / WebClient.cs
Last active May 14, 2021
WebClient with progress
View WebClient.cs
namespace AutogrammaLauncher
using System;
using System.Net;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
public static class Server
glebov21 / pgx.go
Created Aug 22, 2019
pgx postgresql connection example
View pgx.go
package main
import (
func main() {
View UnityExtensions.cs
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.EventSystems;
using UnityEngine.SceneManagement;
public static class UnityExtensions
glebov21 / restore.bash
Created Aug 19, 2019
restore postgresql backup
View restore.bash
cd /data/pgbackup
gunzip -c ${backupfile} > restore.sql
systemctl stop aero
service postgresql restart
su postgres -c 'dropdb aerodb'
su postgres -c $'psql -f /data/pgbackup/restore.sql postgres'
systemctl restart aero
rm restore.sql