Skip to content

Instantly share code, notes, and snippets.

View pablomayobre's full-sized avatar
📖
Learning new technologies

Pablo Ariel Mayobre pablomayobre

📖
Learning new technologies
  • NewCombin
  • Trelew, Chubut, Argentina
View GitHub Profile
@drhayes
drhayes / camera.lua
Created March 9, 2018 15:37
LÖVE camera shake
self.noiseFactor = self.noiseFactor + dt
-- self.trauma = math.min(1, self.trauma) - dt * config.camera.traumaFactor
self.trauma = math.max(0, self.trauma - dt * config.camera.traumaFactor)
if self.cameraTarget then
self.x = self.x + (self.cameraTarget.pos.x - self.x) * dt * self.slideFactor
self.y = self.y + (self.cameraTarget.pos.y - self.y) * dt * self.slideFactor
end
-- Shake based on trauma
local shake = self.trauma ^ 2
local maxOffset, maxAngle = config.camera.shake.maxOffset, config.camera.shake.maxAngle
@Luca-spopo
Luca-spopo / vararg_utils.lua
Last active November 14, 2017 21:52
Mapping and filtering varargs in Lua without intermediate tables
local function va_map_rec(count, transform, a, ...)
if count>0 then
return transform(a), va_map_rec(count-1, transform, ...)
else
return (transform(a))
end
end
local function va_map(transform, ...)
local n = select("#", ...)
@pablomayobre
pablomayobre / batch.lua
Last active December 22, 2018 01:11
Perform many removal, inserting operations on a table, fast!
local batch = {}
local holes_err = "bad argument #%s to function '%s' (this list doesn't support holes)"
local refill = function (t, ...)
local newn = select('#', ...)
local length = math.max(newn, (t.n or #t))
for i = 1, length do
t[i] = select(i, ...)

As you start out with your Electron app, you'll start to notice some features which have been carried directly across from the browser realm but make less sense for a desktop app. Here are the ones I can remember:

Ctrl or + Click Opens Links in New Window

In Electron just like in Chrome, if you hold down the Ctrl key (or on Mac) while clicking a link it opens in a new window. For many SPA apps, this is undesired and will load another full copy of your app in another window. You can disable this by calling the following code once you've created a BrowserWindow

win = new BrowserWindow({ ... });
@josefnpat
josefnpat / Makefile
Last active February 5, 2025 05:46
Love Makefile of Doom
# Copyright 2017 Josef N Patoprsty
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
@TannerRogalsky
TannerRogalsky / main.lua
Created January 23, 2017 13:55
Fast vertex setting in Love using ImageData and the FFI
local num_verts = 100000
local vertices = {}
for i=1,num_verts do
vertices[i] = {0, 0, 0, 0, 255, 255, 255, 255}
end
local ffi = require('ffi')
ffi.cdef[[
typedef struct {
float x, y;
local function check (self)
if not self.isDirty then
return self
end
self.length = 0
local item = self.firstItem
while item do
self.length = self.length + 1
self.items[self.length] = item
item = self.itemAfter[item]
@kikito
kikito / gui.txt
Last active June 8, 2016 04:51
rummagings about gui design
An UI has several parts:
1. The "Layout": Defines the space each control takes. "This button is 32x32 px and is located in 100,100"
2. The "Function": what happens when a control is used. "This needs to happen when this button is pressed"
3. The "Skin": how each control is displayed. "This button, with this state, is a red circle"
4. Bells and whistles: Things like state animations, or playing a sound when a button is hovered.
5. Current focus.
6. A way to handle input: Move focus to next item. "There is a pointer pressing on this position".
Problems:
@novemberborn
novemberborn / howto.md
Created February 18, 2016 17:47
Creating a PKCS#12 file from a Let's Encrypt certificate
@inmatarian
inmatarian / funky.lua
Last active June 13, 2016 23:38
latest version of funky.lua
-- Funky.lua, collection of functional tools
local _ENV = setmetatable({}, {__index = _ENV or _G})
if setfenv then setfenv(1, _ENV) end
unpack = unpack or table.unpack
local __ = {}
do
-- We need a fast way to check for placeholders. All funkier libraries
-- will need to register themselves as a funky placeholder.