The Ghost in the Shell series were about efficient working in the shell environment but one of the feats of any sysadmin profession is the shell scripting. It is often needed to ‘glue’ various solutions and technologies to work as ‘Business’ requires or to fill the gap where any solution is not available – or at least not for free. It also serves a growing role in the automation of various tasks. Today I will try to show you the basics of writing POSIX /bin/sh compatible shell scripts.

You may want to check other articles in the Ghost in the Shell series on the Ghost in the Shell – Global Page where you will find links to all episodes of the series along with table of contents for each episode’s contents.

Read More

Type-level programming in haskell (and other languages that support it) can be quite useful from time to time, but I find that it’s something that a lot of people struggle with learning. In haskell specifically, I think learning how to use type-level programming appropriately can be quite hard because the best real-world examples of type-level programming often come from larger projects, and it can be hard to figure out how to grow the design of your own code to make use of type level programming effectively when you’re only seeing the end-state of projects that have already grown into type level programming.

Outside of real-world projects, there are some well written pieces that describe various aspects of type level programming, but few references that are both accessible to people first trying to dip their toes into the world of type level programming and which also address the various approaches you can take to programming with types holistically.

In this article you’ll learn how to build programs that make heavy use of type-level programming by working through building a theming system. I originally developed the ideas behind this talk and article when trying to write something to unify the various themes and configurations for my own xmonad desktop setup, but the theming system you’ll build as you work through this article can be equally applied to theming web content, desktop or command line applications, or really anything that needs configurable theming.

Read More

There is a lot of confusion about floating-point numbers and a lot of bad advice going around. IEEE-754 floating-point numbers are a complex beast[1], and comparing them is not always easy, but in this post, we will take a look at different approaches and their tradeoffs.

I hang out in a couple programming language development chat channels and new people often seem to ask the same practical questions about parsing and implementing parsers. So I wanted to write up a quick guide about the pragmatic implications of how these things work in the real world.

This assumes that you already have some idea of what a parser does and where it fits in a compiler’s pipeline, and are trying to put that theory into practice and grapple with all the choices involved. If you don’t know what a parser, lexer or abstract syntax tree are, you’ll need more background before this is useful. Come back after doing a light read of the first few chapters in one of the following books.

Read More

Today we will begin writing a compiler for a real high-level language. It will be a simple language for sure. But let’s not let simplicity stand in our way. We will be able to write real programs with our compiler. How real, you ask? Let’s plan on writing a compiler for our selected language and then being able to write a compiler in that same language the compiler compiles using our compiler to compile it! From zero to compiler to self-hosted compiler. It will take a good bit of work for sure, but I think we are up to the task. We’ll spend this series writing our initial, non-self-hosting compiler. We’ll take some time to enjoy our work, then we’ll come back and embark on a second series that develops the self-hosted compiler using the compiler we will write in this series.

For today, let’s select a language for our compiler. Two languages, actually. One language will be the language that the compiler understands. The other will be the language that the compiler is written in. Once we’ve done that, let’s do some organizational work, discuss some of the different ways we could implement our compiler, and choose one of those implementation methods.

Read More

A few friends have recently asked about literature introducing Monad Transformers. The best introduction I have found was in Haskell Programming From First Principles. If you don’t have, or want to purchase, this book, then here is a brief explanation with examples.

Lets start with the problem they solve.

WebAssembly threads support is one of the most important performance additions to WebAssembly. It allows you to either run parts of your code in parallel on separate cores, or the same code over independent parts of the input data, scaling it to as many cores as the user has and significantly reducing the overall execution time.

In this article you will learn how to use WebAssembly threads to bring multithreaded applications written in languages like C, C++, and Rust to the web.

I wrote Python for the last 10 years, and I always tend to write code in a “functional” way - map, filter, lambda and so on, it makes me feel clean and happy. Following this warm feeling I decided to try a True functional language.

So I read a couple of tutorials online and went through the famous Learn You a Haskell for Great Good ! It was a long and painful journey - which is not over yet. After some retrospection I wanted to share my own introduction to Haskell based on my python experience. What I wished I had learnt first and what I wished I learnt later down the road.

Read More

