Code Monkey home page Code Monkey logo

code-cookbook's Introduction

Haxe Code Cookbook

Build Status

Sources for the Haxe Code Cookbook site, a community driven resource website for learning Haxe in practise.

The repository contains a static website generator, which converts markdown articles into a website. The project is being developed here on GitHub, feel free to contribute Haxe related code snippets and tutorials.

Structure

  • The actual articles are in assets/content/cookbook, organized per folder.
  • The html template files are in assets/content/.
  • The static files (css, js, images) files are in assets/includes/.
  • The Haxe source files of the generator are in src/.
  • The website-generated content will output in output/ (excluded from git).

Contributing

Contributing changes

To contribute a change, you have to make a pull request. This can be done using the GitHub website or by fork/cloning the project.

Contributing using GitHub as online editor

This is the easiest way of doing small changes:

  • Navigate to an article on https://code.haxe.org and press the edit button on any page: image
  • You are redirected to GitHub. Once you have an account and are logged in, you can make the change in the online editor.
  • Set the description / what you changed and press the Request change button: image
  • A pull request will be created. GitHub makes a fork for you automatically.
Contributing using a fork

This would also allow to test/see the changes before submitting which is also useful when you want to add new pages.

  • Make a fork (on GitHub) of the project.
  • Checkout your repo on your machine, create a new branch for the pull request.
  • Make the changes in that new branch.
  • Push the commits (they go to your fork).
  • On GitHub, you make a pull request from your fork's branch to the original repo.

Creating articles

Please add/edit the articles (markdown files) in the assets folder and do a pull request. The scope of the cookbook includes the core language, the standard library, and also any libraries maintained by the Haxe Foundation.

Formatting

It would be nice if you keep the formatting of the code in the same style as used already:

  • Braces on same line.
  • Two-space indentation.
  • No type-hints for local variables and function return unless it's instructive.
  • Type-hints for fields.
  • Type-hints for function arguments unless it's very obvious.
  • Judicious use of extra line-breaks to avoid ugly automatic breaks (check the output).

