Skip to content

Instantly share code, notes, and snippets.

View mathieuancelin's full-sized avatar

Mathieu ANCELIN mathieuancelin

View GitHub Profile
import React from 'react';
const maxHeight = 200;
const height = 300;
const Styles = {
container: {
display: 'flex',
flexDirection: 'column',
border: 'solid 1px #f9c300',
width: '100%',
// ---- index.js
import React, { NavigatorIOS, TabBarIOS } from 'react-native';
import { styles } from './style';
import { Reddit } from './reddit';
export const redditnative = React.createClass({
render() {
return (
<NavigatorIOS style = {styles.navigatorios}
package object enums {
trait Day extends Comparable[Day] {
def name(): String
def ordinal(): Int
override def compareTo(o: Day): Int = Integer.compare(this.ordinal(), o.ordinal())
}
private[enums] class DayImpl(n: String, i: Int) extends Day {
def name(): String = n
function Person(firstName: string, lastName: string, age: number) {
if (!this) return new Person(firstName, lastName, age); // if no new, then new to have type
return Object.freeze(Object.assign(this || {}, { // assign is use of enhance this, to have type
copy(obj) {
const values = { firstName, lastName, age, ...obj };
return new Person(values.firstName, values.lastName, values.age);
},
get firstName() {
return firstName;
},
var ws = new WebSocket('...');
var timeout = setTimeout(function() {
console.log('fuuuuuuuu', ws.readyState);
ws.close();
}, monSuperTimeout);
ws.onopen = function(event) {
clearTimeout(timeout);
...
import React from 'react';
// creates an higher order component that can map parts of the context on subcomponent props
export default function enhance(mapper) {
return (Component) => {
return React.createClass({
contextTypes: {
__providedContext: React.PropTypes.object,
},
render() {
function umd(name, api) {
if (typeof exports === "object" && typeof module !== "undefined") {
module.exports = api;
} else if (typeof define === "function" && define.amd) {
define([], function() { return api; });
} else {
var globalScope;
if (typeof window !== "undefined") {
globalScope = window;
} else if (typeof global !== "undefined") {
import React from 'react';
import ReacDOM from 'react-dom';
const Component = React.createClass({
render() {
return (
<h1>Hello World!</h1>
);
}
});
trait Document[T] {}
class JsonDocument extends Document[String] {}
class MyDocument extends Document[String] {}
def get[D <: Document[_]](id: String, timeout: Duration = Duration.Inf)(implicit classTag: ClassTag[D] = ClassTag(classOf[JsonDocument])): Option[D] = {
???
}
val o: Option[JsonDocument] = get("key")
val o2: Option[MyDocument] = get[MyDocument]("key")
const Types = Object.freeze({
Unit: Symbol('Unit')
});
function uselessPromise() {
return new Promise(resolve => {
console.log('Doing stuff !!!');
setTimeout(() => resolve(Types.Unit), 200)
}).then(res => {
if (res === Types.Unit &&