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 / gist:6857627
Last active December 24, 2015 20:28
Basic example on how to connect through Linux Linino to a sqlite3 database via Arduino Yun and over WiFi
/**
* How to query a sqlite3 database through Arduino Yun
*
* The ability to share a database between Linux Linino
* and the arduino board opens endless possibilities
* in terms of interoperability between these two platforms.
*
* This sketch shows an example through the console
* The output could be used for other goals too.
* Tested over WiFi, use Serial instead of Console for USB
@WebReflection
WebReflection / CustomEvent.js
Last active June 7, 2018 18:29
CustomEvent for IE8 or other old browsers that do not implement it. `new CustomEvent('type', {bubbles:true, detail:{what:'ever'}})`
try{new CustomEvent('?')}catch(o_O){
/*!(C) Andrea Giammarchi -- WTFPL License*/
this.CustomEvent = function(
eventName,
defaultInitDict
){
// the infamous substitute
function CustomEvent(type, eventInitDict) {
var event = document.createEvent(eventName);
@WebReflection
WebReflection / gist:6631470
Last active December 23, 2015 11:49
utils
var utils = (function (Object) {
'use strict';
var
ObjectPrototype = Object.prototype,
ArrayPrototype = Array.prototype,
call = Object.call,
utils = {};
function bind(name) {
if (typeof this[name] === 'function') {
utils[name] = call.bind(call, this[name]);
@WebReflection
WebReflection / SCROLLBAR_SIZE.js
Last active December 23, 2015 04:59
Mobile VS Desktop, the scroll bar might or might not appear plus it's different in most browsers. Windows 8 has 17 pixels scrollbar, Mac has usually 15 pixels only but not a single smart phone has more than 0 pixels. Refined after reading [David Walsh good old post](http://davidwalsh.name/detect-scrollbar-width), feel free to use this *constant*…
var SCROLLBAR_SIZE = SCROLLBAR_SIZE || function(d){
var
e = d.documentElement,
p = d.createElement('p'),
r
;
p.style.cssText = [
';position:absolute',
';margin:0',
';padding:0',
@WebReflection
WebReflection / gist:6357168
Created August 27, 2013 18:26
just a lazy split example based on generators
// @example
// var split = lazySplit(
// 'a.\nb.c',
// /\.(?:[\n\r]*?)?/g
// );
function* lazySplit(str, re) {
for (var
i = 0;
re.test(str);
i = re.lastIndex
@WebReflection
WebReflection / typeOf.js
Last active February 15, 2016 16:12
An incrementally improved approach to a common JavaScript function/utility widely adopted all over. Returns the lowercase type or [[Class]] of a generic variable.
var typeOf = (function(Object, RegExp){
// WTFPL License - http://en.wikipedia.org/wiki/WTFPL
// thanks to @jdalton and @ljharb
var toString = Object.prototype.toString,
cache = (Object.create || Object)(null);
return function typeOf(Unknown) {
var asString = typeof Unknown;
return asString == 'object' ? (
Unknown === null ? 'null' : (
cache[asString = toString.call(Unknown)] || (
@WebReflection
WebReflection / TypedObject.js
Last active December 21, 2015 11:08
JavaScript Structs and Typed Objects simplified "fakelyfill"
(function(){
var
// to include old IEs no 1-9 or 0-9 range as first char allowed
SIMPLE_PROPERTY_NAME = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/,
// the right global to pollute
G = typeof global === typeof G ? window : global,
// shortcut for Function composition
F = G.Function,
// shortcut for common Array stuff
@WebReflection
WebReflection / gist:6225242
Created August 13, 2013 20:16
serializing RegExp
/o/.toJSON || (RegExp.prototype.toJSON = function () {
return [
this.source,
(this.global ? "g" : "") +
(this.ignoreCase ? "i" : "") +
(this.multiline ? "m" : "")
];
});
var re = /test/g;
alert(RegExp.apply(null, JSON.parse(JSON.stringify(re))));
@WebReflection
WebReflection / staticip.sh
Created August 4, 2013 23:11
Quick walk through static ip in Arch Linux
systemctl disable dhcpcd@eth0.service
# vi /etc/systemd/system/network.service
# IP=192.168.1.2/24
# RT=192.168.1.254
[Unit]
Description=Static Connectivity
Wants=network.target
Before=network.target
BindsTo=sys-subsystem-net-devices-eth0.device
// ==========================================
// Copyright 2013 Twitter, Inc
// Licensed under The MIT License
// http://opensource.org/licenses/MIT
// ==========================================
// PROTOTYPE --- WON'T WORK, DON'T USE YET, WAIT FOR IT
define(function (require) {
'use strict';