2016 week 49 in programming

This guy taught me better than my professor.

Welcome to Programming from A to Z! “Programming from A to Z” is a course I teach at ITP. This playlist is anyone who would like to follow along online. This course focuses on programming strategies and techniques behind procedural analysis and generation of text-based data. We’ll explore topics ranging from evaluating text according to its statistical properties to the automated production of text with probabilistic methods to text visualization. Students will learn server-side and client-side JavaScript programming and develop projects that can be shared and interacted with online. Influences and Inspiration for the Programming from A to Z class:Jackson Mac Low’s Wikipedia Page: https://en. Js: https://p5js.org/Processing: https://processing.org. For More Programming from A to Z videos: https://www.

Programming Fibonacci on a 8 bits self made breadboard computer

None

How to Pay Programmers Less

How do you prevent that? Unfortunately, we can’t use violence any more, but there are some other mechanisms. If they don’t know how much their coworkers are getting, they won’t raise salary questions for much longer. They will be emotionally attached to the place and it will be very difficult to leave, no matter how underpaid they will be. Brainwash them regularly by communicating how great your company is, how big its mission is, and how important their contribution is. Spend just a little on all those funny office things, and they will pay you back big time, through the ability to underpay your programmers. They simply don’t know how to buy insurance, how to plan a retirement fund, or even how to pay taxes. How do you become friends? Well, meet their families, invite them over for dinner at your house, give them birthday gifts-all those tricks.

Linux kernel maintainer says ‘No.’ to AMDGPU patch

RFC] Using DC in amdgpu for upcoming GPU Dave Airlie airlied at gmail.com Thu Dec 8 20:07:26 UTC 2016 > I can’t dig into details of DC, so this is not a 100% assessment, but if > you call a function called “Validate” in atomic commit, you’re very, very > likely breaking atomic. If > you want to improve shared code the only downside is that you can’t also > improve amd, but that’s not so much a problem for non-amd folks ;-) > > The problem otoh with the abstraction layer between drm core and the amd > driver is that you can’t ignore if you want to refactor shared code. > > - Another issue is that very often we unify semantics in drivers by adding > some new helpers that at least dtrt for most of the drivers. If you have > your own world then the impendance mismatch will make sure that amd > drivers will have slightly different semantics, and I think that’s not > good for the ecosystem and kms - people want to run a lot more than just > a boot splash with generic kms userspace, stuff like xf86-video-$vendor > is going out of favour heavily. The trouble is that having your own world makes it harder for > everyone else to understand the amd driver, and understanding all drivers > is very often step 1 in some big refactoring or feature addition effort. Read up on the whole mac80211 problems we had years ago, where every wireless vendor wrote their own 80211 layer inside their driver, there was a lot of time spent creating a central 80211 before any of those drivers were suitable for merge, well we’ve spent our time creating a central modesetting infrastructure, bypassing it is taking a driver in totally the wrong direction. More information about the dri-devel mailing list [RFC] Using DC in amdgpu for upcoming GPU Dave Airlie airlied at gmail.com Thu Dec 8 20:07:26 UTC 2016 > I can’t dig into details of DC, so this is not a 100% assessment, but if > you call a function called “Validate” in atomic commit, you’re very, very > likely breaking atomic.

AMD responds to Linux kernel maintainer’s rejection of AMDGPU patch

