Skip to content

Instantly share code, notes, and snippets.

function createArray(length, value) {
return Array.apply(null, new Array(length)).map((i, index) => typeof value === 'function' ? value(i, index) : value)
}
createArray(10, (item, index) => ({ a: index }) )
createArray(10, 'lala')
type IItem = {
key: number,
text: string
}
const items: IItem[] = [{key: 0, text: ''}]
// it says type never[] isn't assignable to type [{ text: string}]
for (let index = 1; index < 11; index++) {
items.push({
.visuallyhidden:not(:focus):not(:active) {
position: absolute;
width: 1px;
height: 1px;
margin: -1px;
border: 0;
padding: 0;
white-space: nowrap;
@pixelkritzel
pixelkritzel / extractKeys.js
Created February 24, 2016 14:41
Extract keys from string without delimiter
const str = '__key__dfdsafadf[__index__]kjjkl'
const regx = /__(\w+)__/g
let keys = [];
let res;
while((res = regx.exec(str)) !== null) { console.log( keys.push(res[1]) ) }
import React from 'react';
var template = function(){return(
<form onSubmit={ this.handleFormSubmit.bind(this) } >
<input type="text" value={ this.foo } ref="foo" />
<button type="submit">Go!</button>
</form>
)}
import React, { Component } from 'react';
import template from './MyComponentsTemplate';
export class MyComponent extends Component {
/* skipping all this */
render() {
retun template.call(this)
}
}
import React, { Component } from 'react';
var template = function template() { return(
<form onSubmit={ this.handleFormSubmit.bind(this) } >
<input type="text" value={ this.foo } ref="foo" />
<button type="submit">Go!</button>
</form>
)}
export class MyComponent extends Component {
import React, { Component } from 'react';
export class MyComponent extends Component {
constructor(props) {
super(props);
this.state = {
foo: "foo",
bar: "bar"
}
}
import React, { Component } from 'react';
import template from './MyComponentsTemplate';
export class MyComponent extends Component {
/* skipping all this */
render() {
retun template.call(this)
}
}
@pixelkritzel
pixelkritzel / new_gist_file.js
Created April 20, 2015 17:32
How to trim undefined
(this.get('foobar') || '').trim();