Tuesday, July 25, 2017

Why Is a String Called a String?

Why is a string called a string? Have you ever given this some thought? We never use such a word in contexts other than programming for a set of letters sticking together, and yet - in programming it's as pervasive as the word "variable". Why is that, and where does it come from?

To find out, we have to tackle some related terms first. History lesson time!

Abstract old calendar illustration

The word font is derived from the French fonte - something that has been melted; a casting. Given that letters for printing presses were literally made of metal and smelted at type foundries, that makes sense.

The metal letters of a font

The terms uppercase and lowercase refer to the literal part of the case in which the font was transported. So the printer (person) had a heavy case he lugged around or had set up at a printing press, and in this case were two "levels" - an upper case, and a lower case. The upper case contained only - you guessed it - UPPERCASE letters, while the lower case only contained lowercase ones.

Printing press case

You'll notice that there were more lowercase letters than uppercase ones. This was to be expected - a letter could only be used once on a single page and after all, a written body of text will have many more lowercase letters than uppercase ones, as there was no such thing as Youtube comments and CAPS LOCK yet.

So how does all this relate to strings?

Well, as printing became more mainstream and printing presses began offering their services to individuals, not just newspapers and publishers, it is said they decided to charge based on the length of the printed material - length in feet. Granted, a lot of this is speculative, but if they strung together the produced, printed material, they could easily estimate the costs and bill customers. So we can conclude with a reasonable degree of certainty that they used the word string in this context as a sequence of characters.

Still, how does this relate to the programming field? I mean, you could say a string of anything in regards to anything at all and it would make a degree of sense in the non-programming world. It's just a word that can be applied generally quite easily to things, even though it generally isn't.

What if we look across academia for first references?

A vector illustration of a person looking through binoculars

In 1944's Recursively enumerable sets of positive integers and their decision problems we have a mention that could vaguely resemble the modern definition:

For working purposes, we introduce the letter 6, and consider "strings" of 1's and b's such as 11b1bb1.

In this paper, the term refers to a sequence of identical symbols, so a string of 1's or a string of b's. Not exactly our definition but it's a start.

Continue reading %Why Is a String Called a String?%


by Bruno Skvorc via SitePoint

The Best Markdown Editors for Mac

The Best Markdown Editors for Mac

Markdown provides a convenient way to add formatting to a plain text document, while leaving it in plain text. It’s simpler and faster than adding HTML markup, and doesn’t have the lock-in of using something like Microsoft Word.

The syntax was created by John Gruber way back in 2004, and seems to become more widely used every year, especially in blogs and forums. It’s an easy and efficient way to create online content, and has a number of benefits for writers and bloggers.

Because Markdown is just plain text, you can create it with any text editor. That’s part of its appeal. But using an editor designed for writing in Markdown has a lot of advantages, depending on your needs.

Here are some features you might expect to find in a Markdown editor:

  • Syntax highlighting and a preview pane to show you how your final document will look.
  • Familiar keyboard shortcuts, like command-B for bold.
  • Export and conversion features that easily transform your document from Markdown to HTML, PDF, DOCX or a number of other formats. Some Markdown editors can publish directly to WordPress, Medium and more.
  • A distraction-free mode that takes advantage of features like full-screen editing, dark mode and typewriter mode.
  • Features that appeal to writers, including word count, readability scores, and versions.
  • A document library to organize your content and sync between devices. Some editors have an iOS version so you can keep working while you’re on the move.
  • Advanced formatting, including tables and mathematical expressions.

There’s a rich landscape of Mac options, and the best choice for me may not be the best choice for you. Not all Markdown editors will support all of those features, so the trick is to find the editor with the features you need.

So let’s have a good look at the options, then we’ll make some recommendations.


Looking for more on Markdown? Check out these great links:

Check out SitePoint Premium for more books, courses and free screencasts.


1. Use Your Favorite Text Editor

If you already have a favorite Mac text editor, you might prefer to use that for writing Markdown as well. Of course, Markdown is really just text, so any text editor will do. But many text editors have additional support for Markdown, either natively or through an extension or plugin. These may give syntax highlighting, a preview pane and other features.

Here are some examples:

2. Ulysses

  • Cost: $44.99, or subscribe via SetApp
  • Demo: Yes
  • Other platforms: iOS

