Skip to content

Instantly share code, notes, and snippets.

View olov's full-sized avatar

Olov Lassus olov

  • Linköping, Sweden
View GitHub Profile
@olov
olov / gist:1320163
Created October 27, 2011 17:10
Pygments DartLexer for syntax highlighting. Example and installation instructions: <http://blog.lassus.se/2011/10/dart-syntax-highlighting.html>
class DartLexer(RegexLexer):
"""
For `Dart <http://dartlang.org/>`_ source code.
"""
name = 'Dart'
aliases = ['dart']
filenames = ['*.dart']
mimetypes = ['text/x-dart']
import * as React from "react";
import { nextTick } from "../std/nexttick";
import { updated } from "../std/fridge";
import { shallowObjectEquals } from "../std/u";
const uniqueObject = {};
export class StatefulComponent<T, U> extends React.Component<T> {
protected readonly data: U;
private allowRender: boolean = true;
@olov
olov / app.jsx
Last active September 13, 2016 20:53
import { Router } from 'react-router';
import { Match } from "./matchchildren"
const App = () => (
<Router>
<Match pattern="/"><Hello name="Yoyoma"/></Match>
</Router>
)
const Hello = (props) => {
@olov
olov / react-router-children-api.tsx
Created September 13, 2016 18:07
what prevents this kind of react-router API?
// Run this example locally by copy/pasting it into
// `src/App.js` of an app created with `create-react-app`
// https://github.com/facebookincubator/create-react-app
import React from 'react'
import Match from 'react-router/Match'
import Miss from 'react-router/Miss'
import Link from 'react-router/Link'
import Redirect from 'react-router/Redirect'
import Router from 'react-router/BrowserRouter'
@olov
olov / gist:eb60ab878eb73a7c5e22
Created October 15, 2014 08:55
listenandservetls_nossl30.go
// You don't want to serve HTTPS supporting for SSL3.0 any longer, see:
// http://googleonlinesecurity.blogspot.de/2014/10/this-poodle-bites-exploiting-ssl-30.html
import (
"crypto/tls"
"net/http"
)
// This code supports SSL3.0, TLS1.0, TLS1.1 and TLS1.2
// Chances are you currently do this but want to stop due to the POODLE
err := http.ListenAndServeTLS(addr, "crtfile", "keyfile", handler)
@olov
olov / lossy_dropbox.txt
Created January 5, 2014 19:19
Dropbox, you're handling >260 long paths wrong on Windows
Hello there,
I'm supporting DELETED and DELETED with IT. Both of them are paying customers of yours. I was pretty shocked when I learned today that when you encounter a path longer than 260 characters (on a Windows system), you do no sync it, and you do not inform the end user about it. In a shared folder setup, this is pretty disastrous.
I can think of two sensible ways to handle the limitation of 260 character long paths in Windows.
1. Detect them, and inform the user prominently that he/she has files that will not be synced.
2. Detect and sync as usual (this is certainly possible from a technical standpoint).
Your current way of handling this causes lots of frustration to end-users and at the end of the day, may cause them to lose data quite easily.
@olov
olov / smallsort.c
Last active December 30, 2015 05:58
sorting algorithms for small arrays
#include <stdio.h>
#include <sys/types.h>
#include <stdlib.h>
#include <unistd.h>
#include <time.h>
#include <string.h>
#include <sys/time.h>
long long gettime_ms(void)
{
@olov
olov / alternate.js
Last active December 22, 2015 08:18
funny little ES6 for (let;;) example
// according to my guesses of what is to come in future ES6 specs:
// the loop should execute five times so the program should print five numbers at the end
// the fresh-per-iteration x is captured in a closure (that will increment it by 3),
// then executed (for side-effects only) in the cond-expr and post-expr.
// it will never ever modify the outer x thus five loop iterations
(function() {
let arr = [];
let fn = null;
let cnt = 0;
for (let x = 0; (fn && fn()), x < 5; (fn && fn()), x++) {
@olov
olov / gist:6443290
Created September 4, 2013 21:45
es6 loop variable bindings
// will this example
let arr = [];
for (let x = 0; x < 5; x++) {
x++;
arr.push(function() { return x; });
}
// ..be semantically equivalent to this?
let arr = [];
Lot's of good stuff from Ariya as always and expected! :) I wanted to chime in with a couple of comments regarding ES6 block scope, const in particular. It's kind of a pet-peeve of mine (I'm the author of the defs transpiler).
The article describes Mozilla-JS const, not ES6 const. Mozilla-JS const is not block scoped and is silent on reassignment. ES6 const is block scoped and reassignment is a static error found at parse time (see https://gist.github.com/olov/6255863) before program execution. Do note that you have to opt-in to using ES6 const in v8/node via strict mode, otherwise you'll get Mozilla-const semantics. Prepend a "use strict"; to the example and re-run it - *boom* you're now in the beautiful world of ES6 const. :)
Also, while not an error, my humble opinion is that we're missing out big time by teaching that "the major use case for const is to safeguard important constants". While that may have been true in a Mozilla-JS const world, in ES6 const means that the variable binding won't change - a