Meta-programming is the writing of computer programs with the ability to treat programs as their data. It means that a program could be designed to read, generate, analyze and/or transform other programs, and even modify itself while running.
7
votes
1answer
62 views
Brainfuck Printer Generator
Given a text, this program will output a Brainfuck program, that when executed will print the text back.
Writing Brainfuck in this style to print a sentence is pretty straightforward. Iterate over ...
4
votes
2answers
67 views
Tool to Add Access Modifiers to Code
Working on VSDiagnostics, I implemented a tool that adds the default access modifiers to C# code. An example use would be starting with this:
...
8
votes
2answers
133 views
Putting everything in its place
A new diagnostic has seen the light of day! This one will alert you when you have a string.Format() call where the formatting placeholders are in the wrong order. ...
4
votes
1answer
58 views
Descriptor class with advanced (inspect/metaclass) functionality
Having answered this question over on Programmers.SE, I found myself wondering how much effort it would be to write a descriptor that can automatically figure out what the 'destination' attribute ...
10
votes
2answers
226 views
Memoizing decorator that can retry
I have some tasks that I'd like to memoize because they connect to a rather slow network and have to wait for the data. Unfortunately this network can be a little finnicky and we get occasional ...
1
vote
4answers
73 views
Python Decorator - inspecting function argument values
Some of my functions use a "fail_silently" flag. It is used in the following way:
...
10
votes
1answer
107 views
Try-except decorator for classmethods
This question is related to the Cactus Text Game Engine.
For easy error handling in Cactus, we've put together this small decorator. Essentially, the decorator wraps any class method in a ...
6
votes
1answer
51 views
Game loop decorator for Pygame
I've built a simple decorator that wraps a function in a general Pygame game loop. It also allows for the programmer to set the tick rate.
...
6
votes
1answer
128 views
Automatic flowchart generator
I wanted to see graphically what my programme was doing so I wrote this automatic flowchart generator:
...
3
votes
1answer
25 views
user_interface module
As writing code to handle error-checked input or to present functions to execute to the user is boring and error-prone, I wrote a module to automate these tasks:
...
18
votes
3answers
319 views
Rubberduck's “Extract Method” refactoring implementation
With the ANTLR-powered parser, I was able to reimplement all code inspections from the last release build, and the rest of the inspections on the road map are now implementable.
Code inspections ...
12
votes
2answers
775 views
Wait, is that variable ever assigned?
One of the inspections we wanted to implement in Rubberduck for the next release, is one that finds all unassigned variables in a VBA project.
Implementing this inspection has been ...complicated ...
3
votes
2answers
149 views
Building a chain of responsibility in Ruby to apply transformators on an object
I try to make a middleware stack system in the rack way (but not for HTTP request).
Here is the main class:
...
3
votes
1answer
90 views
Meta-class to allow inspection of all __slots__of a class
If classes provide __slots__ and at the same time inherit from another class also providing __slots__, there is no ...
3
votes
2answers
78 views
Synchronous and asynchronous motor movement
I am working on an API that is mostly intended to be used interactively/little scripts. There are some classes with methods that could act slightly differently depending on the intention of the user, ...
2
votes
1answer
115 views
Memoization of Fibonacci using generic Int => Int helper
I'm trying to understand memoization using Scala. I took the Fibonacci sequence as an example because of the high cost of recursively computing numbers in the sequence without memoization.
...
9
votes
2answers
143 views
Find arity of a rebol function
I needed a way to find the number of arguments a function or operation in Rebol accepts (the functions arity). I could not find any direct support for this in the language, so I made my own ...
2
votes
0answers
55 views
Making a default value a property
I recently asked a question on StackOverflow, looking for a way to more easily turn a class attribute into a @property, but only if no other value has been provided ...
4
votes
0answers
67 views
Creating 2D vectors
I've made a little mechanism for creating 2-D vectors in Lua. Vectors have two components i and j, and support addition, dot ...
3
votes
0answers
53 views
Extracting dynamic behaviors of state machines to modules
This is my initial class. (I am not trying to reinvent state-flows again, just practicing)
As you can see straight forward, it dynamically generates methods like .recommend,.recommend!, ...
4
votes
1answer
110 views
Universal memoization decorator
I've just written a simple caching / memoization python decorator. It's purpose is to cache what the function returns for all the arguments combinations it's been ever invoked with.
So, if, say, we ...
3
votes
1answer
132 views
Perl wrapper library (written using Moose) for a REST API
I wrote a wrapper library for a REST API (https://semantics3.com) in Perl using the Moose library. I would like to gather some feedback on it (mainly on the OOP part since I am new to moose), before ...
3
votes
1answer
120 views
Enums for measurement units, with possible circular dependency
I have some enums that define measurement information, such as volume, mass, distance etc...
They are defined as such:
...
0
votes
1answer
78 views
Python decorator for optional arguments decorator
I want my Python decorators to have optional arguments and not be called when not necessary.
The accepted answer in here doesn't accept named arguments, and I don't want to add boilerplate code ...
2
votes
0answers
136 views
Efficient compile-time directed graph
During my research in Rigid Body Dynamics, (where Contact Graphs are used to solve the contact problem) I came across the question if it is possible to define at compile time a directed graph (class) ...
4
votes
1answer
104 views
Dictionary with restricted keys
I'm currently building some software that works with systemd unit files, and I've been trying to improve how we construct the unit files.
This is all running in Python 3.4
This first block is the ...
2
votes
2answers
446 views
Failing fast by raising an exception with a custom message
This is a script that utilizes lazy exception throwing. What I do is decorate a function that might throw an exception to throw an exception with a formatted string.
...
5
votes
2answers
453 views
Java MVC model for large scale GUI using annotations
I'm trying to make a good MVC model using annotations, which I will use it in a large scale GUI project. I want to respect the maximum of rules and guidelines, and be able to decorrelate every parts ...
6
votes
1answer
184 views
Wrapping the classList API to add/remove array of classes
I've written a function that wraps the classList API, allowing you to pass an array of classes to add/remove, or the variable arguments already supported by ...
3
votes
0answers
45 views
Is monkeypatching __builtin__ in tests like this an absurdly complicated practice?
My hunch: Probably.
I'm testing a little magic behaviour of my script that automatically reads from ~/.ghtoken to do automagic authentication on GitHub API ...
17
votes
5answers
329 views
Automagic testing framework for VBA
Building on @RubberDuck's recommendations, I now have something I find... beautiful. I'm sure there's a couple of things left to polish - this site is about making great code out of good any code, ...
10
votes
3answers
190 views
Ugly workaround to get the vbext_ProcKind of a procedure is breaking encapsulation
This is a follow up to Extending the VBAExtensibility Library. It turns out that code had a really nasty bug. Anytime vbeProcedure.StartLine got called, I was ...
8
votes
2answers
139 views
Generating and calling code on the fly
Delegate
This class module defines what I'm calling, in this context, a Delegate - here a function that can take a number of parameters, evaluate a result, and ...
2
votes
1answer
600 views
define_method vs method_missing and CodeClimate scores
This may be a better fit for another board, but here goes:
I've made a very simple gem that acts as a days-of-the-week bitmask. To be hip, I registered it on CodeClimate, where it's currently scoring ...
6
votes
1answer
163 views
Multiple dispatch decorator classes in Python
This is based on my first review and the suggested points in "Multiple dispatch decorator in Python":
...
3
votes
1answer
90 views
General way to add persistence to a class in Python
The idea here is to write a function that gives you back a persistent version of a class that you supply. So you if you run
...
1
vote
0answers
12 views
Memcache Keys Management Class
I have written below class to manage Memcache keys.
My Memcache keys structure are like:
...
7
votes
3answers
442 views
VB6/VBA Declaration (Dim) Syntax Parser
As part of a project I'm working on, I've implemented a class that encapsulates the syntax for a vb6/vba Dim statement.
Given a line of code, the ...
7
votes
1answer
1k views
Extending the VBA Extensibility Library
The Microsoft Visual Basic for Applications Extensibility library let's us meta-program VBA, but the way it handles (or rather, doesn't handle) getting to the actual subs and functions is clunky at ...
3
votes
3answers
469 views
Math Equation Solver
I made this math script, where you enter an equation and it solves it for you. I was wondering what you thought of the code, and what I could have done better or what doesn't follow Ruby best ...
5
votes
1answer
88 views
Zombie Smack Down game
So about a year and a half ago, me and my friend started on a game called Zombie Smack Down. It's a text based game written in Ruby. But we were both really new to Ruby when most of it was written. I ...
3
votes
1answer
98 views
Ruby 1.9 interner
I'm currently implementing an interner in the style of Guava's Interner, where:
an intern pool is maintained for an immutable class
whenever a new instance of ...
2
votes
1answer
150 views
Streamlining repetitive class definitions in python with a class_factory() function
I forked this repo to be more concise. The code is here. I'll paste it below since that seems to be the style. I removed the class definitions at the bottom that I didn't change -- the edit I'm ...