Skip to content

Instantly share code, notes, and snippets.

@nramsbottom
nramsbottom / rng.c
Last active August 29, 2015 13:59
Simple random number generator.
#include <stdlib.h>
#include <stdint.h>
#include "rng.h"
static uint32_t rng_current_seed = 0;
rng *
rng_create(uint32_t seed) {
rng *r = malloc(sizeof(r));
r->seed = seed;
@nramsbottom
nramsbottom / Program.cs
Last active August 29, 2015 14:01
Detect UTF8 Byte Order Mark
//
// Finds and displays the filenames of all UTF8 files that contain a byte order mark
// in a specified directory tree.
//
// based on information from the following URL
//
// http://stackoverflow.com/questions/4520184/how-to-detect-the-character-encoding-of-a-text-file
//
using System;
@nramsbottom
nramsbottom / gist:89d09ad8d66642c329b4
Last active August 29, 2015 14:01
VB:GetTimePeriod
''' <summary>
''' Simple parser for time periods from a string.
''' e.g.
''' 1d
''' 1m
''' 2days
''' </summary>
''' <param name="str"></param>
''' <returns></returns>
''' <remarks></remarks>
-- http://stackoverflow.com/questions/7892334/get-size-of-all-tables-in-database
SELECT
t.NAME AS TableName,
p.rows AS RowCounts,
SUM(a.total_pages) * 8 AS TotalSpaceKB,
SUM(a.used_pages) * 8 AS UsedSpaceKB,
(SUM(a.total_pages) - SUM(a.used_pages)) * 8 AS UnusedSpaceKB
FROM
sys.tables t
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <io.h>
#include <stdio.h>
#include <stdint.h>
#include <conio.h>
int albion_boost_gold(const char *filename, uint16_t gold_to_give) {
/* Albion Gold Boost for DOS */
#include <stdio.h>
#include <fcntl.h>
#include <io.h>
#include <sys/types.h>
int main(int argc, char *argv[]) {
int fd;
@nramsbottom
nramsbottom / dttm.cs
Last active August 29, 2015 14:01
Simple command line date and time formatter for use in batch scripts.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace dttm
{
class Program
{
static int Main(string[] args)
@nramsbottom
nramsbottom / Backup.cmd
Created May 13, 2014 12:31
Simple backup script using 7zip
@REM Requires the following tools
@REM Blat <http://sourceforge.net/projects/blat>
@REM Dttm <https://gist.github.com/nramsbottom/2296fffdf49fcb824fe4>
@REM Curl <http://curl.haxx.se/>
@SETLOCAL
@REM Set this to 1 to show all script output on the console
@REM which will help when debugging.
@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);
@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)