1600612080
lume is the galician word for fire, but also a (yet another) static site generator for Deno.
Itâs inspired in other general purpose static site generators such Jekyll or Eleventy but itâs faster, simpler and easier to use and configure, besides being super flexible.
markdown
, yaml
, javascript
, typescript
, jsx
, nunjucks
and itâs easy to extend.sass
or postcss
for CSS.node_modules
or complex bundlers. Lume only install that you need. Clean, fast and secure.Make sure you have Deno installed.
Install lume as a Deno executable:
deno install --unstable --allow-read --allow-write --allow-net https://deno.land/x/lume/cli.js
Create your first page, for example using a nunjucks template:
---
title: Welcome to my page
---
<html>
<head>
<title>{{ title }}</title>
</head>
<body>
<h1>{{ title }}</h1>
</body>
</html>
Run it: lume
This command will compile your documents to HTML and saved into the output folder (defaults to _site
)
You can run lume --serve
to start up a webserver. Then open http://localhost:3000
in your web browser to see your website.
Author: oscarotero
Demo: https://deno.land/x/lume
Source Code: https://github.com/oscarotero/lume
#deno #nodejs #node #javascript
1605177550
#hugo #static #site #generator #markup #static site generator
1604008800
Static code analysis refers to the technique of approximating the runtime behavior of a program. In other words, it is the process of predicting the output of a program without actually executing it.
Lately, however, the term âStatic Code Analysisâ is more commonly used to refer to one of the applications of this technique rather than the technique itself â program comprehension â understanding the program and detecting issues in it (anything from syntax errors to type mismatches, performance hogs likely bugs, security loopholes, etc.). This is the usage weâd be referring to throughout this post.
âThe refinement of techniques for the prompt discovery of error serves as well as any other as a hallmark of what we mean by science.â
We cover a lot of ground in this post. The aim is to build an understanding of static code analysis and to equip you with the basic theory, and the right tools so that you can write analyzers on your own.
We start our journey with laying down the essential parts of the pipeline which a compiler follows to understand what a piece of code does. We learn where to tap points in this pipeline to plug in our analyzers and extract meaningful information. In the latter half, we get our feet wet, and write four such static analyzers, completely from scratch, in Python.
Note that although the ideas here are discussed in light of Python, static code analyzers across all programming languages are carved out along similar lines. We chose Python because of the availability of an easy to use ast
module, and wide adoption of the language itself.
Before a computer can finally âunderstandâ and execute a piece of code, it goes through a series of complicated transformations:
As you can see in the diagram (go ahead, zoom it!), the static analyzers feed on the output of these stages. To be able to better understand the static analysis techniques, letâs look at each of these steps in some more detail:
The first thing that a compiler does when trying to understand a piece of code is to break it down into smaller chunks, also known as tokens. Tokens are akin to what words are in a language.
A token might consist of either a single character, like (
, or literals (like integers, strings, e.g., 7
, Bob
, etc.), or reserved keywords of that language (e.g, def
in Python). Characters which do not contribute towards the semantics of a program, like trailing whitespace, comments, etc. are often discarded by the scanner.
Python provides the tokenize
module in its standard library to let you play around with tokens:
Python
1
import io
2
import tokenize
3
4
code = b"color = input('Enter your favourite color: ')"
5
6
for token in tokenize.tokenize(io.BytesIO(code).readline):
7
print(token)
Python
1
TokenInfo(type=62 (ENCODING), string='utf-8')
2
TokenInfo(type=1 (NAME), string='color')
3
TokenInfo(type=54 (OP), string='=')
4
TokenInfo(type=1 (NAME), string='input')
5
TokenInfo(type=54 (OP), string='(')
6
TokenInfo(type=3 (STRING), string="'Enter your favourite color: '")
7
TokenInfo(type=54 (OP), string=')')
8
TokenInfo(type=4 (NEWLINE), string='')
9
TokenInfo(type=0 (ENDMARKER), string='')
(Note that for the sake of readability, Iâve omitted a few columns from the result above â metadata like starting index, ending index, a copy of the line on which a token occurs, etc.)
#code quality #code review #static analysis #static code analysis #code analysis #static analysis tools #code review tips #static code analyzer #static code analysis tool #static analyzer
1591340335
APA Referencing Generator
Many students use APA style as the key citation style in their assignment in university or college. Although, many people find it quite difficult to write the reference of the source. You ought to miss the names and dates of authors. Hence, APA referencing generator is important for reducing the burden of students. They can now feel quite easy to do the assignments on time.
The functioning of APA referencing generator
If you are struggling hard to write the APA referencing then you can take the help of APA referencing generator. It will create an excellent list. You are required to enter the information about the source. Just ensure that the text is credible and original. If you will copy references then it is a copyright violation.
You can use a referencing generator in just a click. It will generate the right references for all the sources. You are required to organize in alphabetical order. The generator will make sure that you will get good grades.
How to use APA referencing generator?
Select what is required to be cited such as journal, book, film, and others. You can choose the type of required citations list and enter all the required fields. The fields are dates, author name, title, editor name, and editions, name of publishers, chapter number, page numbers, and title of journals. You can click for reference to be generated and you will get the desired result.
Chicago Referencing Generator
Do you require the citation style? You can rely on Chicago Referencing Generator and will ensure that you will get the right citation in just a click. The generator is created to provide solutions to students to cite their research paper in Chicago style. It has proved to be the quickest and best citation generator on the market. The generator helps to sort the homework issues in few seconds. It also saves a lot of time and energy.
This tool helps researchers, professional writers, and students to manage and generate text citation essays. It will help to write Chicago style in a fast and easy way. It also provides details and directions for formatting and cites resources.
So, you must stop wasting the time and can go for Chicago Referencing Generator or APA referencing generator. These citation generators will help to solve the problem of citation issues. You can easily create citations by using endnotes and footnotes.
So, you can generate bibliographies, references, in-text citations, and title pages. These are fully automatic referencing style. You are just required to enter certain details about the citation and you will get the citation in the proper and required format.
So, if you are feeling any problem in doing assignment then you can take the help of assignment help.
If you require help for Assignment then livewebtutors is the right place for you. If you see our prices, you will observe that they are actually very affordable. Also, you can always expect a discount. Our team is capable and versatile enough to offer you exactly what you need, the best services for the prices you can afford.
read more:- Are you struggling to write a bibliography? Use Harvard referencing generator
#apa referencing generator #harvard referencing generator #chicago referencing generator #mla referencing generator #deakin referencing generator #oxford referencing generator
1599527554
Websites can be of 2 types: static and dynamic. For static types, when user requests a file, server sends the file and user can see it. Every page is hand coded in html. In a dynamic type, When user requests, content is generated and server builds the page then sends it to the user. Generally managed by CMS like Wordpress or Joomla.
Static site generator (SSG) bridges the gap between static HTML sites and CMS based sites (like Wordpress). It provides better performance of static sites and we do not have to write HTML for content of our site.
Think of a static site generator as a script which takes in data, content and templates, processes them, and outputs a folder full of all the resultant pages and assets.
-Phil Hawksworth
In short, SSGs bring good of both worlds together.
1. Security
Static websites do not have a database and all our server does is returns the file asked by user.
Our server becomes dumb (doesnât use logic to construct page) so no security issue to exploit.
2. Performance
Static websites perform better and load faster because the page isnât constructed at run time.
3. Version Control
Our website can live in a version controlled environment, meaning if you make a mistake you can go back to a previous version in one command.
4. Scaling
When the number of users on a dynamic website increase it would mean to efficiently scale the website to ensure every userâs page is served as quickly as possible while for static sites thats not a issue because our work is pre-done. Our website pages are already made and we just have to provide them.
#webdevelopment #programming #static-site-generator #web-development #static-website #html #ssg #website
1658977500
Calyx provides a simple API for generating text with declarative recursive grammars.
gem install calyx
gem 'calyx'
The best way to get started quickly is to install the gem and run the examples locally.
Requires Roda and Rack to be available.
gem install roda
Demonstrates how to use Calyx to construct SVG graphics. Any Gradient generates a rectangle with a linear gradient of random colours.
Run as a web server and preview the output in a browser (http://localhost:9292
):
ruby examples/any_gradient.rb
Or generate SVG files via a command line pipe:
ruby examples/any_gradient > gradient1.xml
Requires the Twitter client gem and API access configured for a specific Twitter handle.
gem install twitter
Demonstrates how to use Calyx to make a minimal Twitter bot that periodically posts unique tweets. See @tiny_woodland on Twitter and the writeup here.
TWITTER_CONSUMER_KEY=XXX-XXX
TWITTER_CONSUMER_SECRET=XXX-XXX
TWITTER_ACCESS_TOKEN=XXX-XXX
TWITTER_CONSUMER_SECRET=XXX-XXX
ruby examples/tiny_woodland_bot.rb
Faker is a popular library for generating fake names and associated sample data like internet addresses, company names and locations.
This example demonstrates how to use Calyx to reproduce the same functionality using custom lists defined in a YAML configuration file.
ruby examples/faker.rb
Require the library and inherit from Calyx::Grammar
to construct a set of rules to generate a text.
require 'calyx'
class HelloWorld < Calyx::Grammar
start 'Hello world.'
end
To generate the text itself, initialize the object and call the generate
method.
hello = HelloWorld.new
hello.generate
# > "Hello world."
Obviously, this hardcoded sentence isnât very interesting by itself. Possible variations can be added to the text by adding additional rules which provide a named set of text strings. The rule delimiter syntax ({}
) can be used to substitute the generated content of other rules.
class HelloWorld < Calyx::Grammar
start '{greeting} world.'
greeting 'Hello', 'Hi', 'Hey', 'Yo'
end
Each time #generate
runs, it evaluates the tree and randomly selects variations of rules to construct a resulting string.
hello = HelloWorld.new
hello.generate
# > "Hi world."
hello.generate
# > "Hello world."
hello.generate
# > "Yo world."
By convention, the start
rule specifies the default starting point for generating the final text. You can start from any other named rule by passing it explicitly to the generate method.
class HelloWorld < Calyx::Grammar
hello 'Hello world.'
end
hello = HelloWorld.new
hello.generate(:hello)
As an alternative to subclassing, you can also construct rules unique to an instance by passing a block when initializing the class:
hello = Calyx::Grammar.new do
start '{greeting} world.'
greeting 'Hello', 'Hi', 'Hey', 'Yo'
end
hello.generate
Basic rule substitution uses single curly brackets as delimiters for template expressions:
fruit = Calyx::Grammar.new do
start '{colour} {fruit}'
colour 'red', 'green', 'yellow'
fruit 'apple', 'pear', 'tomato'
end
6.times { fruit.generate }
# => "yellow pear"
# => "red apple"
# => "green tomato"
# => "red pear"
# => "yellow tomato"
# => "green apple"
Rules are recursive. They can be arbitrarily nested and connected to generate larger and more complex texts.
class HelloWorld < Calyx::Grammar
start '{greeting} {world_phrase}.'
greeting 'Hello', 'Hi', 'Hey', 'Yo'
world_phrase '{happy_adj} world', '{sad_adj} world', 'world'
happy_adj 'wonderful', 'amazing', 'bright', 'beautiful'
sad_adj 'cruel', 'miserable'
end
Nesting and hierarchy can be manipulated to balance consistency with novelty. The exact same word atoms can be combined in a variety of ways to produce strikingly different resulting texts.
module HelloWorld
class Sentiment < Calyx::Grammar
start '{happy_phrase}', '{sad_phrase}'
happy_phrase '{happy_greeting} {happy_adj} world.'
happy_greeting 'Hello', 'Hi', 'Hey', 'Yo'
happy_adj 'wonderful', 'amazing', 'bright', 'beautiful'
sad_phrase '{sad_greeting} {sad_adj} world.'
sad_greeting 'Goodbye', 'So long', 'Farewell'
sad_adj 'cruel', 'miserable'
end
class Mixed < Calyx::Grammar
start '{greeting} {adj} world.'
greeting 'Hello', 'Hi', 'Hey', 'Yo', 'Goodbye', 'So long', 'Farewell'
adj 'wonderful', 'amazing', 'bright', 'beautiful', 'cruel', 'miserable'
end
end
By default, the outcomes of generated rules are selected with Rubyâs built-in pseudorandom number generator (as seen in methods like Kernel.rand
and Array.sample
). To seed the random number generator, pass in an integer seed value as the first argument to the constructor:
grammar = Calyx::Grammar.new(seed: 12345) do
# rules...
end
Alternatively, you can pass a preconfigured instance of Rubyâs stdlib Random
class:
random = Random.new(12345)
grammar = Calyx::Grammar.new(rng: random) do
# rules...
end
When a random seed isnât supplied, Time.new.to_i
is used as the default seed, which makes each run of the generator relatively unique.
Choices can be weighted so that some rules have a greater probability of expanding than others.
Weights are defined by passing a hash instead of a list of rules where the keys are strings or symbols representing the grammar rules and the values are weights.
Weights can be represented as floats, integers or ranges.
The following definitions produce an equivalent weighting of choices:
Calyx::Grammar.new do
start 'heads' => 1, 'tails' => 1
end
Calyx::Grammar.new do
start 'heads' => 0.5, 'tails' => 0.5
end
Calyx::Grammar.new do
start 'heads' => 1..5, 'tails' => 6..10
end
Calyx::Grammar.new do
start 'heads' => 50, 'tails' => 50
end
Thereâs a lot of interesting things you can do with this. For example, you can model the triangular distribution produced by rolling 2d6:
Calyx::Grammar.new do
start(
'2' => 1,
'3' => 2,
'4' => 3,
'5' => 4,
'6' => 5,
'7' => 6,
'8' => 5,
'9' => 4,
'10' => 3,
'11' => 2,
'12' => 1
)
end
Or reproduce Gary Gygaxâs famous generation table from the original Dungeon Masterâs Guide (page 171):
Calyx::Grammar.new do
start(
:empty => 0.6,
:monster => 0.1,
:monster_treasure => 0.15,
:special => 0.05,
:trick_trap => 0.05,
:treasure => 0.05
)
empty 'Empty'
monster 'Monster Only'
monster_treasure 'Monster and Treasure'
special 'Special'
trick_trap 'Trick/Trap.'
treasure 'Treasure'
end
Dot-notation is supported in template expressions, allowing you to call any available method on the String
object returned from a rule. Formatting methods can be chained arbitrarily and will execute in the same way as they would in native Ruby code.
greeting = Calyx::Grammar.new do
start '{hello.capitalize} there.', 'Why, {hello} there.'
hello 'hello', 'hi'
end
4.times { greeting.generate }
# => "Hello there."
# => "Hi there."
# => "Why, hello there."
# => "Why, hi there."
You can also extend the grammar with custom modifiers that provide useful formatting functions.
Filters accept an input string and return the transformed output:
greeting = Calyx::Grammar.new do
filter :shoutycaps do |input|
input.upcase
end
start '{hello.shoutycaps} there.', 'Why, {hello.shoutycaps} there.'
hello 'hello', 'hi'
end
4.times { greeting.generate }
# => "HELLO there."
# => "HI there."
# => "Why, HELLO there."
# => "Why, HI there."
The mapping shortcut allows you to specify a map of regex patterns pointing to their resulting substitution strings:
green_bottle = Calyx::Grammar.new do
mapping :pluralize, /(.+)/ => '\\1s'
start 'One green {bottle}.', 'Two green {bottle.pluralize}.'
bottle 'bottle'
end
2.times { green_bottle.generate }
# => "One green bottle."
# => "Two green bottles."
In order to use more intricate rewriting and formatting methods in a modifier chain, you can add methods to a module and embed it in a grammar using the modifier
classmethod.
Modifier methods accept a single argument representing the input string from the previous step in the expression chain and must return a string, representing the modified output.
module FullStop
def full_stop(input)
input << '.'
end
end
hello = Calyx::Grammar.new do
modifier FullStop
start '{hello.capitalize.full_stop}'
hello 'hello'
end
hello.generate
# => "Hello."
To share custom modifiers across multiple grammars, you can include the module in Calyx::Modifiers
. This will make the methods available to all subsequent instances:
module FullStop
def full_stop(input)
input << '.'
end
end
class Calyx::Modifiers
include FullStop
end
Alternatively, you can combine methods from existing Gems that monkeypatch String
:
require 'indefinite_article'
module FullStop
def full_stop
self << '.'
end
end
class String
include FullStop
end
noun_articles = Calyx::Grammar.new do
start '{fruit.with_indefinite_article.capitalize.full_stop}'
fruit 'apple', 'orange', 'banana', 'pear'
end
4.times { noun_articles.generate }
# => "An apple."
# => "An orange."
# => "A banana."
# => "A pear."
Rule expansions can be âmemoizedâ so that multiple references to the same rule return the same value. This is useful for picking a noun from a list and reusing it in multiple places within a text.
The @
sigil is used to mark memoized rules. This evaluates the rule and stores it in memory the first time itâs referenced. All subsequent references to the memoized rule use the same stored value.
# Without memoization
grammar = Calyx::Grammar.new do
start '{name} <{name.downcase}>'
name 'Daenerys', 'Tyrion', 'Jon'
end
3.times { grammar.generate }
# => Daenerys <jon>
# => Tyrion <daenerys>
# => Jon <tyrion>
# With memoization
grammar = Calyx::Grammar.new do
start '{@name} <{@name.downcase}>'
name 'Daenerys', 'Tyrion', 'Jon'
end
3.times { grammar.generate }
# => Tyrion <tyrion>
# => Daenerys <daenerys>
# => Jon <jon>
Note that the memoization symbol can only be used on the right hand side of a production rule.
Rule expansions can be marked as âuniqueâ, meaning that multiple references to the same rule always return a different value. This is useful for situations where the same result appearing twice would appear awkward and messy.
Unique rules are marked by the $
sigil.
grammar = Calyx::Grammar.new do
start "{$medal}, {$medal}, {$medal}"
medal 'Gold', 'Silver', 'Bronze'
end
grammar.generate
# => Silver, Bronze, Gold
Template expansions can be dynamically constructed at runtime by passing a context map of rules to the #generate
method:
class AppGreeting < Calyx::Grammar
start 'Hi {username}!', 'Welcome back {username}...', 'Hola {username}'
end
context = {
username: UserModel.username
}
greeting = AppGreeting.new
greeting.generate(context)
In addition to defining grammars in pure Ruby, you can load them from external JSON and YAML files:
hello = Calyx::Grammar.load('hello.yml')
hello.generate
The format requires a flat map with keys representing the left-hand side named symbols and the values representing the right hand side substitution rules.
In JSON:
{
"start": "{greeting} world.",
"greeting": ["Hello", "Hi", "Hey", "Yo"]
}
In YAML:
---
start: "{greeting} world."
greeting:
- Hello
- Hi
- Hey
- Yo
Calling #evaluate
on the grammar instance will give you access to the raw generated tree structure before it gets flattened into a string.
The tree is encoded as an array of nested arrays, with the leading symbols labeling the choices and rules selected, and the trailing terminal leaves encoding string values.
This may not make a lot of sense unless youâre familiar with the concept of s-expressions. Itâs a fairly speculative feature at this stage, but it leads to some interesting possibilities.
grammar = Calyx::Grammar.new do
start 'Riddle me ree.'
end
grammar.evaluate
# => [:start, [:choice, [:concat, [[:atom, "Riddle me ree."]]]]]
Rough plan for stabilising the API and features for a 1.0
release.
Version | Features planned |
---|---|
0.6 | |
0.7 | |
0.8 | |
0.9 |
|
0.10 | |
0.11 | |
0.12 | |
0.13 | |
0.14 | |
0.15 | |
0.16 | |
0.17 |
|
Author: Maetl
Source Code: https://github.com/maetl/calyx
License: MIT license