This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const std = @import("std"); | |
const assert = std.debug.assert; | |
const mem = std.mem; | |
const Allocator = std.mem.Allocator; | |
const Buffer = std.Buffer; | |
pub fn wrap(allocator: *Allocator, string: []const u8, width: usize) ![]u8 { | |
assert(width > 3); | |
var justified = try Buffer.initSize(allocator, string.len); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<div class="hello">{{ world | capitalize }}</div> | |
</template | |
<script lang="lua"> | |
local helpers = require "@/js-helpers.lua" | |
local Object = helpers.Object | |
local Array = helpers.Array | |
return Object { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local new = js.new | |
local helpers = require "./js-helpers.lua" | |
local Object = helpers.Object | |
local Array = helpers.Array | |
local BASE_URL = helpers.webpack.process.env.BASE_URL | |
local isDev = helpers.webpack.process.env.NODE_ENV == "development" | |
local Vue = require "vue".default | |
local Router = require "vue-router".default | |
local Home = require "./views/Home.vue".default |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const path = require("path"); | |
module.exports = { | |
configureWebpack: { | |
module: { | |
rules: [ | |
{ | |
test: /\.lua$/, | |
oneOf: [ | |
// this applies to <template lang="lua"> in Vue components |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- luacheck: ignore | |
local HelloWorld = Component { | |
-- Everything is wrote in Lua so rendered html | |
-- is always valid. | |
-- Chain of functions could build up a string | |
-- or a vdom | |
template = function(self) | |
return |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
os.execute("/usr/bin/env stty raw -echo 2> /dev/null") | |
local term = require "term" | |
local function loop() | |
local char | |
repeat | |
term.cursor.save() | |
char = io.stdin:read(1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <SDL2/SDL.h> | |
#include <cairo/cairo.h> | |
#include <math.h> | |
void draw(cairo_t *cr) { | |
cairo_text_extents_t extents; | |
const char *utf8 = "cairo"; | |
// Hello world cairo | |
double x, y; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Fetch n url in parallel, must be run in a coroutine (co parameter) | |
local fetch = function(co, ...) | |
local requests = {...} | |
for i = 1, #requests do | |
local promise = js.global:fetch(requests[i]) | |
promise["then"](promise, function(_, res) | |
local textPromise = res:text() | |
textPromise["then"](textPromise, function(_, text) | |
co(i, text) | |
end) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local co | |
local fetch = function(url) | |
local promise = js.global:fetch(url) | |
promise["then"](promise, function(_, res) | |
local jsonPromise = res:json() | |
jsonPromise["then"](jsonPromise, function(_, json) | |
co(json) | |
end) | |
end) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if let _ = optional { | |
} |