Skip to content

Instantly share code, notes, and snippets.

View jonathanweiss's full-sized avatar

Jonathan Weiss jonathanweiss

View GitHub Profile
@jonathanweiss
jonathanweiss / fun_with_proxies.js
Created June 27, 2017 06:15
Proxies can be quite useful
const vCard = {
firstName: '',
lastName: '',
yearOfBirth: 0
};
// Simple logging:
const vCardLogged = new Proxy(vCard, {
set: (obj, prop, value) => {
console.log(`vCard got new value for key "${prop}": "${value}"`);
@jonathanweiss
jonathanweiss / trace_changes.js
Created June 22, 2017 17:44
Combine Proxy with new Error().stack for tracing changes.
const o = {};
const n = new Proxy(o, {
set: (obj, prop, value) => {
obj[prop + '_trace'] = new Error().stack;
obj[prop] = value;
return true;
}
});
n.a = 10;
console.log(JSON.stringify(n.a_trace, null, 2));
@jonathanweiss
jonathanweiss / js_fn_es6.js
Created March 7, 2017 10:58
Same example in ES6
'asdf klkl wererw cvxcxv'
.split(' ')
.reduce((list, word) => list.length < 2 ? [...list, word] : list, [])
.map(word => word.substring(0, 1).toUpperCase())
.join('');
@jonathanweiss
jonathanweiss / js_fn_example.js
Last active March 7, 2017 10:29
Another functional programming example for Raphael
'asdf klkl wererw cvxcxv'
.split(' ')
.reduce(function(list, word){
if (list.length < 2) {
list.push(word);
}
return list;
}, [])
.map(function(word) {
return word

Keybase proof

I hereby claim:

  • I am jonathanweiss on github.
  • I am jonathanweiss (https://keybase.io/jonathanweiss) on keybase.
  • I have a public key whose fingerprint is 39CD FF8A D577 1D27 7702 5FBA 8DEA 8317 E70D 5FFF

To claim this, I am signing this object:

@jonathanweiss
jonathanweiss / husky_error_handling.js
Created March 9, 2016 15:13
Husky Error Handling
window.onerror = function (message, source, lineno, colno, error) {
var stack = '';
var browser = navigator.userAgent;
if (error && error.stack) {
stack = JSON.stringify(error.stack)
}
var errorData = {
Message: message,
@jonathanweiss
jonathanweiss / Inject Undersore
Created February 11, 2014 08:36
Injects _ into the current website.
(function(url){
var head = document.getElementsByTagName('head')[0];
var script = document.createElement('script');
script.src = url;
head.appendChild(script);
})('http://underscorejs.org/underscore-min.js');
@jonathanweiss
jonathanweiss / qx_bug #2573
Created March 22, 2010 10:58
Playground demo for bug #2573
var doc = this.getRoot();
var t = new qx.ui.tabview.TabView();
for (var i=1; i<=20; i++)
{
var page = new qx.ui.tabview.Page("Page #" + i, "icon/16/apps/utilities-terminal.png");
page.setLayout(new qx.ui.layout.VBox());
page.add(new qx.ui.basic.Label("Page #" + i + " with close button."));
@jonathanweiss
jonathanweiss / qx_bug #2591
Created March 22, 2010 09:53
Playground demo for bug #2591
var doc = this.getRoot();
var s = new qx.ui.form.Spinner();
s.setHeight(400);
s.set({
allowGrowX : false,
allowGrowY : false
})
sc = new qx.ui.container.Scroll();
alert("Business-Kasper");