Skip to content

Instantly share code, notes, and snippets.

@glebov21
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
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"?>
<configuration>
<location path="ForDownload" allowOverride="false" inheritInChildApplications="false">
<system.webServer>
<security>
<authorization>
<!-- Allow all users access to the Public folder -->
<remove users="*" roles="" verbs="" />
<add accessType="Allow" users="*" roles="" />
</authorization>
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
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));
<system.diagnostics>
<trace autoflush="true" indentsize="4">
<listeners>
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
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;
configuration.Save();
@glebov21
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
glebov21 / pgx.go
Created Aug 22, 2019
pgx postgresql connection example
View pgx.go
package main
import (
"log"
"time"
"github.com/jackc/pgx"
)
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
glebov21 / restore.bash
Created Aug 19, 2019
restore postgresql backup
View restore.bash
#!/bin/bash
backupfile="pgsql_2019-08-06.sql.gz"
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