The ultimate writing app for Mac, iPad and iPhone.

Ulysses is a full-featured Markdown app designed for writers. It’s designed to keep you focused on the writing task at hand, organize all your projects in one place, provide comprehensive writing features in a simple interface, and export your documents beautifully in a number of formats.

Distraction-free features include typewriter mode, dark themes, and full-screen editing. All of your documents can be accessed in a single library, whether they’re contained in Ulysses’ database or in files elsewhere. Filters can be used to create smart folders that update according to the flexible criteria you specify.

Writers will appreciate features like word and character count, writing goals that indicate when you reach the desired word count, notes and attachments for your reference information, and keywords. You can export your documents to a variety of text and rich text formats, HTML, ePub, PDF and DOCX. Or you can publish directly to WordPress or Medium.

My take: I purchased Ulysses on the day it was released, and I’ve been using it ever since. It has become my writing tool of choice. It’s not cheap, but it’s been worth every penny. If you do a lot of writing, professionally or otherwise, take a good look at this app.

A screen shot of the Ulysses editor

3. Quiver

  • Cost: $9.99
  • Demo: Yes
  • Other platforms: iOS (coming)

The programmer’s notebook

Quiver is designed for developers, and can combine text, code, Markdown and LaTeX in a single note. It’s more than just a document editor: it’s a complete reference library for your documentation.

The editor gives you syntax highlighting and a live preview of your rendered Markdown, and offers cloud syncing, team collaboration, version control and backup. Programmers will appreciate code editing and the ability to write scripts to integrate Quiver with your other tools.

The document library can organize your notes by tag or notebook (including shared notebooks), and has instant, full-text search. Images are saved locally with notes, and displayed inline.

My take: Quiver is the ultimate Markdown (and code and LaTeX) editor for devs. Its document library can be synced to your other computers and devices via Dropbox. It’s a geekier alternative to Ulysses, designed with a completely different audience in mind, at an affordable price point.

A screen shot of the Quiver editor

Continue reading %The Best Markdown Editors for Mac%


by Adrian Try via SitePoint

Alessandro Rigobello

Alessandro Rigobello

Fun interactive bio filled with awesome GIFs in this One Page portfolio for designer, Alessandro Rigobello. (I reduced the portfolio items in this screenshot for load time purposes)

by Rob Hope via One Page Love

Ryan Morrison

Ryan Morrison

Minimal One Pager for Webflow designer Ryan Morrison featuring a few interactive floating images.

by Rob Hope via One Page Love

What Are GitHub Pull Requests?

Getting Started With Matter.js: The Engine and World Modules

In the introductory tutorial of this series, you were briefly introduced to different modules in Matter.js. The library contains a lot of modules, so it was impractical to write in detail about each of them in a single tutorial. After reading the first part of the series, you should now have a general idea of the library and its features.

In this tutorial, we will just focus on the World module and the Engine module in Matter.js. The World module provides us with the necessary methods and properties to create and manipulate the world composite. You can use it to add or remove different bodies from the world. The Engine module contains methods for creating and manipulating the engines that are responsible for creating the simulation of your world.

The World Module

In this section, you will learn about different methods, properties and events of the World module. World is actually a Composite with additional properties like gravity and bounds added to it. Here is a list of important methods available in this module:

  • add(composite, object): This method is inherited from the Composite module and allows you to add one or more body(s), composite(s) or constraint(s) to the given composite or world. 
  • addBody(world, body): This method allows you to add individual body elements to the given world. There are also addComposite() and addConstraint() methods that allow you to add a composite or constraint to the world.

The code below uses both these methods to add different bodies to the world. The add() method adds three static rectangles that act as walls. The addBody() method adds a circle, square or rectangle based on the button clicked by the user.