Hey you! Have you ever wanted to become a CPU Whisperer? Me too! I’m a frontend web developer by trade but low-level assembly code and compilers have always fascinated me. I’ve procrastinated on learning either for a long time but after I recently picked up Rust and have been hanging out in a lot of online Rust communities it’s given me the kick in the butt to dive in. Rustaceans use fancy words and acronyms like auto-vectorization, inlining, alignment, padding, linking, custom allocators, endianness, system calls, LLVM, SIMD, ABI, TLS and I feel bad for not being able to follow the discussions because I don’t know what any of that stuff is. All I know is that it vaguely relates to low-level assembly code somehow so I decided I’d learn assembly by writing entirely too many brainfuck compilers in Rust. How many is too many? Four! My compile targets are going to be x86, ARM, WebAssembly, and LLVM.

Read More

The best way to understand complex data structures is to see them in action. We’ve developed interactive animations for a variety of data structures and algorithms. Our visualization tool is written in javascript using the HTML5 canvas element, and run in just about any modern browser – including iOS devices like the iPhone and iPad, and even the web browser in the Kindle! (The frame rate is low enough in the Kindle that the visualizations aren’t terribly useful, but the tree-based visualizations – BSTs and AVL Trees – seem to work well enough)

Read More

As a web developer, I use relational databases every day at my job, but they’re a black box to me. Some questions I have:

  • What format is data saved in? (in memory and on disk)

  • When does it move from memory to disk?

  • Why can there only be one primary key per table?

  • How does rolling back a transaction work?

  • How are indexes formatted?

  • When and how does a full table scan happen?

  • What format is a prepared statement saved in?

In other words, how does a database work?

To figure things out, I’m writing a database from scratch. It’s modeled off sqlite because it is designed to be small with fewer features than MySQL or PostgreSQL, so I have a better hope of understanding it. The entire database is stored in a single file!

Read More
@johntitor shared their post

This book dives deeply into JavaScript:

  • It teaches practical techniques for using the language better.

  • It teaches how the language works and why. What it teaches is firmly grounded in the ECMAScript specification (which the book explains and refers to).

  • It covers only the language (ignoring platform-specific features such as browser APIs) but not exhaustively. Instead, it focuses on a selection of important topics.

Last week, I drank my first cup of Rust. I learned concepts that are foreign in the languages I know: ownership, borrowing and lifetimes. This week I want to drink the second cup and see where it leads me.

This is the 2nd post in the Start Rust focus series.Other posts include:

  1. My first cup of Rust

  2. My second cup of Rust (this post)

As CPU cores become both faster and more numerous, the limiting factor for most programs is now, and will be for some time, memory access. Hardware designers have come up with evermore sophisticated memory handling and acceleration techniques–such as CPU caches–but these cannot work optimally without some help from the programmer. Unfortunately, neither the structure nor the cost of using the memory subsystem of a computer or the caches on CPUs is well understood by most programmers. This paper explains the structure of memory sub systems in use on modern commodity hardware, illustrating why CPU caches were developed, how they work, and what programs should do to achieve optimal performance by utilizing them.

Read More

In this brief tutorial I’m aiming to make a small game for the ZX Spectrum, written 100% in assembler. I’ve done a bunch of projects for the speccy using SDCC; while I couldn’t completely escape assembly, the C compiler did a lot of heavy lifting for me. In other words, I traded control for convenience.

Now, since I’ve never actually done a 100% assembler project before (ignoring some tiny DOS TSR experiments), this is a learning experience for me as well. A lot of things I’ll do here is likely not going to be optimal, but what I present is what happened to work for me. All the source code is free to use in whatever way you wish, with no warranty whatsoever.

Read More

On implementing streaming algorithms, counting of events often occurs, where an event means something like a packet arrival or a connection establishment. Since the number of events is large, the available memory can become a bottleneck: an ordinary n-bit counter allows to take into account no more than 2n−1 events.
One way to handle a larger range of values using the same amount of memory would be approximate counting. This article provides an overview of the well-known Morris algorithm and some generalizations of it.

Read More

This guide is intended to help you gain a true understanding of SQL query speeds. It includes research that demonstrates the speed of slow and fast query types. If you work with SQL databases such as PostgreSQL, MySQL, SQLite, or others similar, this knowledge is a must.

Recently, I needed to learn this completely new language Clojure but couldn’t find what I wanted. So, I decided to create one while learning Clojure.

Clojure is a functional programming language and learning functional programming languages is sometimes hard if you’ve only had experiences with imperative languages. I have paid careful attention to make this page easy to understand for people who don’t have experiences with functional programming languages, so please don’t hesitate to read this page even if you don’t know anything about functional programming.

Hopefully, this page helps you learning functional programming and starting to write Clojure!

Read More
Created on Nov 8, 2020
By @gurlic