Skip to content

Instantly share code, notes, and snippets.

View GitSquared's full-sized avatar
👨‍🎤

Gabriel Saillard GitSquared

👨‍🎤
View GitHub Profile
@GitSquared
GitSquared / configFileReader.js
Last active March 1, 2018 17:33
Node.js module to load a configuration file.
/*
Configuration file reader module. Takes an absolute file path and the boolean watch as arguments.
* filePath is expected to be the path to a JSON file (with the .json extension).
* watch is optional and defaults to false. If set to true, the config file will be watched by fs and any changes made to it will be automatically reflected on the module instance.
Returns an object:
* filePath: The file currently in use.
* watching: Boolean, indicate if the config file is being monitored for changes.
* config: Object containg the parsed data of the config file.
* parseFile(path, watch): Parse a config file. If you specify a new file, set watch to true to start watching it for changes, too. As always, watch defaults to false.
@GitSquared
GitSquared / colorify.js
Created September 30, 2017 23:28
Colorify a whole CSS theme using color.js
const Color = require('color');
const colorifyTarget = Color("#bee6c1");
let original = require('fs').readFileSync("original.css", {encoding: "utf-8"});
console.log(original);
let colorified = original.replace(/(#{1}[0-g]{6})+/ig, (match) => {
console.log(match);
return Color(match).grayscale().mix(colorifyTarget, 0.3).hex(); // Edit colorify options here
});
console.log(colorified);
@GitSquared
GitSquared / form-keyboard-submit-jquery.js
Last active July 20, 2017 14:41
Automatically run the onsubmit="" function of forms when the enter key is pressed on the last input field.
$(() => {
let update_form_listeners = () => {
// Always check that the onsubmit attribute ends by return false; otherwise the page will reload
$("form[onsubmit] input:last-of-type").each((index, element) => {
if ($(element).parents('form').attr('onsubmit').substr(-13) !== 'return false;') {
$(element).parents('form').attr('onsubmit', $(element).parents('form').attr('onsubmit')+'return false;');
}
});
$("form[onsubmit] input:last-of-type").keypress((e) => {
@GitSquared
GitSquared / index.html
Created February 26, 2017 18:12
Render de dégats pour jeux HTML5
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Déganimation</title>
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script>
window.cursorPos = {x: 0, y: 0};