You can see that the isStatic key has been set to true for the three walls in our world. Setting this key to true for any object makes that object completely static. The object will never change its position or angle now. There are a lot of other properties that can be specified to control the behavior of different objects. You will learn about all of them in the Body module tutorial of this series.

  • remove( composite, object, [deep=false]): This is a generic method to remove one or more body(s), composite(s) or constraint(s) from the given composite or world. For example, you could use the following line to remove the top and left walls from the world.
  • clear( world, keepStatic): This method is an alias for its Composite counterpart. You can use it to remove all the elements from the world at once. The second parameter is a Boolean which can be used to prevent static elements from being cleared. Its value is false by default. This means that calling World.clear( world) will remove all the elements from that particular world.
  • rotate( composite, rotation, point, [recursive=true]): This method can be used to rotate all the children in a given world or composite by a specific angle around the provided point. The angle given here is in radians. The point parameter determines the point for rotation.
  • scale( composite, scaleX, scaleY, point, [recursive=true]): You can use this method to scale all the children of your composite or world by the given values. This method scales everything from width, height and area to mass and inertia.
  • translate(composite, translation, [recursive=true]): The translate method is useful when you want to translate or move all the children of a world or composite by a given vector relative to their current positions. 

One thing you should keep in mind is that neither translate() nor rotate() imparts any kind of velocity to the bodies in the world. Any motion that occurs is just the result of changes in the shape or position of different bodies. Here is some code to scale, rotate and translate a world based on button clicks:

You should note that the above code applies a different scale on the x and y axis. This turns the circle in our Matter.js world into an oval. The oval then topples to go to a more stable state with lower potential energy.

Try pressing the Scale button in the above demo. After that, press the Rotate button to see how closely Matter.js simulates the real-life motion of an oval.

Besides all these methods, the World module has a lot of useful properties as well. For example, you can get an array of all the bodies that are direct children of the world composite using world.bodies. Similarly, you can get an array of all the composites and constraints using world.composites and world.constraints

You can also specify the bounds of the world within which Matter.js should detect collisions using world.bounds. One interesting thing that you can change with the world properties is gravity. The gravity along the x and y axis is set to 0 and 1 by default. You can change these values using world.gravity.x and world.gravity.y respectively.

You should visit the Matter.World documentation page to read more about this module.

The Engine Module

The Engine module is necessary for properly updating the simulation of the world. Here is a list of some important methods of the Engine module.

  • create([options]): This method is useful when you want to create a new engine. The options parameter in this method is actually an object with key-value pairs. You can use options to override the default values for different properties of the engine. For example, you can use the timeScale property to slow down or speed up the simulation. 
  • update(engine, [delta=16.666], [correction=1]): This method will move the simulation forward in time by delta ms. The value of the correction parameter specifies the time correction factor to apply after the update. This correction is usually only necessary when the delta is changing between each update.
  • merge(engineA, engineB): This method will merge two engines specified by the given parameters. While merging, the configuration is applied from engineA and the world is taken from engineB.

The Engine module also has a lot of other properties to help you control the quality of the simulation. You can set a value for constraintIterations, positionIterations or velocityIterations to specify the number of constraint, position and velocity iterations to perform during each update. A higher value in each case will provide a better simulation. However, a higher value will also adversely affect the performance of the library.

You can set a value for the timing.timeScale property to control the speed at which the simulation occurs. Any value below 1 will result in a slow-motion simulation. Setting this property to zero will completely freeze the world. The following example should make it clear.

You might have noticed that the balls are bouncing off the ground this time. Every rigid body has a coefficient of restitution set to 0 by default. This gives them clay-like properties, and they don't bounce back on collision. I have changed the restitution value to 1 so that the balls can easily bounce back. 

You will learn about all these properties of rigid bodies in the next tutorial of the series. For now, add some circles or balls to the world and try pressing the slow motion and fast motion buttons to notice the difference.

You should visit the Matter.Engine documentation page to read more about this module.

Conclusion

This tutorial discussed two very important modules in Matter.js that you need to know about in order to run any simulations. After reading this tutorial, you should be able to scale, rotate, slow down or speed up your world. Now, you also know how to remove or add bodies to a world. This can be helpful when you are developing 2D games.

In the next tutorial of the series, you will learn about the different methods, properties and events available in the Bodies module.


by Monty Shokeen via Envato Tuts+ Code

How to Create a Snapchat Geofilter on Your Phone

Want to design Snapchat geofilters on the go? Have you seen the Snapchat in-app geofilter creation tool? In this article, you’ll discover how to easily create and purchase custom Snapchat geofilters from within the mobile app. #1: Design Your Snapchat On-Demand Geofilter To get started creating your geofilter, open the Snapchat app. From the camera [...]

This post How to Create a Snapchat Geofilter on Your Phone first appeared on .
- Your Guide to the Social Media Jungle


by Shaun Ayala via