Skip to content

Instantly share code, notes, and snippets.

View giann's full-sized avatar
🧑‍🚀
Working on Buzz

Benoit Giannangeli giann

🧑‍🚀
Working on Buzz
View GitHub Profile
@giann
giann / warp.zig
Last active March 20, 2021 03:34
Wrap text to fit into given width
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);
@giann
giann / Example.vue
Created May 29, 2019 06:23
Vue SFC with Fengari
<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 {
@giann
giann / router.lua
Created May 29, 2019 06:17
Vuex router with Fengari
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
@giann
giann / vue.config.js
Created May 29, 2019 06:16
vue.config.js to use Fengari with Vue
const path = require("path");
module.exports = {
configureWebpack: {
module: {
rules: [
{
test: /\.lua$/,
oneOf: [
// this applies to <template lang="lua"> in Vue components
@giann
giann / lframework.lua
Last active April 24, 2019 08:52
Lua web framework idea
-- 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
@giann
giann / echochars.lua
Created February 13, 2019 09:03
Echo keyboard input (useful to print out escape codes)
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)
#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;

Keybase proof

I hereby claim:

  • I am giann on github.
  • I am giann (https://keybase.io/giann) on keybase.
  • I have a public key ASDCyQPp-y67NC7iEpvqP98x5vj8iQat495Pznvu3cK6jgo

To claim this, I am signing this object:

-- 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)
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)