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 / re
Created January 18, 2015 18:31
a js17 based bash utility to regexp a generic input
#!/usr/bin/env bash
js17 -e '
function stdin() {
var a = [], l;
while(null != (l = readline())) a.push(l);
return a.join("\n");
}
print(
(arguments[2] || stdin()).replace(
@WebReflection
WebReflection / inherit.js
Created January 14, 2015 22:53
good old prototypal inheritance done without leaks
var inherit = (function () {
function Constructor() {
// always reassign the initial
// prototype to avoid problems
// in jurassic engines
Constructor.prototype = cp;
}
// original prototype
var cp = Constructor.prototype;
// the inherit function
function shoutOut(name, opts) {
opts || (opts = {});
return [
name, 'says',
opts.greeting || 'greeting',
opts.target || 'target'
].join(' ');
}
@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);
@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 / String.prototype.template.js
Last active August 17, 2022 04:04
ES6 Template like strings in ES3 compatible syntax.
// this is now a module:
// https://github.com/WebReflection/backtick-template#es2015-backticks-for-es3-engines--
var template = require('backtick-template');
// just string
const info = 'template';
`some ${info}` === template('some ${info}', {info});
@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 / 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 / is-native-function.js
Last active March 27, 2021 18:25
a runtime feature detection way to sniff native functions from fakes
var isNativeFunction = (function (Function) {
var
toString = Function.toString,
re = new RegExp(
'^' +
toString
.call(Function)
.replace(/([\/\\[\]{}()^$.*+?_-])/g, '\\$1')
.replace('Function', '[a-zA-Z$_][\\S]*') +
'$'

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">