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 / dollar.js
Last active August 29, 2015 14:01
A jQuery like function with :first built in optimization, will return an Array regardless it's one element search only for consistency.
function $(CSS, parentNode) {
// @link http://webreflection.blogspot.com/2014/05/134-bytes-for-optimized-and-very-basic.html
var el = parentNode || document,
first = CSS.lastIndexOf(':first') === CSS.length - 6,
query = first ?
el.querySelector(CSS.slice(0, -6)) :
el.querySelectorAll(CSS);
return first ?
(query ? [query] : []) :
Array.prototype.slice.call(query);
ctor->defineDefaultProperty(QStringLiteral("setPrototypeOf"), method_set_proto_of, 2);
ReturnedValue ObjectPrototype::method_set_proto_of(CallContext *ctx)
{
Scope scope(ctx);
Scoped<Object> o(scope, ctx->argument(0));
Scoped<Object> p(scope, ctx->argument(1));
if (!o)
return ctx->throwTypeError();
o->method_set_proto(p);
@WebReflection
WebReflection / nody
Last active August 29, 2015 14:02
nody is a little CDN like script designed for low memory capable devices and read-only intranets
#!/usr/bin/env node
/**
* ___ ___ ___ ___
* /\__\ /\ \ /\ \ |\__\
* /::| | /::\ \ /::\ \ |:| |
* /:|:| | /:/\:\ \ /:/\:\ \ |:| |
* /:/|:| |__ /:/ \:\ \ /:/ \:\__\ |:|__|__
* /:/ |:| /\__\ /:/__/ \:\__\ /:/__/ \:|__| /::::\__\
* \/__|:|/:/ / \:\ \ /:/ / \:\ \ /:/ / /:/~~/~
@WebReflection
WebReflection / AnimationBatch.js
Last active August 29, 2015 14:06
A generic requestAnimationFrame batches controller
var AnimationBatch = AnimationBatch || (function(window){
'use strict';
/*! (C) Andrea Giammarchi - Mit Style License */
var
instances = [],
forEach = instances.forEach || function (fn) {
// ad-hoc shim for this use case
var
self = this,

My table orderer ... instead of the filter

<!DOCTYPE html>
<html ng-app="tasteAngularJS">
    <head>
      <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.26/angular.min.js"></script>
      <link rel="stylesheet" 
      href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
      <link rel="stylesheet" 
      href="https://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css">
@WebReflection
WebReflection / proto-reviver.js
Created November 25, 2014 22:04
A cross platform JSON reviver able to return instances from namespaces
var protoReviver = (function (proto, hasNoProto) {
// (C) Andrea Giammarchi - WTFPL License
return function (k, v) {
if (k === proto && v !== null) {
for (var
tmp = window,
nmsp = v.split('.'),
i = 0;
i < nmsp.length;
i++
@WebReflection
WebReflection / arrayfy.js
Created December 2, 2014 12:55
Add Array.prototype methods to a generic constructor.prototype
function arrayFy(constructor) {
Object.getOwnPropertyNames(
Array.prototype
).forEach(function (key) {
var descriptor = Object.getOwnPropertyDescriptor(
Array.prototype,
key
);
if (
typeof descriptor.value === 'function' &&
@WebReflection
WebReflection / static-group.md
Last active August 29, 2015 14:11
Annotated static group in class definition

The proposal is to be able to define multiple static properties as group, using already defined object literal syntax.

// currently in ES6
class Foo {
  static f() {return 'f';}
  static get g() {return 'g';}
}
@WebReflection
WebReflection / shellog.js
Last active August 29, 2015 14:13
basic bash logger with cursor and feedback
log.cursor = '\\|/-';
function log(info) {
// (C) Andrea Giammarchi
var
verify = function (condition) {
if (timer) {
if (condition()) {
self.ok();
} else {
setTimeout(verify, delay, condition);
function shoutOut(name, opts) {
opts || (opts = {});
return [
name, 'says',
opts.greeting || 'greeting',
opts.target || 'target'
].join(' ');
}