The OverloadedStrings language pragma can be enabled either by passing the -XOverloadedStrings switch to GHC or you can just add the following to the top of your Haskell source:
{-# LANGUAGE OverloadedStrings #-}
The OverloadedStrings language pragma changes the way that literal strings identify themselves, in a way that favours performance. [Char] is a rather cumbersome type to be used when dealing with something as primitive as a string.
The literal string "Hello, world" now identifies as a call to the fromString function out of the IstString type class. You can define instances like so:
The abstract window toolkit provide the programmer with a great level of flexibility when creating user interfaces. Today’s blog post is going to go through the basic setup of a double-buffered animation loop implemented in Java, using AWT.
Settings
First off, we start by making some system settings; setting up to use OpenGL, etc:
static{System.setProperty("sun.java2d.trace","timestamp,log,count");System.setProperty("sun.java2d.transaccel","True");System.setProperty("sun.java2d.opengl","True");System.setProperty("sun.java2d.d3d","false");//default on windowsSystem.setProperty("sun.java2d.ddforcevram","true");}
We’ll draw to a Canvas and flip that onto our Frame. We need to configure the Canvas so that it’ll behave in a render-loop fashion, rather than responding to paint messages as it does normally.
Now comes the double-buffer part. We create a BufferStrategy using createBufferStrategy. The strategy is what holds our graphics objects that we’ll render to.
The pump for the application is the renderer. It’s pretty simple:
publicvoidrender(){// get the graphics objectGraphics2DbkG=(Graphics2D)strategy.getDrawGraphics();// start with a black canvasbkG.setPaint(backgroundGradient);bkG.fillRect(0,0,getWidth(),getHeight());// TODO: Here's where the render code goes// release the resources held by the background imagebkG.dispose();// flip the back buffer nowstrategy.show();Toolkit.getDefaultToolkit().sync();}
Get running
Here is a class that you can use to get running immediately.
Git provides some excellent features when you need to amend your commit history before pushing your changes into a repository. In today’s article, I’ll run through a relativly simple use-case of the rebase command and how you can squash commits down.
This blog
I’ve recently changed text editors from Sublime back to vim. In the repository of this blog, I have a script that bootstraps a blog post with the title and date; and then opens my text editor ready for me to write.
Today I also patched a small bug where, when the file name is calculated from the title of the blog I specify - consecutive letters were being de-duplicated. Made it a real pain for a lot of words . . so, this changed. These two changes occured on the same file, new-post.sh; but I didn’t think about changing my text editor until after.
The first change
So, the first change went into the file. I staged the change and then committed it:
This sucks. Really only wanted this in the one commit. So, I kicked off rebase in interactive mode (with -i).
➜ tuttlem.github.io git:(master) git rebase -i origin/master
This opened up a text editor for me, allowing me to make changes.
Changing history!
You’re presented with a list of commits that haven’t yet been pushed to the server. You’re also given the opportunity to change what goes on with these before you push:
pick 50412a2 New article
pick 3029ddc New article
pick e8df37a New article
pick ef5028c New article
pick e151644 New article
pick 378fc34 New article
pick eaccbd8 New article
pick 05c2d82 New article
pick d60be6a New articles
pick 5b7b3b4 Patched create script
pick 7408fdf Changed editor
# Rebase 5c2c93d..7408fdf onto 5c2c93d (11 command(s))
#
# Commands:
# p, pick = use commit
# r, reword = use commit, but edit the commit message
# e, edit = use commit, but stop for amending
# s, squash = use commit, but meld into previous commit
# f, fixup = like "squash", but discard this commit's log message
# x, exec = run command (the rest of the line) using shell
# d, drop = remove commit
#
# These lines can be re-ordered; they are executed from top to bottom.
#
# If you remove a line here THAT COMMIT WILL BE LOST.
#
# However, if you remove everything, the rebase will be aborted.
#
# Note that empty commits are commented out
I just want 7408fdf squashed into 5b7b3b4. I also want to change the commit message of 5b7b3b4. Afterwards, I’d learned that git will give me the opportunity to re-word this to combine commit messages.
pick 50412a2 New article
pick 3029ddc New article
pick e8df37a New article
pick ef5028c New article
pick e151644 New article
pick 378fc34 New article
pick eaccbd8 New article
pick 05c2d82 New article
pick d60be6a New articles
reword 5b7b3b4 Patched create script and changed editor
squash 7408fdf Changed editor
Saving this file off, we’re now presented with another text editor that allows us to update the commit message accordingly. After a bit of processing, we’re done:
➜ tuttlem.github.io git:(master) git rebase -i origin/master
[detached HEAD f0b825a] Patched create script
Date: Wed Mar 8 11:54:00 2017 +1000
1 file changed, 1 insertion(+), 1 deletion(-)
[detached HEAD 7bc6902] Patched create script
Date: Wed Mar 8 11:54:00 2017 +1000
1 file changed, 2 insertions(+), 2 deletions(-)
Successfully rebased and updated refs/heads/master.
Your git log should now confirm that everything has gone to plan:
commit 7bc6902d2543eb87dad14b088edc9a5506295809
Author: Michael Tuttle <tuttlem@gmail.com>
Date: Wed Mar 8 11:54:00 2017 +1000
Patched create script
Changed editor
Patched create script and changed editor
commit d60be6ae1acc508669193a5bfead887913284aef
Author: Michael Tuttle <tuttlem@gmail.com>
Date: Fri Mar 3 20:04:06 2017 +1000
New articles