Skip to content

Instantly share code, notes, and snippets.

# basic example configuration for nginx with php-fpm
server {
root /usr/share/nginx/www;
index index.html index.htm;
server_name localhost;
location /app1 {
using System;
using System.Drawing;
using System.Windows.Forms;
// based on http://alanbondo.wordpress.com/2008/06/22/creating-a-system-tray-app-with-c/
namespace MyTrayApp
{
public partial class TrayApp : Form
private static string GetCharacterNameFromSkyrimSaveFileName(string filename)
{
var re = new Regex(@"save \d+ - (?<charname>[\w]+)\s+([\w\s])+\s+\d{2}\.\d{2}.\d{2}", RegexOptions.IgnoreCase);
var m = re.Match(Path.GetFileName(filename));
return m.Success ? m.Groups["charname"].Value : null;
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AutoMapper;
namespace AutoMapperTest
{
class Program
{
SET NOCOUNT ON
DECLARE @Starts DATETIME
DECLARE @Ends DATETIME
SET @Starts = '2014-06-05 00:00:00'
SET @Ends = '2014-06-05 23:59:00'
select
Public Class LoginCheckHttpModule
Implements IHttpModule
Public Sub Dispose() Implements System.Web.IHttpModule.Dispose
End Sub
Public Sub Init(ByVal context As System.Web.HttpApplication) Implements System.Web.IHttpModule.Init
AddHandler context.PostAcquireRequestState, AddressOf OnPostAcquireRequestState
End Sub
public abstract class BasePage : System.Web.UI.Page
{
protected override void OnInit(EventArgs e)
{
// cache none of the things!
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetNoStore();
Response.Cache.SetMaxAge(TimeSpan.Zero);
base.OnInit(e);
}
public static TimeSpan GetTimePeriod(string str)
{
if (str == null)
throw new ArgumentNullException("str");
// Plain old regex: ([\+-]?)(\d+)([A-Za-z]+)?
Regex re = new Regex("(?<Operator>[+\\-]?)(?<Value>\\d+)(?<Unit>[A-Za-z]+)?", RegexOptions.IgnoreCase);
Match m = re.Match(str);
if (m.Success)
@nramsbottom
nramsbottom / ReadToEnd.cs
Created May 13, 2014 17:54
StreamReader.ReadToEnd with maximum length
public static string ReadToEnd(this StreamReader reader, int maximumCharacters)
{
var builder = new System.Text.StringBuilder();
while (true)
{
var line = reader.ReadLine();
if (line == null)
break;
if (builder.Length + line.Length > maximumCharacters)
@nramsbottom
nramsbottom / garbage.cs
Last active August 29, 2015 14:01
Generates a 6GB file of random data.
long targetFileSize = UUInt32.MaxValue + (long)(UInt32.MaxValue / 2);
long bytesWritten = 0;
byte[] buf = new byte[8192];
var rng = new System.Security.Cryptography.RNGCryptoServiceProvider();
using (var output = File.Open(@"C:\tmp\garbage.dat", FileMode.CreateNew, FileAccess.Write, FileShare.None))
{
while (bytesWritten < targetFileSize)
{
rng.GetBytes(buf);
output.Write(buf, 0, buf.Length);