Skip to content

Instantly share code, notes, and snippets.

View gitlarryf's full-sized avatar

Larry Frieson gitlarryf

View GitHub Profile
@gitlarryf
gitlarryf / WordWrap.vb
Created November 19, 2014 01:45
Visual Studio Macro Helper Function that can wrap automatic code comments, and even lines of code at a given column number.
Function WordWrap(ByVal sText, ByVal nWrapAt)
Dim i
For i = 1 To Len(sText) / nWrapAt
sText = Mid(sText, 1, nWrapAt * i - 1) & Replace(sText, " ", vbCrLf, nWrapAt * i, 1, vbTextCompare)
Next
WordWrap = sText
End Function
@gitlarryf
gitlarryf / Posix_copy2.cpp
Last active August 29, 2015 14:25
Posix File Copy Routines...
bool file$copyfile(const std::string &sourceFile, const std::string &destFile, bool &failIfExists)
{
const int BUFSIZE = 32768;
FILE *src = fopen(sourceFile.c_str(), "rb");
if (not src) {
throw RtlException("FileNotFoundError", sourceFile);
}
@gitlarryf
gitlarryf / MazeGenerator.neon
Last active August 29, 2015 14:28
Generates an ASCII maze on the command line, taking parameters for the x and y size of the maze.
IMPORT bitwise
IMPORT sys
IMPORT random
TYPE Direction := RECORD
direction: String
bit: Number
dx: Number
dy: Number
opposite: Direction
@gitlarryf
gitlarryf / Anagrams
Last active November 2, 2015 17:19
Create a list of Anagrams from the dictionary file stored at the supplied URI.
% Rosettacode Coding Exercise: Anagrams
% Description: Two or more words can be composed of the same characters, but in a different order.
% Using the word list at http://www.puzzlers.org/pub/wordlists/unixdict.txt, find the
% sets of words that share the same characters that contain the most words in them.
% From: http://rosettacode.org/wiki/Anagrams
% Language: http://neon-lang.org
% Author: Larry Frieson
% Date: 10/13/2015
IMPORT http
IMPORT io
@gitlarryf
gitlarryf / brackets.neon
Last active November 2, 2015 17:21
Generate a random string of opening and closing brackets, and test to see if they are 'balanced' or not. That is, there is a closing bracket for every opening bracket, and are not mis-nested.
% Rosettacode Coding Exercise: Balanced Brackets
% Description: Determine whether the string of square brackets is balanced; that is, whether it
% consists entirely of pairs of opening/closing brackets (in that order), none of
% which mis-nest.
% From: http://rosettacode.org/wiki/Balanced_brackets
% Language: http://neon-lang.org
% Author: Larry Frieson
% Date: 10/21/2015, BTTF Day
IMPORT random
@gitlarryf
gitlarryf / RomanNumerals.neon
Last active October 23, 2015 17:36
A function taking a positive integer as its parameter and returning a string containing the Roman Numeral representation of that integer. Modern Roman numerals are written by expressing each digit separately, starting with the left most digit and skipping any digit with a value of zero.
% Rosettacode Coding Exercise: Roman Numerals
% Description: Create a function taking a positive integer as its parameter and returning a string
% containing the Roman Numeral representation of that integer.
% From: http://rosettacode.org/wiki/Roman_numerals/Encode
% Language: http://neon-lang.org
% Author: Larry Frieson
% Date: 10/22/2015
CONSTANT Value: Array<Number> := [ 1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4]
CONSTANT Digit: Array<String> := [ "M","CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV"]
@gitlarryf
gitlarryf / stringtoken.cpp
Created October 29, 2015 23:16
Looks in the string, passed in as pszSource for pszMoniker, and if it exists, populates buf with what the value is equal to. dwBufferLen provides the max number of chars that can be copied into buf. This function will allow a programmer to "parse" a string in the following format:
int StringToken(const char *pszMoniker, const char *pszSource, char *buf, DWORD dwBufferLen)
{
int f = 0;
char *p = (char*)pszSource;
char *m = (char*)pszMoniker;
while(p) {
if(!*p) break;
if(*p == *m) {
while(*p == *m) {
p++;
@gitlarryf
gitlarryf / stringtoken.cpp
Last active October 29, 2015 23:19
Looks in the string, passed in as pszSource for pszMoniker, and if it exists, populates buf with what the value is equal to. dwBufferLen provides the max number of chars that can be copied into buf. This function will allow a programmer to "parse" a string in the following format: "foo=bar;desc=value", and so on.
int StringToken(const char *pszMoniker, const char *pszSource, char *buf, DWORD dwBufferLen)
{
int f = 0;
char *p = (char*)pszSource;
char *m = (char*)pszMoniker;
while(p) {
if(!*p) break;
if(*p == *m) {
while(*p == *m) {
p++;
@gitlarryf
gitlarryf / LastFridays.neon
Last active November 6, 2015 17:07
Print out the last Friday of every month of the supplied year.
% Rosettacode Coding Exercise: Last Fridays
% Description: Write a program or a script that returns the last Fridays of each month of a given year.
% The year may be given through any simple input method in your language (command line,
% std in, etc.).
% From: http://rosettacode.org/wiki/Last_Friday_of_each_month
% Language: http://neon-lang.org
% Author: Larry Frieson
% Date: 11/05/2015
IMPORT datetime
IMPORT sys
@gitlarryf
gitlarryf / RunLengthCompression.neon
Created November 7, 2015 00:55
Given a string containing uppercase characters (A-Z), compress repeated 'runs' of the same character by storing the length of that run, and provide a function to reverse the compression.
% Rosettacode Coding Exercise: Run-length encoding
% Description: Given a string containing uppercase characters (A-Z), compress repeated 'runs' of the
% same character by storing the length of that run, and provide a function to reverse
% the compression. The output can be anything, as long as you can recreate the input with it.
% Example:
% Input: WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWW
% Output: 12W1B12W3B24W1B14W
%
% From: http://rosettacode.org/wiki/Run-length_encoding
% Language: http://neon-lang.org