Deucher at amd.com Fri Dec 9 17:32:24 UTC 2016 > —Original Message— > From: Dave Airlie > Sent: Thursday, December 08, 2016 3:07 PM > To: Daniel Vetter > Cc: Wentland, Harry; dri-devel; Grodzovsky, Andrey; amd-gfx mailing list; > Deucher, Alexander; Cheng, Tony > Subject: Re: [RFC] Using DC in amdgpu for upcoming GPU > > > I can’t dig into details of DC, so this is not a 100% assessment, but if > > you call a function called “Validate” in atomic commit, you’re very, very > > likely breaking atomic. It’s annoying since > > lots of code, and bugfixes have to be duplicated and all that, but it’s > > fairly easy to fix case-by-case, and as long as AMD folks stick around > > not a maintainance issue. If > > you want to improve shared code the only downside is that you can’t also > > improve amd, but that’s not so much a problem for non-amd folks ;-) > > > > The problem otoh with the abstraction layer between drm core and the > amd > > driver is that you can’t ignore if you want to refactor shared code. > > Given the choice between maintaining Linus’ trust that I won’t merge > 100,000 lines > of abstracted HAL code and merging 100,000 lines of abstracted HAL code > I’ll give you one guess where my loyalties lie. > > I’ve also wondered if the DC code is ready for being part of the > kernel anyways, what > happens if I merge this, and some external contributor rewrites 50% of > it and removes a > bunch of stuff that the kernel doesn’t need. If code trumps all, then why do we have staging? I understand forward progress on APIs, but frankly from my perspective, atomic has been a disaster for stability of both atomic and pre-atomic code. Are you basically telling us that you’d rather we water down our driver and limit the features and capabilities and stability we can support so that others can refactor our code constantly for hazy goals to support some supposed glorious future that never seems to come? What about right now? Maybe we could try and support some features right now.

Why does calloc exist?

In terms of its public API, calloc is different in two ways: first, it takes two arguments instead of one, and second, it returns memory that is pre-initialized to be all-zeros. So… why does calloc exist, if it’s equivalent to these 2 lines? The C library is not known for its excessive focus on providing convenient shorthands! So that’s the first way that calloc cheats: when you call malloc to allocate a large buffer, then probably the memory will come from the operating system and already be zeroed, so there’s no need to call memset. Calloc lives inside the memory allocator, so it knows whether the memory it’s returning is fresh from the operating system, and if it is then it skips calling memset. This only explains part of the speedup: memset+malloc is actually clearing the memory twice, and calloc is clearing it once, so we might expect calloc to be 2x faster at best. Numpy allocated the array using calloc, and then it wrote 1s in the diagonal… but most of the array is still zeros, so it isn’t actually taking up any memory, and our 2 GiB matrix fits into ~60 MiB of actual RAM. Of course there are other ways to accomplish the same thing, like using a real sparse matrix library, but that’s not the point. Calloc exists because it lets the memory allocator and kernel engage in a sneaky conspiracy to make your code faster and use less memory.

DoomRL open sourced

Parts of this codebase date back to 2002, please do not judge! :P. This FreePascal source code release is provided as is. You can try compiling it using the latest version of Lazarus. Detailed compilation instructions will appear at some later point after the Jupiter Hell Kickstarter finishes. Chaosforge.org/ Copy bin/mp3, bin/music, bin/sound, bin/soundhq from the DoomRL folders to the source tree bin folder Download 32-bit Lazarus Open src/makewad.lpi build, do not run Run makewad.exe from the command line in the bin folder to generate doomrl. Code is distributed under the GPL 2.0 license. All art is 2003-2016 Derek Yu. Art is distributed under the CC-BY-SA 4.0 license.

What algorithm did Microsoft use to dither color in early versions of Windows?

