Skip to content

Instantly share code, notes, and snippets.

View WebReflection's full-sized avatar
🎯
Focusing

Andrea Giammarchi WebReflection

🎯
Focusing
View GitHub Profile
@WebReflection
WebReflection / multiple-uploads.md
Last active June 30, 2021 14:12
Uploading multiple files at once, and without jQuery

The aim of this gist is to fix the following informative post about uploading via XHR.

Fixing the HTML

The first part is the HTML. First of all, you really don't need JavaScript to upload a file but you do need a proper form. Secondly, inputs in a form shouild have a name, because the name is what the server will receive: not IDs, names!

Following the fixed form part.

@WebReflection
WebReflection / state.js
Created May 13, 2016 10:16
Prototypal inheritance used to define states.
/*! (c) 2016 Andrea Giammarchi - MIT Style License */
// simple state-like objects handler
// based on prototypal inheritance
function State() {'use strict';}
// States are serializable dictionaries
// toJSON and toString are the only reserved keywords
// every other name can be used as name (included __proto__)
@WebReflection
WebReflection / vsc.sh
Created April 15, 2016 17:44
Visual Studio Code
#!/usr/bin/env bash
$(which visual-studio-code) "$@" > /dev/null 2>&1 &
@WebReflection
WebReflection / gtk.sh
Created April 11, 2016 16:22
basic gjs test
gjs -c '
const Gtk = imports.gi.Gtk;
Gtk.init(null);
const win = new Gtk.Window({
type: Gtk.WindowType.TOPLEVEL,
window_position: Gtk.WindowPosition.CENTER
});
win.connect("show", Gtk.main);
win.connect("destroy", Gtk.main_quit);
win.add(new Gtk.Label({label: "centered?"}));
@WebReflection
WebReflection / broadway.md
Created March 29, 2016 15:01
GTK3 Broadway and HiDPi

Broadway on the left, Native on the right.

Avoiding new Foo

function Foo() {
  function foo(a) {
    console.log(a);
  }
  foo.bar = function bar() {
    console.log('bar');
 };

Basic utility to launch a python 2 or python 3 simple http server.

#!/usr/bin/env bash

if [ "$1" != "" ]; then
  PORT="$1"
elif [ "$PORT" = "" ]; then
  PORT=8000
fi
@WebReflection
WebReflection / issue.md
Created February 24, 2016 14:12
Dell XPS Audio / Microphone Issue

Coming from this thread, uploading some evidence about the weird behavior happening only after changing in Ubuntu 16 LTS the input and the output.

@WebReflection
WebReflection / merge.js
Last active February 23, 2016 17:47
A simple way to merge config-like objects or arrays
function merge(t, s) { /*! (C) Andrea Giammarchi */
return Object.defineProperties(t,
Object.keys(s).reduce((o, k) => {
let d = Object.getOwnPropertyDescriptor(s, k),
m = typeof d.value == 'object';
if (m)
d.value = merge(k in t ?
t[k] : Object.create(Object.getPrototypeOf(s[k])
), d.value);
if (m || !(k in t)) o[k] = d;
@WebReflection
WebReflection / dom-class-zero.js
Last active February 18, 2016 19:16
A simplified way to register Custom Elements
var DOMClass = (function (O,o) {
/*! (C) Andrea Giammarchi */
var
create = O.create,
css = create(null),
dP = O.defineProperty,
gOPD = O.getOwnPropertyDescriptor,
gOPN = O.getOwnPropertyNames,