Other remarks

  • The first heading is used in the navigation. Keep this title short.
  • The first paragraph is used as description. Describe what the content of the article is about.
  • Use > Author: [Name](https://github.com/username) to mark yourself as author of the article. The other contributors are inferred from git commits.
  • Tag the article using [tags]: / "tag1,tag2" (no spaces). Try to use an existing tag.
  • Mention the author / sources at the bottom of the page.
  • If you want to include a try.haxe.org code snippet use [tryhaxe](https://try.haxe.org/embed/76f24).
  • If you want to include a YouTube video use [youtube](https://www.youtube.com/watch?v=dQw4w9WgXcQ).
  • If possible, link to related pages in the Haxe Manual / API documentation.
  • If you want to use images or other includes, create a folder called assets in the same directory as the article and link to that.

This would be a typical template to use. Use ```haxe for syntax highlighting:

[tags]: / "class,array,json,building-fields"

# Title of the page

Description and explanation of the code.

## Implementation
```haxe
class Main {
  // Code here
}
```

## Usage

Description of how to use/test the code.

```haxe
class Test {
  // Code here
}
```

> More on this topic: 
> 
> * [Class field in Haxe Manual](https://haxe.org/manual/class-field.html)
> 
> Author: [Name](https://github.com/username)

Running a local copy

To run the project you can use Neko:

Call neko CodeCookBook.n to re-generate the output files.

Contributing to the generator

You need Haxe 3.4.2+ installed.

The static site generator source depends on hxtemplo and haxe-markdown.

Install the libraries using haxelib, run the following command in the root of the project:

haxelib install all

The CSS files are compressed using less. Install from npm:

npm install -g less
npm install -g less-plugin-clean-css

code-cookbook's People

Contributors

andyli avatar aurel300 avatar cambiata avatar cancerberosgx avatar confidantcommunications avatar dstrekelj avatar fhalo48 avatar flashultra avatar francescoagati avatar gama11 avatar gogoprog avatar gulvan0 avatar haxiomic avatar ibilon avatar jcward avatar klabz avatar lewislepton avatar markknol avatar mrcdk avatar nadako avatar r32 avatar realyuniquename avatar romamik avatar sehnsucht13 avatar simn avatar t1ml3arn avatar tomashubelbauer avatar uvtc avatar vascofr avatar xvw avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

code-cookbook's Issues

Deployment

Have: No deployment
Want: Deployment

That's all I really know about this repository at the moment. Assigning to special CI investigator Rudy!

Make it possible to group entries if they are part of a series

Currently, the cookbook is designed to accommodate single entries grouped by tags and categories. This is great for code snippets and small examples.

However, there is no way to effectively group together a series of entries, for instance, that concern the development of a (larger) project. Displaying every series entry in the sidebar would quickly inflate the sidebar and make it hard to navigate.

I would like to discuss the possibility of supporting a system for series. I feel like this is a necessity if bigger examples are to be hosted by the cookbook, such as those that were present in the old Haxe documentation.

Here is a proposal to start things off:

  • Series of examples are placed in their own category (e.g. "Series")
  • A series has a landing page, which will be accessible from the sidebar
    • The landing page briefly describes the series - its topic, motivation, and proposed solution
    • It serves as both the series' introduction and table of contents
  • Every entry contains links to other entries, including the landing page
    • Note that this would not mean the behaviour of a series page imitates a single-page application

The folder structure might look something like this:

cookbook
+- ...
`- Series
  `- my-cool-series
    +- my-cool-series.md
    +- my-cool-series-1-set-up.md
    +- my-cool-series-2-tear-down.md
    `- my-cool-series-3-conclusion.md

I'm interested in hearing your thoughts on the matter!

Suggestion: Using arrays

Sources:

@dstrekelj

This is not likely the proper way to post this comment, but I am presuming that whomever owns/manages this documentation facility will receive some notification. Hopefully, you will be able to read my comments and then simply delete it so that it won't clutter your work.

I strongly feel the need to comment upon the high quality of the work being shown in the evolution of this Cookbook. I have decades of experience in dealing with the frustrations that arise wherever the documentation of new technology is required. Indeed, since I have spent about 12 hours per day and night for each of the last ten days in trying to get my arms around so many new pieces of technology from the Haxe ecosystem, and since much of that effort has resulted in incomplete and/or out of date snippets of information, that finally coming upon this work has truly been refreshing.

Several key ingredients are necessary to getting tutorial documentation right. The first key ingredient is the absolute understanding that the top-level stake holders must make. Where such stake-holders mostly come from the software engineering ranks, there is all-too-often a failure to understand and a failure to insist upon the timely release of documentation amidst the always-present pressure to release some new block of code. The second key ingredient is recognizing that the old fashioned ability to craft words in well-organized paragraphs never goes away -- the short-hand acronymiphomia that we have as writers of code, can never be used as some sort of a stand-in for quality writing by those dedicated to that profession. The third key ingredient comes from watching how these sorts of on-line references have evolved since the folks at Sun released the first java docs, but especially outstanding has been the manner in which Adobe evolved the living ActionScript documentation repleat with meaningful examples.

You are on the right track with what I have read so far and I hope you will be given the mandate and support to aggressively work towards a higher percentage of the total toolkit being properly documented. The toolkit, of course, has achieved earned respect for what it represents, but unless its key features can be properly conveyed to newcomers, its capture of the marketplace will always remain small. In the final analysis, engineers, marketeers and documentation specialists work together to get on paper and in a few well-contrived graphics the important facts that a user must master in order to move forward in developing applications with that toolkit.

Suggestion: Loading an external file - fails with quotes

var http = new haxe.Http("https://api.ipify.org?format=json");
http.onData = function (data:String) {
var result = haxe.Json.parse(data);
trace('Your IP-address: ${result.ip}');
}

http.onError = function (error) {
trace('error: $error');
}
http.request();

the above does not work. it throws an error in the most current haxe (2.4.6)

the code below does work. change the " changed to '
now it works and gives the jsonified ip address
I have NO idea what changeing the " to ' made it work.

var http = new haxe.Http('http://api.ipify.org?format=json);    
http.onData = function (data:String) {   
var result = haxe.Json.parse(data);  
trace('Your IP-address: ${result.ip}');  
}  
http.onError = function (error) {  
trace('error: $error');  
}  
http.request();  

Sources:

Fix travis

It does compile but the neko call to generate stuff fails.

Matching on Structures: example not correct

Table of contents -> Beginner -> Pattern matching -> Matching on structures:

If we would like to trace the age of the person in the first case we could have written
case { age: age > 50 => true}: trace('found somebody older than 50, the age is $age').

does not evaluate as expected.

To get the expected result it should be written something like:

case {age: age} if (age > 50): trace('found somebody older than 50, the age is $age.');

Wanted articles

If you are in the mood for writing but don't know what, then you can use this list:

  • Beginner - Lists and Arrays
  • Beginner - Using Regular Expressions
  • Beginner - Using Math
  • Beginner - Using abstract
  • Beginner - Using enum / ADT
  • Beginner - Using strings
  • Beginner - Using numbers
  • Beginner - Type parameters and generics
  • Beginner - Using FileSystem - add section about Path
  • Using Sys stuff to write command line tools
  • Using sys.io.Process
  • Pattern Matching examples
  • How to use Array Access
  • How to type Json using typedefs
  • Examples of expression reification
  • Examples of type reification
  • Examples of class reification
  • Using HXML (https://blog.onthewings.net/2013/03/04/hxml-tricks-every-haxe-user-should-know/) this is in manual now
  • Mainloop / Timing / Delays / Intervals
  • Using Haxe to make backend API
  • Using Haxe to make command line tool
  • Using Haxe to make static websites (like code.haxe.org ๐Ÿ˜‰)
  • onAfterGenerate
  • JavaScript: macro --include to bundle external js files
  • JavaScript: Use promises
  • JavaScript: How to use/manipulate DOM
  • JavaScript: Use canvas
  • JavaScript: Use webGL
  • JavaScript: Use camera
  • JavaScript: Get location
  • JavaScript: Send notifications
  • JavaScript: Use virtual dom
  • JavaScript: Output ES6
  • JavaScript: Split output https://github.com/elsassph/haxe-modular
  • JavaScript: Use local storage
  • JavaScript: Minify / get smallest output / make project production ready https://github.com/back2dos/closure or uglify
  • Make simple game

Btw, these titles are suggestions. This list will get updated over time.

VGA text renderer

anniz on #haxe posted a fun little example of a vga text renderer:

class Main {
    static var Font = [
        0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
        0x7E,0x81,0xA5,0x81,0xBD,0x99,0x81,0x7E,
        0x7E,0xFF,0x00,0xFF,0xC3,0xE7,0xFF,0x7E,
        0x6C,0xFE,0xFE,0xFE,0x7C,0x38,0x10,0x00,
        0x10,0x38,0x7C,0xFE,0x7C,0x38,0x10,0x00,
        0x38,0x7C,0x38,0xFE,0xFE,0x92,0x10,0x7C,
        0x00,0x10,0x38,0x7C,0xFE,0x7C,0x38,0x7C,
        0x00,0x00,0x18,0x3C,0x3C,0x18,0x00,0x00,
        0xFF,0xFF,0xE7,0xC3,0xC3,0xE7,0xFF,0xFF,
        0x00,0x3C,0x66,0x42,0x42,0x66,0x3C,0x00,
        0xFF,0xC3,0x99,0xBD,0xBD,0x99,0xC3,0xFF,
        0x0F,0x07,0x0F,0x7D,0xCC,0xCC,0xCC,0x78,
        0x3C,0x66,0x66,0x66,0x3C,0x18,0x7E,0x18,
        0x3F,0x33,0x3F,0x30,0x30,0x70,0xF0,0xE0,
        0x7F,0x63,0x7F,0x63,0x63,0x67,0xE6,0xC0,
        0x99,0x5A,0x3C,0xE7,0xE7,0x3C,0x5A,0x99,
        0x80,0xE0,0xF8,0xFE,0xF8,0xE0,0x80,0x00,
        0x02,0x0E,0x3E,0xFE,0x3E,0x0E,0x02,0x00,
        0x18,0x3C,0x7E,0x18,0x18,0x7E,0x3C,0x18,
        0x66,0x66,0x66,0x66,0x66,0x00,0x66,0x00,
        0x7F,0x00,0x00,0x7B,0x1B,0x1B,0x1B,0x00,
        0x3E,0x63,0x38,0x6C,0x6C,0x38,0x86,0xFC,
        0x00,0x00,0x00,0x00,0x7E,0x7E,0x7E,0x00,
        0x18,0x3C,0x7E,0x18,0x7E,0x3C,0x18,0xFF,
        0x18,0x3C,0x7E,0x18,0x18,0x18,0x18,0x00,
        0x18,0x18,0x18,0x18,0x7E,0x3C,0x18,0x00,
        0x00,0x18,0x0C,0xFE,0x0C,0x18,0x00,0x00,
        0x00,0x30,0x60,0xFE,0x60,0x30,0x00,0x00,
        0x00,0x00,0xC0,0xC0,0xC0,0xFE,0x00,0x00,
        0x00,0x24,0x66,0xFF,0x66,0x24,0x00,0x00,
        0x00,0x18,0x3C,0x7E,0xFF,0xFF,0x00,0x00,
        0x00,0xFF,0xFF,0x7E,0x3C,0x18,0x00,0x00,
        0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
        0x18,0x3C,0x3C,0x18,0x18,0x00,0x18,0x00,
        0x6C,0x6C,0x6C,0x00,0x00,0x00,0x00,0x00,
        0x6C,0x6C,0xFE,0x6C,0xFE,0x6C,0x6C,0x00,
        0x18,0x7E,0xC0,0x7C,0x06,0xFC,0x18,0x00,
        0x00,0xC6,0xCC,0x18,0x30,0x66,0xC6,0x00,
        0x38,0x6C,0x38,0x76,0xDC,0xCC,0x76,0x00,
        0x30,0x30,0x60,0x00,0x00,0x00,0x00,0x00,
        0x18,0x30,0x60,0x60,0x60,0x30,0x18,0x00,
        0x60,0x30,0x18,0x18,0x18,0x30,0x60,0x00,
        0x00,0x66,0x3C,0xFF,0x3C,0x66,0x00,0x00,
        0x00,0x18,0x18,0x7E,0x18,0x18,0x00,0x00,
        0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x30,
        0x00,0x00,0x00,0x7E,0x00,0x00,0x00,0x00,
        0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x00,
        0x06,0x0C,0x18,0x30,0x60,0xC0,0x80,0x00,
        0x7C,0xCE,0xDE,0xF6,0xE6,0xC6,0x7C,0x00,
        0x30,0x70,0x30,0x30,0x30,0x30,0xFC,0x00,
        0x78,0xCC,0x0C,0x38,0x60,0xCC,0xFC,0x00,
        0x78,0xCC,0x0C,0x38,0x0C,0xCC,0x78,0x00,
        0x1C,0x3C,0x6C,0xCC,0xFE,0x0C,0x1E,0x00,
        0xFC,0xC0,0xF8,0x0C,0x0C,0xCC,0x78,0x00,
        0x38,0x60,0xC0,0xF8,0xCC,0xCC,0x78,0x00,
        0xFC,0xCC,0x0C,0x18,0x30,0x30,0x30,0x00,
        0x78,0xCC,0xCC,0x78,0xCC,0xCC,0x78,0x00,
        0x78,0xCC,0xCC,0x7C,0x0C,0x18,0x70,0x00,
        0x00,0x18,0x18,0x00,0x00,0x18,0x18,0x00,
        0x00,0x18,0x18,0x00,0x00,0x18,0x18,0x30,
        0x18,0x30,0x60,0xC0,0x60,0x30,0x18,0x00,
        0x00,0x00,0x7E,0x00,0x7E,0x00,0x00,0x00,
        0x60,0x30,0x18,0x0C,0x18,0x30,0x60,0x00,
        0x3C,0x66,0x0C,0x18,0x18,0x00,0x18,0x00,
        0x7C,0xC6,0xDE,0xDE,0xDC,0xC0,0x7C,0x00,
        0x30,0x78,0xCC,0xCC,0xFC,0xCC,0xCC,0x00,
        0xFC,0x66,0x66,0x7C,0x66,0x66,0xFC,0x00,
        0x3C,0x66,0xC0,0xC0,0xC0,0x66,0x3C,0x00,
        0xF8,0x6C,0x66,0x66,0x66,0x6C,0xF8,0x00,
        0xFE,0x62,0x68,0x78,0x68,0x62,0xFE,0x00,
        0xFE,0x62,0x68,0x78,0x68,0x60,0xF0,0x00,
        0x3C,0x66,0xC0,0xC0,0xCE,0x66,0x3A,0x00,
        0xCC,0xCC,0xCC,0xFC,0xCC,0xCC,0xCC,0x00,
        0x78,0x30,0x30,0x30,0x30,0x30,0x78,0x00,
        0x1E,0x0C,0x0C,0x0C,0xCC,0xCC,0x78,0x00,
        0xE6,0x66,0x6C,0x78,0x6C,0x66,0xE6,0x00,
        0xF0,0x60,0x60,0x60,0x62,0x66,0xFE,0x00,
        0xC6,0xEE,0xFE,0xFE,0xD6,0xC6,0xC6,0x00,
        0xC6,0xE6,0xF6,0xDE,0xCE,0xC6,0xC6,0x00,
        0x38,0x6C,0xC6,0xC6,0xC6,0x6C,0x38,0x00,
        0xFC,0x66,0x66,0x7C,0x60,0x60,0xF0,0x00,
        0x7C,0xC6,0xC6,0xC6,0xD6,0x7C,0x0E,0x00,
        0xFC,0x66,0x66,0x7C,0x6C,0x66,0xE6,0x00,
        0x7C,0xC6,0xE0,0x78,0x0E,0xC6,0x7C,0x00,
        0xFC,0xB4,0x30,0x30,0x30,0x30,0x78,0x00,
        0xCC,0xCC,0xCC,0xCC,0xCC,0xCC,0xFC,0x00,
        0xCC,0xCC,0xCC,0xCC,0xCC,0x78,0x30,0x00,
        0xC6,0xC6,0xC6,0xC6,0xD6,0xFE,0x6C,0x00,
        0xC6,0xC6,0x6C,0x38,0x6C,0xC6,0xC6,0x00,
        0xCC,0xCC,0xCC,0x78,0x30,0x30,0x78,0x00,
        0xFE,0xC6,0x8C,0x18,0x32,0x66,0xFE,0x00,
        0x78,0x60,0x60,0x60,0x60,0x60,0x78,0x00,
        0xC0,0x60,0x30,0x18,0x0C,0x06,0x02,0x00,
        0x78,0x18,0x18,0x18,0x18,0x18,0x78,0x00,
        0x10,0x38,0x6C,0xC6,0x00,0x00,0x00,0x00,
        0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,
        0x30,0x30,0x18,0x00,0x00,0x00,0x00,0x00,
        0x00,0x00,0x78,0x0C,0x7C,0xCC,0x76,0x00,
        0xE0,0x60,0x60,0x7C,0x66,0x66,0xDC,0x00,
        0x00,0x00,0x78,0xCC,0xC0,0xCC,0x78,0x00,
        0x1C,0x0C,0x0C,0x7C,0xCC,0xCC,0x76,0x00,
        0x00,0x00,0x78,0xCC,0xFC,0xC0,0x78,0x00,
        0x38,0x6C,0x64,0xF0,0x60,0x60,0xF0,0x00,
        0x00,0x00,0x76,0xCC,0xCC,0x7C,0x0C,0xF8,
        0xE0,0x60,0x6C,0x76,0x66,0x66,0xE6,0x00,
        0x30,0x00,0x70,0x30,0x30,0x30,0x78,0x00,
        0x0C,0x00,0x1C,0x0C,0x0C,0xCC,0xCC,0x78,
        0xE0,0x60,0x66,0x6C,0x78,0x6C,0xE6,0x00,
        0x70,0x30,0x30,0x30,0x30,0x30,0x78,0x00,
        0x00,0x00,0xCC,0xFE,0xFE,0xD6,0xD6,0x00,
        0x00,0x00,0xB8,0xCC,0xCC,0xCC,0xCC,0x00,
        0x00,0x00,0x78,0xCC,0xCC,0xCC,0x78,0x00,
        0x00,0x00,0xDC,0x66,0x66,0x7C,0x60,0xF0,
        0x00,0x00,0x76,0xCC,0xCC,0x7C,0x0C,0x1E,
        0x00,0x00,0xDC,0x76,0x62,0x60,0xF0,0x00,
        0x00,0x00,0x7C,0xC0,0x70,0x1C,0xF8,0x00,
        0x10,0x30,0xFC,0x30,0x30,0x34,0x18,0x00,
        0x00,0x00,0xCC,0xCC,0xCC,0xCC,0x76,0x00,
        0x00,0x00,0xCC,0xCC,0xCC,0x78,0x30,0x00,
        0x00,0x00,0xC6,0xC6,0xD6,0xFE,0x6C,0x00,
        0x00,0x00,0xC6,0x6C,0x38,0x6C,0xC6,0x00,
        0x00,0x00,0xCC,0xCC,0xCC,0x7C,0x0C,0xF8,
        0x00,0x00,0xFC,0x98,0x30,0x64,0xFC,0x00,
        0x1C,0x30,0x30,0xE0,0x30,0x30,0x1C,0x00,
        0x18,0x18,0x18,0x00,0x18,0x18,0x18,0x00,
        0xE0,0x30,0x30,0x1C,0x30,0x30,0xE0,0x00,
        0x76,0xDC,0x00,0x00,0x00,0x00,0x00,0x00,
        0x00,0x10,0x38,0x6C,0xC6,0xC6,0xFE,0x00
    ];

    public static function PcRenderLetter(charCode:Int, colorOn:Int, colorOff:Int, baseRow:Int, baseCol:Int, targetBMD:flash.display.BitmapData) {
        var baseIndex = charCode << 3;
        for (curRow in 0...8) {
            var rowBits = Font[baseIndex + curRow];
            for (curCol in 0...8) {
                targetBMD.setPixel32(baseCol+curCol, baseRow+curRow, (((rowBits << curCol) & 0x80) == 0x80)? colorOn : colorOff);
            }
        }
    }

    public static function main() {
        var bmd = new flash.display.BitmapData(320, 200, false, 0);
        var bm = new flash.display.Bitmap(bmd);

        var msgLines = [
            "256KB OK",
            "",
            "",
            "The current date is: Thu 04/20/1989",
            "Enter new date: (mm-dd-yy)",
            "",
            "The current time is: 03:14:15.9",
            "Enter new time:",
            "",
            "",
            "MS-DOS 2.04",
            "",
            "A:\\>"
        ];

        for (j in 0...msgLines.length) {
            var msgStr = msgLines[j];
            for (i in 0...msgStr.length) {
                var c = msgStr.charCodeAt(i);
                PcRenderLetter(c, 0xa0a0a0, 0, (j>>1) + (j<<3), (i>>1) + (i<<3), bmd);
            }
        }
        flash.Lib.current.addChild(bm);
    }
}

Maybe we could port it to canvas?

Request for "Graphics" section and initial tentative start on colored triangle webgl.

Mark

Hi I started on improving the webgl triangle example ( just colored triangles yet to tidy up the image one yet ), and have made a start on a tutorial but there is just so much to cover it's tricky to know if I have the patience to try to go into every detail, but it's a start, but I suggest that Codebook has a Intermediate "Graphics" section where I could also add swing, svg, canvas, flash, kha, flambe, flump examples of triangle drawing, rendering an image etc..

https://github.com/Justinfront/CookbookGraphics/blob/master/cookbookGraphics/triangleHaxeLogo/webgl/tutorial/webgl_triangleHaxeLogo.md

I don't know it this quite fits with your vision please let me know if this is useful and worth integration of some form, also maybe if it is then it would be good to continue it separately before forming a pull ?

Best Justin

Class reification for building fields

Recently found this:
https://github.com/lbergman/GASM/blob/develop/src/gasm/core/macros/ComponentMacros.hx#L37-L52

After some investigation, I heard you can do (macro class { ... }).fields.

As example it can be reduced to:

var fields = Context.getBuildFields();

var name = "Message";
var extraFields = (macro : {
	public function name(get, null):String;
	private inline function get_name() return $v{name};
	public static var NAME:String = $v{name};
}).fields;

fields = fields.concat(extraFields);

Some info from nadako:

One just has to remember - macro something is just a syntax sugar for creating data structures (Expr, TypeDefinition, ComplexType, etc), so of course if you create macro class {...} that's going to be a TypeDefinition, so you can access its fields normally
I almost always create fields manually, but for exprs I use reification. It doesn't feel right to create a TypeDefinition that will be thrown away later, but OTOH Haxe will inline and eliminate it.

This is awesome and much more readable than creating fields manually for some cases.

ref https://haxe.org/manual/macro-reification-class.html

TODO: Make article about this, and/or integrate in those https://code.haxe.org/tag/building-fields.html

Article (Git) dates are incorrect

Article: https://code.haxe.org/category/principles/null-safety.html

"Created: Jan 02, 2018 Last modified: Nov 16, 2017"

Actual history: https://github.com/HaxeFoundation/code-cookbook/commits/master/assets/content/cookbook/Principles/Null-safety.md


Code to blame:

static function getCreationDate(path:String):Date {
#if !display
var process = new sys.io.Process('git', ['log','--diff-filter=A','--follow','--date=short','--format=%ad', '-1', '--', path]);
if (process.exitCode() != 0) throw process.stderr.readAll().toString();
var dateString = process.stdout.readAll().toString();
dateString = dateString.replace("\n", "").replace("\r", "");
if (dateString == null || dateString.length < 8) return Date.now();
return Date.fromString(dateString);
#else
return Date.now();
#end
}
static function getModificationDate(path:String):Date {
#if !display
var process = new sys.io.Process('git', ['log','--date=short','--format=%ad', '-1', '--', path]);
if (process.exitCode() != 0) throw process.stderr.readAll().toString();
var dateString = process.stdout.readAll().toString();
dateString = dateString.replace("\n", "").replace("\r", "");
if (dateString == null || dateString.length < 8) return Date.now();
return Date.fromString(dateString);
#else
return Date.now();
#end
}

Increase code readability

In my opinion the code is a bit hard to read. I think it is a combination of the font and a somewhat small font size.

Here's a concrete example from the Cookbook where the text is big and clear but the code is lacking in clarity.

screen shot 2016-08-16 at 09 10 57


Here's an example where I've tried substituting the code font with another. I've used the Inconsolata font with a size of 15px.

screen shot 2016-08-16 at 09 44 07

In my opinion this makes for clearer code and aligns better with the text.

Add CodeCookBook.n to the repository?

I know there are different opinions on this, but I've had good experience having the .n file in the repository for Dox because it means people don't have to install the dependencies in order to run the thing. Any opinions?

Code example max width?

Do we want to set a max width for our code examples? It would be nice to have them properly formatted on an average landscape cellphone screen, but I'm not sure if we would have to make too many concessions for this.

Code Cookbook example custom generator needed and problems

Trying to understand how to use haxe.macro.Context.onGenerate(types:Array<Type>) to create custom generators I noticed that the types parameter comes with a strange order instead of the declaration order (line number) see the output bellow, this make it's usage a bit more involved than if it came ordered by file/line number, also probably in doing a working example several corner cases will surface and internal changes can be made to make life easy for Haxe users.

Would be nice to have an entry in the Code Cookbook with a simple functional example and I suggest the one bellow as starting point (generate Haxe again for simplicity), any comments/suggestions/improvements are welcome !

  • TestOnGenerate.hx:
final _version = "1.0";

/** Get version string. */

function getVersion(): String {
	return _version;
}

enum Color {
	Red;
	Green;
	Blue;
	RGB(r: Int, g: Int, b: Int);
}

class Test {
  static var _count: Int = 0;
  public var name:String;
  public var x:Float;
  public var y:Float;

  public function new(name:String, x:Float, y:Float) {
    this.name = name;
    this.x = x;
    this.y = y;
  }
  public function toString() : String {
	return name + "::" + Std.string(x) + "::" + Std.string(y);
  }
}

class TestOnGenerate {
    static function main() {
        var t = new Test("dad", 1.4, 2.9);
	trace(t.toString() + "::" + getVersion());
    }
}
  • MyOnGenerate.hx:
#if macro
import haxe.macro.Type;
import haxe.macro.Context;

using haxe.macro.PositionTools;

/**
 * Callback on generating code from context
 */
private function mygenerate(types:Array<Type>, filterFileName: String):Void {
	var buf = new StringBuf();
	for (atype in types) {
		// trace(atype);
		var aref = atype.getParameters()[0].get();
		var apos = Context.getPosInfos(aref.pos);
		//trace(apos);
		if(filterFileName != null && apos.file != filterFileName) continue;
		switch (atype) {
			case TMono(t):
				trace(t + "::" + aref.pos);
			case TEnum(t, params):
				var t_ref = t.get();
				//trace(t.toString() + "::" + aref.pos + "::" + params.toString());
				buf.add('\nenum ${t_ref.name} {\n');
				var enumFields = [];
				for (efield in t_ref.constructs) {
					//trace(efield);
					var ebuf = new StringBuf();
					ebuf.add('\t${efield.name}');
					switch(efield.type) {
						case TEnum(_, _): ebuf.add(";\n");
						case TFun(args, _):
							ebuf.add("(");
							for (i in 0...args.length) {
								var arg = args[i];
								if (i > 0)
									ebuf.add(", ");
								var type_name = switch(arg.t) {
									case TAbstract(t, params): t.get().name;
									default:
										throw 'Unsupported paramter ${arg.t}';
										null;
								};
								ebuf.add('${arg.name}: ${type_name}');
							}
							ebuf.add(");\n");

						default:
							throw 'Unsupported paramter ${efield.type}';
					}
					enumFields.insert(efield.index, ebuf.toString());
				}
				for(elm in enumFields) buf.add(elm);
				buf.add("}\n");
				//trace(buf.toString());
			case TInst(t, params):
				var t_ref = t.get();
				trace(aref.name + "::" + aref.pos /*.getInfos().min*/ + "::" + params.toString());
				var classFields = t_ref.fields.get();
				buf.add('\nclass ${t_ref.name} {\n');
				//trace(classFields);
				if(t_ref.constructor != null) trace(t_ref.constructor.get());
				for (ifield in classFields) {
					trace(ifield);
					buf.add('\t${ifield.name};\n');
				}
				trace(t_ref.statics.get());
				buf.add("}\n");
				//trace(buf.toString());
			case TType(t, params):
				trace(aref.name + "::" + aref.pos /*.getInfos().min*/ + "::" + params.toString());
			case TFun(args, ret):
				trace(args + "::" + aref.pos + "::" + ret);
			case TAnonymous(a):
				trace(a + "::" + aref.pos);
			case TDynamic(t):
				trace(t + "::" + aref.pos);
			case TLazy(f):
				trace(f + "::" + aref.pos);
			case TAbstract(t, params):
				trace(aref.name + "::" + aref.pos /*.getInfos().min*/ + "::" + params.toString());
		}
	}
	trace(buf.toString());
}

function set_on_generate(?ffname: String) {
	haxe.macro.Context.onGenerate(function(types:Array<Type>){mygenerate(types, ffname);});
}
#end
  • TestOnGenerate.hxml:
-main TestOnGenerate
--macro MyOnGenerate.set_on_generate("TestOnGenerate.hx")
#--macro MyOnGenerate.set_on_generate()
#-dce full
#-D analyzer_optimize

Output:

haxe "TestOnGenerate.hxml"
MyOnGenerate.hx:58: Test::#pos(TestOnGenerate.hx:16: lines 16-30)::[]
MyOnGenerate.hx:62: {name: new, isFinal: false, namePos: #pos(TestOnGenerate.hx:22: characters 19-22), isPublic: true, isAbstract: false, doc: null, params: [], pos: #pos(TestOnGenerate.hx:22: lines 22-26), kind: FMethod(MethNormal), meta: {get: #fun, remove: #fun, has: #fun, extract: #fun, add: #fun}, overloads: overloads, isExtern: false, type: TFun([{name: name, t: TInst(<...>,[]), opt: false},{name: x, t: TAbstract(<...>,[]), opt: false},{name: y, t: TAbstract(<...>,[]), opt: false}],TAbstract(Void,[])), expr: #fun}
MyOnGenerate.hx:64: {name: name, isFinal: false, namePos: #pos(TestOnGenerate.hx:18: characters 14-18), isPublic: true, isAbstract: false, doc: null, params: [], pos: #pos(TestOnGenerate.hx:18: characters 3-26), kind: FVar(AccNormal,AccNormal), meta: {get: #fun, remove: #fun, has: #fun, extract: #fun, add: #fun}, overloads: overloads, isExtern: false, type: TInst(String,[]), expr: #fun}
MyOnGenerate.hx:64: {name: x, isFinal: false, namePos: #pos(TestOnGenerate.hx:19: characters 14-15), isPublic: true, isAbstract: false, doc: null, params: [], pos: #pos(TestOnGenerate.hx:19: characters 3-22), kind: FVar(AccNormal,AccNormal), meta: {get: #fun, remove: #fun, has: #fun, extract: #fun, add: #fun}, overloads: overloads, isExtern: false, type: TAbstract(Float,[]), expr: #fun}
MyOnGenerate.hx:64: {name: y, isFinal: false, namePos: #pos(TestOnGenerate.hx:20: characters 14-15), isPublic: true, isAbstract: false, doc: null, params: [], pos: #pos(TestOnGenerate.hx:20: characters 3-22), kind: FVar(AccNormal,AccNormal), meta: {get: #fun, remove: #fun, has: #fun, extract: #fun, add: #fun}, overloads: overloads, isExtern: false, type: TAbstract(Float,[]), expr: #fun}
MyOnGenerate.hx:64: {name: toString, isFinal: false, namePos: #pos(TestOnGenerate.hx:27: characters 19-27), isPublic: true, isAbstract: false, doc: null, params: [], pos: #pos(TestOnGenerate.hx:27: lines 27-29), kind: FMethod(MethNormal), meta: {get: #fun, remove: #fun, has: #fun, extract: #fun, add: #fun}, overloads: overloads, isExtern: false, type: TFun([],TInst(String,[])), expr: #fun}
MyOnGenerate.hx:67: [{name: _count, isFinal: false, namePos: #pos(TestOnGenerate.hx:17: characters 14-20), isPublic: false, isAbstract: false, doc: null, params: [], pos: #pos(TestOnGenerate.hx:17: characters 3-30), kind: FVar(AccNormal,AccNormal), meta: {get: #fun, remove: #fun, has: #fun, extract: #fun, add: #fun}, overloads: overloads, isExtern: false, type: TAbstract(Int,[]), expr: #fun}]
MyOnGenerate.hx:58: TestOnGenerate::#pos(TestOnGenerate.hx:32: lines 32-37)::[]
MyOnGenerate.hx:67: [{name: main, isFinal: false, namePos: #pos(TestOnGenerate.hx:33: characters 21-25), isPublic: false, isAbstract: false, doc: null, params: [], pos: #pos(TestOnGenerate.hx:33: lines 33-36), kind: FMethod(MethNormal), meta: {get: #fun, remove: #fun, has: #fun, extract: #fun, add: #fun}, overloads: overloads, isExtern: false, type: TFun([],TAbstract(Void,[])), expr: #fun}]
MyOnGenerate.hx:58: TestOnGenerate_Fields_::#pos(TestOnGenerate.hx:1: character 1)::[]
MyOnGenerate.hx:67: [{name: _version, isFinal: true, namePos: #pos(TestOnGenerate.hx:1: characters 7-15), isPublic: true, isAbstract: false, doc: null, params: [], pos: #pos(TestOnGenerate.hx:1: characters 1-24), kind: FVar(AccNormal,AccNever), meta: {get: #fun, remove: #fun, has: #fun, extract: #fun, add: #fun}, overloads: overloads, isExtern: false, type: TInst(String,[]), expr: #fun},{name: getVersion, isFinal: false, namePos: #pos(TestOnGenerate.hx:5: characters 10-20), isPublic: true, isAbstract: false, doc:  Get version string. , params: [], pos: #pos(TestOnGenerate.hx:5: lines 5-7), kind: FMethod(MethNormal), meta: {get: #fun, remove: #fun, has: #fun, extract: #fun, add: #fun}, overloads: overloads, isExtern: false, type: TFun([],TInst(String,[])), expr: #fun}]
MyOnGenerate.hx:84: 
enum Color {
	Red;
	Green;
	Blue;
	RGB(r: Int, g: Int, b: Int);
}

class Test {
	name;
	x;
	y;
	toString;
}

class TestOnGenerate {
}

class TestOnGenerate_Fields_ {
}

Library/Toolkit Connect and Commuity Log

Hi would like to propose one or two additional sections.
"Library/Toolkit Connect"
This will eventually include forums on specific haxe targets if they are formed such as Java, NodeJS, c# etc..., but currently should include "active" groups, a good starter might be these.

Luxe
https://gitter.im/snowkit/public ( there is also a Luxe one but I think this is used more )
Kha
irc://ktxsoftware.com/kha
Openfl
http://community.openfl.org/
Flambe
https://groups.google.com/forum/#!forum/flambe
NME
https://gitter.im/haxenme/nme
Fixel
http://haxeflixel.com/documentation/community/

... probably some more but I am sure libraries / toolkits can suggest for themselves you just need a starting list, I can imagine Heaps, Nape etc.. should be added if they have ones, the important aspect maybe activity, I think it might be very hard to order these by activity but perhaps that would be ideal, certainly it would help new users know which projects to explore, and would be very relatively fair on projects.

Also it would be ideal to work towards a "Community Log"
Ideally it would be amazing to have a collated log of new posts/topics in some form from the Haxe and library forums, but I don't have any code for this it's just an additional suggestion to the Library Connect proposal, and not one I would be able to implement.

Certainly I can look at creating a pull request for "Library/Toolkit Connect" if such a concept seems interesting to reduce the workload on Mark, but maybe you disagree with my logic which I was originally going to put in a haxelang email but decided to post here.

"It would be really nice to maybe go a bit further with the "Connect" section to cover more specific ecosystems where users share promote and discuss Haxe related projects, it's often more worthwhile hanging out on some of these if you want to discuss more specific topics."

Certainly something along these lines might be useful to clarify the section.

All looks good best Justin. :)

Auto deploy to Github Pages

It would be awesome if we can auto deploy this website on Github Pages. Nicolas was ok with this, he will link code.haxe.org to it.

@andyli can you help with this? What do we need?

Improve Google discoverability

For some reason, code.haxe.org doesn't seem to rank very highly on google.. googling for static extensions haxe, I get the Haxe Manual's article as the first result:

https://haxe.org/manual/lf-static-extension.html

The code cookbook snippet for static extensions doesn't show up anywhere though (at least not in the first five pages):

http://code.haxe.org/category/beginner/using-static-extensions.html

This is a bit of a shame, especially because a lot of people seem to struggle with the manual's technical wording - the cookbook has more of a tutorial-style that is beginner-friendly.

Linking to code cookbook snippets from the Haxe Manual might help. Perhaps some things could also be linked to from the API docs? Not static extensions of course, there's no API for that, but maybe macros.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.