Basically, Windows used the basic 16-color CGA palette, which included 4 shades of monochrome, and 12 basic colors, which later formed the basis of the “Web safe palette” that became popular during the early days of the Internet. The algorithm used back then was known as the Bayer dithering technique, otherwise referred to as ordered dithering. The basic idea was to generate a grid of threshold values in a mathematical arrangement that favors nearly consistent values equal distances from each other, which is what produces the cross-hatch effect. They also included some example source code written in PHP:. <?php /* Create a 8x8 threshold map / $map = array map(function($p) , range(0,63 ; / Define palette / $pal = Array(0x080000,0x201A0B,0x432817,0x492910, 0x234309,0x5D4F1E,0x9C6B20,0xA9220F, 0x2B347C,0x2B7409,0xD0CA40,0xE8A077, 0x6A94AB,0xD5C4B3,0xFCE76E,0xFCFAE2); / Read input image */ $srcim = ImageCreateFromPng(‘scene. Basically, the entire thing was dreamed up by Bayer, and this algorithm dominated the market during the 4-bit era of computer graphics. 000000 #808080 #800000 #FF0000 #008000 #00FF00 #808000 #FFFF00 #000080 #0000FF #800080 #FF00FF #008080 #00FFFF #C0C0C0 #FFFFFF. Always dither from a full-color image, otherwise it’ll probably look even worse than you intended. Dithering in realtime is trivial for modern systems, as even classic 33mhz systems that ran Windows had no trouble implementing the Bayer dithering pattern.

PostgreSQL 10 will ship with table partitioning

Table partitioning is like table inheritance and reuses much of theexisting infrastructure, but there are some important differences. The parent is called a partitioned table and is always empty; it maynot have indexes or non-inherited constraints, since those make nosense for a relation with no data of its own. Each partition has animplicit partitioning constraint. Multiple inheritance is notallowed, and partitioning and inheritance can’t be mixed. Tuple routing isn’t yet supported for partitions which are foreigntables, and it doesn’t handle updates that cross partition boundaries. Listpartitioning is limited to a single column, but range partitioning caninvolve multiple columns. A partitioning “Column” can be anexpression.

I am tired of Makefiles

At Cesanta, we use Makefiles to build our firmwares, libraries, and perform other things. I want my incremental builds to be reliable, and I want to be able to reuse my Makefiles as needed. A …. Now, we have a project app with a separate Makefile, and we want to use mylib. We don’t want the app target to always get rebuilt. The app won’t be rebuilt, even though we want it to. My point is that if the author of makefile wants some variable to be overriddable, they should just use FOO ?= foo. There are plenty of other issues, some of them require ancient wisdom to write Makefiles which are correct, but I got used to most of them.

Atari 2600 Emulator in Minecraft

None

Developers’ side projects

So let’s consider this question: if you’re a developer working for software company, does that company own what you do in your spare time? Every software company is going to want to own the copyright to the code that its employees write for them, so no software company can accept the “Default” way the law works. So before you hire this developer, you agree, “Hey listen, I know that inventing happens all the time, and it’s impossible to prove whether you invented something while you were sitting in the chair I supplied in the cubicle I supplied or not. I don’t just want to buy your 9:00-5:00 inventions. I want them all, and I’m going to pay you a nice salary to get them all,” and she agrees to that, so now you want to sign something that says that all her inventions belong to the company for as long as she is employed by the company. So every software company tries to own everything that its employees do. Hmmm. OK, what if my employer is a small company making software for the legal industry. All of them need to purchase your copyright and patents without having to prove that they were generated “On the clock,” so they will all try to do this, unless the company is being negligent and has not arranged for appropriate contracts to be in place, in which case, the company is probably being badly mismanaged and there’s another reason not to work there. If you leave and start a competitive company or even a half-competitive company, we will use this contract to bring you to tears.

Well, what started as an r/ProgrammerHumor joke is now a real programming language. Enter Coding, a stack-based markup language.

Coding has 2 stacks, one for strings and another for HTML output. Parentheses push to the string stack; for example, would push asdf to the string stack. The standard library has a function S that can push from the string stack to the output stack. >: Pops top string stack element, wraps with a tag name, and pushes to output stack. Adds an attribute to the top output stack element using the popped top string stack element. S: Push the top string stack element to the output stack in text form. Se: Push the HTML string form of the top output stack element to the string stack.

Announcing TypeScript 2.1

Function get(obj: T, propertyName: K): T[K] let x = ; let foo = get(x, “Foo”); // has type ‘number’ let bar = get(x, “Bar”); // has type ‘string’ let oops = get(x, “Wargarbl”); // error! Mapped Types. Mapped types are definitely the most interesting feature in TypeScript 2.1. Mapped types are produced by taking a union of literal types, and computing a set of properties for a new object type. Notice how we leveraged TypeScript 2.1’s new indexed access types here by writing out T[P]. So instead of defining a completely new type like PartialPerson, we can just write Partial. Originally, we planned to ship a type operator in TypeScript 2.1 named partial which could create an all-optional version of an existing type. Because the Partial and Readonly types we used above are so useful, they’ll be included in TypeScript 2.1. Do be careful though - TypeScript will assume the package has the type any, meaning you can do anything with it.

TrendMicro starts a server in your machine and was allowing remote code execution from an HTTP request

When you install TrendMicro Antivirus on Windows, by default a component called Password Manager is also installed and automatically launched on startup. Html This product is primarily written in JavaScript with node. Js, and opens multiple HTTP RPC ports for handling API requests. It took about 30 seconds to spot one that permits arbitrary command execution, openUrlInDefaultBrowser, which eventually maps to ShellExecute(). This means any website can launch arbitrary commands, like this: x = new XMLHttpRequest() x.open(“GET”, “Https://localhost:49155/api/openUrlInDefaultBrowser?url=c:/windows/system32/calc.exe", true); try catch ;. This bug is subject to a 90 day disclosure deadline. If 90 days elapse without a broadly available patch, then the bug report will automatically become visible to the public.

Saving the internet 2000 terabytes a day: fixing Font Awesome’s fonts

Font Awesome, the most ubiquitous icon font on the web, just succesfully finished a Kickstarter campaign flushing a million dollars towards its creators to revamp the icon set. With a clear signal that Font Awesome isn’t going away anytime soon, let’s take a look at the technical integrity of its fonts. A font like Font Awesome has about 100.000 coordinates for all glyphs combined, resulting in a potential savings of 100kB! Long story short: the original unitsPerEm of Font Awesome’s fonts is 1792. Running our font through it reduces the font down from 150508 to 141376 bytes, saving another 9kB. Not super much, but since it was all dead weight anyway I say good riddance. If each day 73 million websites serve the Font Awesome WOFF to an average of a thousand visitors who don’t have these fonts in the browser’s cache, at a 26kB savings on the WOFF, we’ve saved. If they’re sticking to icon fonts instead of SVG, Font Awesome better make their font files awesome too.

What’s New In Python 3.6

This article explains the new features in Python 3.6, compared to 3.5. Whenever a new class is defined, the new method will be called on all descriptors included in the definition, providing them with a reference to the class being defined and the name given to the descriptor within the class namespace. The new PYTHONMALLOC environment variable allows setting the Python memory allocators and installing debug hooks. The new Collection abstract base class has been added to represent sized iterable container classes. The new DomainFilter filter class has been added to filter block traces by their address space. Since the typing module was provisional in Python 3.5, all changes introduced in Python 3.6 have also been backported to Python 3.5.x. The typing module has a much improved support for generic type aliases. The “Object allocated at” traceback is new and is only displayed if tracemalloc is tracing Python memory allocations and if the warnings module was already imported.

Talks that changed the way I think about programming

Here are some talks which have given me new insight into programming, and in particular what good programming is and isn’t. Software is the platform Code should be designed around a model of the world Code is more important than data Jonathan Blow: How to program independent games. One of the most important metrics to optimize for is hours of your life spent programming something. Eskil Steenberg: How I program in C. In the beginning all you want is results, in the end, all you want is control. Brian Will: Why OOP is Bad. Almost everything that’s interesting in a non-trivial program are ‘cross-cutting’ concerns. When faced with the reality of real word programs, promises of encapsulation tend to be broken, and object graphs quickly become tangled webs. The emphasis of programming should be on solving problems, and not on the code itself.

Neovim State and Progress Update

Neovim is a refactor of Vim to make it viable for another 30 years of hacking. Neovim very intentionally builds on the long history of Vim community knowledge and user habits. If you find an article about Vim, it likely also applies to Neovim, unless it’s about :smile. App is a macOS Neovim GUI available via homebrew for macOS 10.9+. nvim-hs is a host to enable writing Neovim plugins in Haskell. ZyX-I, a prolific committer to Neovim and Vim, agreed to take the role of “Lead developer”, i.e. the developer who receives the funding. If the project makes you happy, let the pledge continue! API. The Neovim API is one of the defining technical and “Soft” features of the project. C will be separated into modules, marking a point where Neovim’s VimL implementation diverges from Vim’s.

10 Features in C# That You Really Should Learn (and use!)

If you start exploring C# or decide to expand your knowledge, you should learn these useful language features, which will help you to simplify the code, avoid errors and save a lot of time. The async / await-pattern works by letting the code continue executing even if something is blocking the execution. The above example can be really useful in unit testing but should be avoided in other contexts as instances of classes should be created using a constructor. These features are practically a necessity in many cases, make sure to actually learn when and how to use them. GetValue(); var defaultValue = 23 //result will be 23 if someValue is null var result = someValue ?? defaultValue;. Format(“Some data: , some more data:“, someVariable, someOtherVariable); //NewWay var someString = $“Some data: , some more data:“;. So the new nameof-expression might not seem important, but it really has it value.

Write a Shell in C

This is a walkthrough on how I wrote my own simplistic Unix shell in C, in the hopes that it makes other people feel that way too. The code for the shell described here, dubbed lsh, is available on GitHub. University students beware! Many classes have assignments that ask you to write a shell, and some faculty are aware of this tutorial and code. Terminate: After its commands are executed, the shell executes any shutdown commands, frees up any memory, and terminates. These steps are so general that they could apply to many programs, but we’re going to use them for the basis for our shell. Our shell will be so simple that there won’t be any configuration files, and there won’t be any shutdown command. Reading a line from stdin sounds so simple, but in C it can be a hassle.

[PDF] “Concepts: The Future of Generic Programming” by Bjarne Stroustrup

Designing with concepts What makes a good concept? Ideally, a concept represents a fundamental concept in some domain, hence the name “Concept.” A concept has semantics; it means something; it is not just a set of unrelated operations and types. Examples are C/C++ built-in type concepts: arithmetic, integral, and floating STL concepts like iterators and containers Mathematical concepts like monad, group, ring, and field Graph concepts like edges and vertices; graph, DAG, etc. The first step to design a good concept is to consider what is a complete set of properties to match the domain concept, taking into account the semantics of that domain concept. We call such overly simple or incomplete concepts “Constraints” to distinguish them from the “Real concepts.” 12/11/2016 Page 12 of 23 Stroustrup D-R-A-F-T Concepts 5.5 Matching types to concepts How can a writer of a new type be sure it matches a concept? That’s easy: We simply static assert the desired concept matches. Overload resolution based on concepts is fundamentally simple: If a function matches the requirements of one concept only, call it If a function matches the requirements of no concept, the call is an error If the function matches the requirements of two concepts, see if the requirements of one of those concepts is a subset of the requirements of the other. 8.7 Concepts like classes Based on experience with other languages and experimentation with C++0x concepts, some people are convinced that concepts should be defined like classes. We have worked together on concepts for many years and share some favorite examples that we have used in the design of concepts and to explain concepts.

This is unfortunate and we’re stuck with it forever

The phrase immediately resounded in my head, because to me it was a perfect definition of JavaScript, or at least the current state of JavaScript. II. Douglas Crockford published JavaScript: The Good Parts about eight years ago. It’s a masterpiece to me, with a lot of takeaways: JavaScript is loaded with crap; there’s a great functional language somewhere in there, striving to get out; sometimes, a lot of the times, less is more. We can make a better language out of JavaScript by subsetting it. IV. Unlike any other language, JavaScript runs in browsers. V. I always wonder how is it like to learn JavaScript in 2016, for new programmers and for programmers coming from other languages. Can’t the browsers manage multiple versions of JavaScript? is it worth their save, especially now that this uneven language has crawled its way to the server and the desktop?

How Discord handles push request bursts of over a million per minute with Elixir’s GenStage

Stage 1 - the Push Collector: The Push Collector is a producer that collects push requests. Stage 2 - the Pusher: The Pusher is a consumer that demands push requests from the Push Collector and pushes the requests to Firebase. The Push Collector never sends a request to a Pusher unless the Pusher asks for one. Since the Pushers put back-pressure on the Push Collector, we now have a potential bottleneck at the Push Collector. In the Push Collector, we specify how many push requests to buffer. If there are way too many messages moving through the system and the buffer fills up then the Push Collector will shed incoming push requests. The bottom graph is the number of push requests buffered by the Push Collector.

Dart 1.21 released, with generic gethod syntax

It introduces support for generic method syntax along with a few popular convenience features. Dart 1.21 introduces syntax allowing type arguments on methods and functions. For more examples, check out the Using Generic Methods article. We’ve had generic methods and functions for a while in strong mode. 1.21 introduces support for generic method syntax even without strong mode. Libraries can use this feature and work in both contexts, providing a stepping stone to full generic methods in all Dart code. X is T will not work outside strong mode if T is a method type argument.

comments powered by Disqus