Small, local changes that make later improvements possible
Large, structural changes that improve the overall design
Before the big changes can happen, you often need to do a lot of small, mechanical edits. These help clean things up, but they also serve as a way to re-learn the codebase. What developers often won’t admit is that they usually don’t know what the big change is going to be when they start. They just know the code isn’t right.
Semgrep is an incredible tool that allows you to search code by matching against the Abstract Syntax Tree (AST).
For instance, if you want to find all method calls named get_foo, you can write a pattern like this:
In the past year, I’ve been using a lot of tools to automatically rewrite/refactor code. These include semgrep, ast-grep, LLMs, and one-off scripts. After running these tools on a large code-base, you usually end up with lots of additional unintended changes. These range from formatting/whitespace to unrequested modifications by LLMs.
The subsequent “cleanup” step is a very manual and tedious process. I’m essentially running git add -p and staging hunks one at a time. At times it feels like this step offsets the productivity gain from the rewrite tool itself.
About a year ago, I purchased a BambuLab P1P 3D printer for about $1000 CAD (after taxes and shipping). This is something I’ve wanted to do on-and-off for the past 10 years and I finally decided to pull the trigger.
For my first few projects, I decided to print existing STL models I found on the internet instead of designing my own. This was a good idea at first, but eventually led me down the (very expensive) rabbit hole of 3D printed RC (Radio Control) vehicles. This was not ideal because it resulted in learning (and paying for) two separate hobbies at the same time: 3D printing + RC. The cost and complexity of the project was off-putting and the printer sat idle for a few months after that.
At my current workplace, we use X-Ray configured with a sample rate of 0.01.
This means that a random 1% of requests will be traced.
The low rate is great at keeping costs down, but it’s not useful for debugging specific failed requests.
Fortunately, you can force X-Ray to sample your request by generating a trace id, and setting the X-Amzn-Trace-Id header.
Generating trace IDs
The id format is documented here
along with a Python code sample.
git clone https://github.com/rr-debugger/rr.git
cd rr
git checkout 5.4.0 # change this to the latest release (DO NOT BUILD HEAD)mkdir build
cd build
cmake ..
make -j8
sudo make install
I’ve been trying to find an elegant way of dealing with events in AngularJS recently.
If you’re not farmiliar with Angular, that’s ok, this is a pretty common pattern.
Here I have a controller that registers an event listener:
One of the main advantages of using static types is that you get much better support from your tools.
I recently got TypeScript auto-completion working in vim and I’m documenting how to do it here.
I discovered a cool little feature in less (not less.css) today. You can interactively filter the data.
&pattern
Display only lines which match the pattern; lines which do not match the pattern are not displayed. If pattern is empty (if you type & immediately followed by ENTER), any filtering is turned off, and all lines are displayed. While filtering is in effect, an ampersand is displayed at the beginning of the prompt, as a reminder that some lines in the file may be hidden.
Certain characters are special as in the / command:
One of the things I really like about dynamic languages like javascript & python is the repl. After you’ve gotten used to that type of exploratory programming, it’s hard to go back to the edit/compile/run cycle.
Luckily that has finally changed with cling. It’s an interactive C++ environment that behaves pretty much like a repl. In my recent projects I’ve been adding a new make rule: repl which lets me interactively play with the code I’m working on and it has drastically improved my productivity.
Even though overuse of getter and setter functions can be frowned upon, they can help a lot if you’re looking to provide a intuitive api. However the overhead the additional function call introduces is undesirable. Thankfully, there’s the inline keyword. It tells the compiler to replace each invocation of the function with the body of the function.
structFoo{intm_number=123;inlineintnumber(){returnm_number;}};intmain(){Foofoo;// used like a regular function
std::cout<<foo.number()<<std::endl;// compiled to almost identical assembly as this
std::cout<<foo.m_number<<std::endl;return0;}
However the inline keyword isn’t a guarantee that the compiler will do this. It’s more of a hint to the compiler. So keep in mind that the compiler is free to ignore the fact that a function is declared inline and it can inline functions that haven’t been delcared as such. But in examples similar to the one above, you can assume it will behave as expected.
Marks are a feature that I’ve never really used enough. Hopefully writing about them will change that for the better.
Make a basic, file local, mark called a
ma
Jump back to that mark
'a
Now I try to be pragmatic. So use cases are what motivate me to learn new thing. I think that marks are a good replacement for a lot of the things I use visual line V mode for now.
Looking for a way to create a class which behaved like one of the std::ostream classes.
MyClassobj;obj<<"foo"<<123<<some_string.c_str();
Problem
Implementing all those operator<< overloads would be redundant because something like std::stringstream already does it. However inheriting from std::stringstream is more complicated than it should be.
structMyClass:publicstd::stringstream{/* not that simple ... */};
Solution
You can use a simple template to achive the desired effect.
It seems that logging in C++ isn’t a much discused topic when compared to a language like java. In a recent C++ project, I needed to add real logging support. Up till this point, the following was good enough (don’t judge).
I finally got around to reading the Pragmatic Programmer book. One thing that really interested me was the section on Code Generation. So in a recent C++ project I was interfacing with postgres and there was a LOT of code repetition. The sql query, class members, getters/setters, response parsing logic. They all contained the same information. Perfect I thought, here was the ideal chance to give code generation a shot. My first incarnation was a very ugly perl script (aren’t they all .. ?) which used mustache as the templating engine. It worked, But I had to copy and paste the generated code into my source every time it changed which was a pain.
During the past week I’ve been learning to use Vim (gVim). Day 1 and 2 weren’t fun to say the least. But now I’m completely hooked. I’m the type of person who will sit there for hours customizing my development environment until I think it’s perfect. I’ve been playing with almost every cool plugin i can find (and wasting a lot of time in the process).
So Vim is, without a doubt, the best text editor I’ve ever used. However, that’s all it is. It’s just a text editor and I know a lot people don’t agree with me on this one, but IDE’s do help. They just make everything better. Therefore the ultimate combination would be an ide with vim as the text editor.
I’ve recently discovered the brilliant Ember.js library and the first major issue I ran into was how to organize/modularize this thing!? At first I just opted into RequireJs because that’s what I know but I started hitting walls fast. I decided to try out the Brunch build system since I had heard good things about it before and this was a great opportunity to learn how to use it. Brunch uses skeletons which are essentially project templates to get rid of the boilerplate. Google search “ember brunch” and I found charlesjolley/ember-brunch perfect!
I just tried starting up vmware workstation and was greeted with a message saying it needed to compile some modules and then went on to fail this step no matter what. This is an issue I’ve encountered before on Ubuntu 11.04 and now on 11.10.
QML is Nokia’s recent addition to its well known Qt framework and comes part of the Qt Quick Suite
The way I describe it to people is:
it’s like html and css combined with the power of Qt in a extremely simple syntax.
Why?
I have used Swing, WinForms, and GTK in the past and never really liked anything to do with GUI work. QML is the first time I’m actually enjoying designing user interfaces and this results in a better end result. It feels a lot more like web development except without browser specific issues.
In this example i’m linking boost::filesystem and boost::asio.boost::system is required by other boost libraries but if you can compile without it, then trash it.
I’ve always wanted to like web based IDE’s. However, there was one thing that always prevented it: they’ve always been terrible.
Until now that is. http://cloud9ide.com/ Cloud9 is epic. It’s built on node.js and has support for coffeescript and sass syntax highlighting and real time error checking. I can’t even find an desktop ide to do that right!
It gets better though. It’s 100% open source so you can install it on locally. I kinda used this as a general guide but didn’t need most of it
So I just realized that I hadn’t actually written anything about compass. Now I feel a little dumb about the title of the Formalize post but w.e shit happens. Anyway I’ll be talking about css in this post. I started using these a while back so I don’t really know why I haven’t posted anything about it. Better late than never.
Let’s start with SASS. Syntactically Awesome Style Sheet
well actually I’ll be talking about SCSS which is sass syntax which is more like css. Well actually it’s exactly like regular css except you can add way more stuff. but regular css is still valid scss. I’m not going to try to explain so here’s an example.
I just spent the last 5 hours learning CoffeeScript and I feel like I have pretty much everything down. My brain is kinda dead right now, but at the same time I’m pretty excited to actually try it in a real project. In case you don’t know CoffeeScript is a python-esque language which ‘compiles’ into javascript. classes, list comprehension inheritance, ranges, semantic code etc…. dream come true. http://jashkenas.github.com/coffee-script/
One thing I was worried about was being able to use 3rd party libraries with it. It’s actually not different at all… Once you figure it all out, you realize that it’s still the exact same js you’re working with and you can do just as much. It’s just a lot less shitty. Yes, the learning curve is balls, but it’s definitely worth it (i hope).
I think forms and all things related ( inputs, buttons, etc… ) are probably one of the more annoying things when building a website. They’re just not consistent and it takes a lot of effort to make them look decent. I spent some time looking for a tool to help me with this and I ended up with formalize which comes as a compass plugin and integrates with any web framework you’re using. http://formalize.me/ It actually didn’t jump out at me the first time around when I checked out the site. It didn’t ‘dazzel’ me so I kept looking, but what I realized was that it shouldn’t stand out. It’s a form… You don’t want it to be shiny with crazy animations. So I went back and used it for the project I’m currently working on. It was perfect… enough said.
I recently started developing on linux and unfortunately stylizer 5 does not support linux. So I’m back to using kate. However, one thing that I really missed right away was the instant preview feature. Having to go and refresh multiple browsers every time you change a line of code blows. I searched around for a bit and found a few tools but none of them were any good. I needed something that would work in multiple browsers at the same time and I couldn’t find anything to my liking so I wrote my own.
JPProxy is a very simple yet powerful JSONP script.
It allows you to make ajax like requests to any page on a server that has the jpproxy.php script on it.
I tried really hard to make it as simple and generic as possible so the source is tiny.
1. Client
A script tag is injected into the DOM and all the values are added to the url as GET parameters.
Lets start with a little preface. Prior to finding Stylizer, I was completely happy using a regular text editor (gedit, notepad++) with firebug to do my css coding. I don’t really know how I found stylizer, or what motivated me to download it, but I am glad I did. Stylizer is, by far, the best css editor. I went on to try 10+ different editors in hopes of finding a free alternative and nothing even comes close. This is the first piece of software I bought a legitimate licence for and $80 is a lot for a broke ass student.
You’re designing some type of user interface. Clients never know what they want (even when they think they do) so it’s usually a good idea to come prepared with a basic design to go off. You quickly whip together something in photoshop and think you’re good to go.
This is how the conversation goes:
Me: I threw together this mockup of a potential design. It’s very rough so just look at the basic layout and ignore details.
assuming that the parent element has either relative or absolute positioning, the child div will fit inside with a 10px margin. This is a very powerful technique for creating liquid css layouts.
Problem
The problem is, that ie doesn’t support giving values to all sides (top,bottom,left,right) so you were forced to have a separate stylesheet for ie with a static layout.