RSSAmplifier

Blog

Choly's Blog

Recent content on Choly's Blog

choly.caRSS feed ↗38 posts

Latest posts

Go: Defer Blocks (idea)

This is an idea that I’ve had for a while. It’s an extension of defer that behaves similar to handle . I’m not sure if it’s original, but I thought it was worth writing down. 
 Syntax 
 defer { 
 // Code runs at function exit 
 } 
 
 defer ( _ string , err error ) { 
 if err != nil { 
 return '' , fmt . Errorf ( 'wrapped: %w' , err ) 
 }…

Go: Blank Lines and Error Handling Syntax

When writing Go, I generally don’t include a lot of blank lines. Here’s an example (ignore the lack of error wrapping/annotation): 
 func zipmod ( dir , modpath , version string ) ([] byte , error ) { 
 	 var buf bytes . Buffer 
 	 zw := zip . NewWriter ( & buf ) 
 	 err := filepath . WalkDir ( dir , func ( path string , d fs . DirEntry , err error ) error {…

Agent Recursion

When AI agents start using tools, the context window fills up fast.
Each run_command or read_file tool call dumps a lot of text that quickly loses relevance in subsequent steps. 
 I’ve been experimenting with the idea of “recursive agents” to mitigate this issue.
The idea is simple: An agent can kick off new instances of itself to handle specific subtasks . 
 The…

Semgrep: AutoFixes using LLMs

Semgrep: 
 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: 
 $A.get_foo(...)
 Test your own patterns using the playground: https://semgrep.dev/playground/new 
 While there are other tools like this, semgrep is…

Git: programmatic staging

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…

3D Printing

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…

AWS X-Ray: Force Sample

Background 
 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. 
…

Debugging a flaky Go test with Mozilla rr


 This is how you debug a test that only fails once every 1000 times. 
 The Test 
 package my 
 
 import ( 
 	 'math/rand' 
 	 'testing' 
 	 'time' 
 ) 
 
 func init () { 
 	 rand . Seed ( time . Now (). UnixNano ()) 
 } 
 
 func TestRandFail ( t * testing . T ) { 
 	 if n := rand . Intn ( 1000 ); n == 50 { 
…

Merging Multiple Git Repositories Into A MonoRepo

Note: Replace thing with your own repo name in the examples. 
 1. Create a repository which will store all your code 
 mkdir monorepo && cd monorepo
git init .
echo '# MonoRepo' > README.md
git add .
git commit -m 'first commit'
 2. Clone one of the existing repositories to a temporary location 
 Example Remote: ssh://git@code.company.com/thing.git 
 mkdir…

Go: Composable http.Handler

When using net/http , handling errors is kinda annoying. 
 http . HandleFunc ( '/foo' , func ( w http . ResponseWriter , r * http . Request ) { 
 	 thing , err := storage . Get ( 'thing' ) 
 	 if err != nil { 
 		 http . Error ( w , err . Error (), 500 ) 
 		 return 
 	 } 
 	 _ = json . NewEncoder ( w ). Encode ( thing ) 
 }) 
…

Angular Events

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: 
 function MyController ( $rootScope ) { 
 $rootScope . $on ( 'event1' , () => { 
 console . log ( 'event 1 occured' ); 
 });…

TypeScript: Working with JSON

EDITS: 
 
 Calling toString on Date is for illustrative purposes. 
 There’s a full commented example at the end. 
 Use toJSON method as suggested by Schipperz . 
 Add reviver method as suggested by Anders Ringqvist . 
 
 
 So you have a User type in your code. 
 interface User { 
 name : string ; 
 age : number ; 
 created : Date ; 
 }…

Custom JSON Marshalling in Go

Go’s encoding/json package makes it really easy to marshal struct s to JSON data. 
 package main 
 
 import ( 
 	 'encoding/json' 
 	 'os' 
 	 'time' 
 ) 
 
 type MyUser struct { 
 	 ID int64 `json:'id'` 
 	 Name string `json:'name'` 
 	 LastSeen time . Time `json:'lastSeen'` 
 } 
 
 func main () { 
…

TypeScript completion in Vim

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. 
 Demo: 
 
 1. Install TSS 
 git clone https://github.com/clausreinke/typescript-tools.git
 cd typescript-tools
 git checkout testing_ts1.4
 sudo npm install…

interactive filtering with less

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…

C++: Make Repl

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…

C++: Inline Functions

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. 
 struct Foo { 
 int m_number = 123 ;…

Vim Marks

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.

C++ Extending Classes via the Stream Operator

Vision &#xA; Looking for a way to create a class which behaved like one of the std::ostream classes. &#xA; MyClass obj ; &#xA; &#xA; obj << 'foo' << 123 << some_string . c_str (); &#xA; Problem &#xA; 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…

C&#43;&#43; Log4cxx vs Glog vs Boost.log vs Wrapper

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). &#xA; #ifdef DEBUG&#xA; std :: cerr << 'some error' << std :: endl ; &#xA; #endif &#xA; I started googling and the following to be the most popular and mature. &#xA; glog &#xA;…

Libpq: PQexec Timeout

1. Establish the connection &#xA; PGconn * pg_conn = PQconnect ( 'info' ); &#xA; &#xA; // error check&#xA; if ( PQstatus ( pg_conn ) != CONNECTION_OK ) throw 'invalid connection' ; &#xA; 2. Grab the socket file descriptor &#xA; int socket_fd = PQsocket ( pg_conn ); &#xA; &#xA; // error check&#xA; if ( socket_fd < 0 ) throw 'invalid socket' ; &#xA; 3. Set the timeout &#xA; // 5 second timeout&#xA;…

SWAPM: Code generation made easy.

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…

A week with Vim

During the past week I&rsquo;ve been learning to use Vim (gVim). Day 1 and 2 weren&rsquo;t fun to say the least. But now I&rsquo;m completely hooked. I&rsquo;m the type of person who will sit there for hours customizing my development environment until I think it&rsquo;s perfect. I&rsquo;ve been playing with almost every cool plugin i can find (and wasting a lot of time in the process). &#xA;…

Ember.js with Brunch

I&rsquo;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&rsquo;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.…

CSS Compass Gradient Generator

This is a css gradient generator that i&rsquo;ve been using for a while: &#xA; &#xA; http://www.colorzilla.com/gradient-editor/ &#xA; &#xA; CSS Output &#xA; background : # 1e5799 ; /* Old browsers */ &#xA; background : -moz-linear-gradient ( top , # 1e5799 0 %, # 2989d8 50 %, # 207cca 51 %, # 7db9e8 100 %); /* FF3.6+ */ &#xA; background : -webkit-gradient ( linear , left top , left bottom ,…

VMware Workstation Ubuntu problems

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&rsquo;ve encountered before on Ubuntu 11.04 and now on 11.10. &#xA; This is a bug with all v7.x of workstation and can be fixed with a simple patch I found today at…

QML is Awesome

QML is Nokia&rsquo;s recent addition to its well known Qt framework and comes part of the Qt Quick Suite &#xA; The way I describe it to people is: &#xA; &#xA; it&rsquo;s like html and css combined with the power of Qt in a extremely simple syntax. &#xA; &#xA; &#xA; &#xA; &#xA;&#xA; Why? &#xA; I have used Swing, WinForms, and GTK in the past and never really liked anything to do with GUI work. QML…

Qt Creator &#43; Boost on Ubuntu 11.04

1. make a home for boost &#xA; sudo mkdir -p /code/include&#xA; sudo chown -R YOUR_USER_NAME /code&#xA; cd /code/include&#xA; 2. download boost &#xA; sudo apt-get install subversion&#xA; svn co http://svn.boost.org/svn/boost/trunk boost&#xA; cd boost&#xA; 3. compile boost &#xA; sudo ./bootstrap.sh&#xA; sudo ./b2&#xA; note: this will take a while, go get some coffee. &#xA; 4. Include in qt project…

Compile CompassApp on Ubuntu 11.04

&#xA; &#xA; &#xA; &#xA;&#xA; 1. Install RVM &#xA; bash < < ( curl -s https://rvm.beginrescueend.com/install/rvm ) ; &#xA; echo 'if [[ -s '$HOME/.rvm/scripts/rvm' ]] ; then source '$HOME/.rvm/scripts/rvm' ; fi' > ~/.bashrc&#xA; rvm install 1.9.2&#xA; 2. Install jRuby &#xA; rvm install jruby&#xA; cd ~/.rvm/bin/jruby-1.6.4 -S gem install rawr&#xA; 3. Get and Compile CompassApp &#xA; git clone…

Cloud9 IDE

I&rsquo;ve always wanted to like web based IDE&rsquo;s. However, there was one thing that always prevented it: they&rsquo;ve always been terrible. &#xA; Until now that is. http://cloud9ide.com/ Cloud9 is epic. It&rsquo;s built on node.js and has support for coffeescript and sass syntax highlighting and real time error checking. I can&rsquo;t even find an desktop ide to do that right! &#xA; It gets…

Sass Compass Blueprint

So I just realized that I hadn&rsquo;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&rsquo;ll be talking about css in this post. I started using these a while back so I don&rsquo;t really know why I haven&rsquo;t posted anything about it. Better late than never. &#xA; Let&rsquo;s start with SASS. Syntactically…

CoffeeScript

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&rsquo;m pretty excited to actually try it in a real project. In case you don&rsquo;t know CoffeeScript is a python-esque language which &lsquo;compiles&rsquo; into javascript. classes, list comprehension inheritance, ranges, semantic code…

Formalize [More Compass]

I think forms and all things related ( inputs, buttons, etc&hellip; ) are probably one of the more annoying things when building a website. They&rsquo;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&rsquo;re…

Reloader - multi browser live web preview

I recently started developing on linux and unfortunately stylizer 5 does not support linux. So I&rsquo;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…

JPProxy - tiny jsonp proxy

JPProxy is a very simple yet powerful JSONP script.&#xA;It allows you to make ajax like requests to any page on a server that has the jpproxy.php script on it.&#xA;I tried really hard to make it as simple and generic as possible so the source is tiny. &#xA; 1. Client &#xA; A script tag is injected into the DOM and all the values are added to the url as GET parameters.

Skybound Stylizer 5 - CSS Editor

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&rsquo;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…

Balsamiq Mockups - wireframing done right

Senario: &#xA; You&rsquo;re designing some type of user interface. Clients never know what they want (even when they think they do) so it&rsquo;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&rsquo;re good to go. &#xA; This is how the conversation goes: &#xA; Me: I threw together this mockup of a potential design.…

absoluteFudge - ie6 absolute positioning

I don&rsquo;t know about you, but here is a snippet of css that I love. &#xA; div # selector { &#xA; position : absolute ; &#xA; left : 10 px ; &#xA; right : 10 px ; &#xA; top : 10 px ; &#xA; bottom : 10 px ; &#xA; } &#xA; 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…