Skip to content

Instantly share code, notes, and snippets.

View wmadden's full-sized avatar

Will Madden wmadden

  • Remerge
  • Berlin, Germany
View GitHub Profile
const activeLocale = germanTranslations;
activeLocale.user.address; // -> "Anschrift"
const germanTranslations = {
user: {
name: "Name",
address: "Anschrift",
gender: "Geschlecht",
},
};
getTranslation("user.address"); // -> "Anschrift"
@wmadden
wmadden / better-return-type-error.ts
Created November 28, 2019 09:07
better-return-type-error.ts
type User = {
id: string;
name: string;
};
function getUser(): User {
return {
id: '123',
namee: 'Tom Hanks', // misspelled
// ^^^^^^^^^^^^^^^^^^
// Type '{ id: string; namee: string; }' is not assignable to type 'User'.
function getUser() {
return {
id: '123',
namee: 'Tom Hanks', // misspelled
};
}
console.log(getUser().name);
// ^^^^
// Property 'name' does not exist on type '{ id: string; namee: string; }'. Did you mean 'namee'?
@wmadden
wmadden / controllers.application.js
Created April 26, 2017 09:08
ember-flatpickr time picker broken bug
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
onFlatpickrChange(dates) {
console.log(dates);
},
flatpickrValue: new Date(),
});
@wmadden
wmadden / controllers.application.js
Last active April 26, 2017 08:55
ember-flatpickr attributeBindings bug
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
onFlatpickrChange(dates) {
this.set('flatpickrValue', dates);
},
flatpickrValue: new Date(),
});
@wmadden
wmadden / fix_fixed.coffee
Created July 15, 2015 12:50
fix_fixed.coffee
define [
'jquery'
], ($) ->
# Fix Fixed is a work around an iOS bug involving fixed positioned elements.
# Whenever the keyboard shows up, a fixed positioned element would reposition
# itself randomly on the screen. This work around adds the .fix-fixed class to the
# body in order to let fixed positioned elements change their position to absolute
# while the keyboard is shown.
#
@wmadden
wmadden / react_wrapper.coffee
Last active September 8, 2015 10:06
react_wrapper.coffee
class ReactWrapper extends Marionette.ItemView
initialize: ({ @Element, props }) ->
@model ?= new Backbone.Model(props)
@listenTo @model, 'change', @updateProps
render: =>
@component = React.render( React.createElement(@Element, @serializeData()), @el )
close: => React.unmountComponentAtNode(@el)
@wmadden
wmadden / eventually.js
Last active August 29, 2015 14:23
eventually
var MAX_TIME_TO_WAIT = 10; // ms
// Tests for the eventual satisfaction of a set of expectations. Returns
// a Promise that resolves if the given function runs without errors and
// rejects if resolution cannot be obtained within `MAX_TIME_TO_WAIT` ms.
function eventually(expectations) {
var timeStarted = Date.now();
new Promise(function (resolve, reject) {
function testExpectationsAndResolve() {
try {
'.source.js':
'React.PropTypes.':
'prefix': 'rpt'
'body': 'React.PropTypes.${1},${2}'
'React.PropTypes.string':
'prefix': 'rpts'
'body': 'React.PropTypes.string${1:.isRequired},${2}'
'React.PropTypes.object':
'prefix': 'rptobj'
'body': 'React.PropTypes.object${1:.isRequired},${2}'