Skip to content

Instantly share code, notes, and snippets.

View alecthomas's full-sized avatar
😀

Alec Thomas alecthomas

😀
View GitHub Profile
+
+ <div class="page">
+ <ul class="tabs">
+ <li class="tab" onclick="{TabChanged Title}">Hello</li>
+<li class="tab" onclick="{TabChanged Title}">Goodbye</li>
+
+ </ul>
+ <div class="content">
+ <p>hello world</p>
+ </div>
@alecthomas
alecthomas / participle.go
Created October 15, 2018 01:59
Participle
package main
import (
"fmt"
"github.com/alecthomas/participle"
"github.com/alecthomas/repr"
)
type CLI struct {
Currently, it works.
```
➤ echo 'field2; field1; @f3 = foo(1,2);' | go run main.go
&main.FieldExprs{
Exprs: []*main.FieldExpr{
&main.FieldExpr{
Field: &"field2",
},
&main.FieldExpr{
@alecthomas
alecthomas / DayAndNight.py
Created March 31, 2016 01:48
Sublime plugin to toggle between light and dark themes
import sublime
import sublime_plugin
class DayAndNightCommand(sublime_plugin.ApplicationCommand):
def run(self):
s = sublime.load_settings("Preferences.sublime-settings")
if s.get("theme") == "Reverse Gravity.sublime-theme":
print("Switching to dark theme")
s.set("theme", "Gravity.sublime-theme")
@alecthomas
alecthomas / entityx_tx2.cc
Last active May 17, 2016 10:26
Parallel EntityX prototype
#include <utility>
#include <thread>
#include <limits>
#include <algorithm>
#include <cassert>
#include <vector>
#include <cstdint>
#include <iostream>
#include <mutex>
#include <future>
@alecthomas
alecthomas / log.cc
Last active May 17, 2016 10:26
Simple, type and thread safe C++11 console logging function
#include <iostream>
#include <mutex>
std::recursive_mutex log_lock;
// If you have ever tried using cerr/cout from multiple threads you may have experienced
// character interleaving. These functions avoid that.
template <typename A>
void log(const A &arg) {
log_lock.lock();
@alecthomas
alecthomas / entityx_tx.cc
Created October 14, 2015 22:40
Experimental (not working) EntityX transactional support
#include <condition_variable>
#include <thread>
#include <mutex>
#include <iostream>
#include <algorithm>
#include <type_traits>
#include <vector>
#include <cstdint>
#include <iterator>
#include <functional>
@alecthomas
alecthomas / tryerror.go
Last active November 6, 2015 01:27
What would Go code look like with Swift 2.0-style error handling?
// before
func CreateZipWithWriter(writer io.Writer, sourceRoot string) error {
zf := zip.NewWriter(writer)
defer zf.Close()
return filepath.Walk(sourceRoot, func(p string, info os.FileInfo, err error) error {
if err != nil || info.IsDir() {
return err
}
relPath, err := filepath.Rel(sourceRoot, p)
if err != nil {
@alecthomas
alecthomas / IO.swift
Created July 8, 2015 13:38
Swift IO
//
// Swift.IO
//
// Created by Alec Thomas on 25/02/2015.
// Copyright (c) 2015 SwapOff. All rights reserved.
//
//
// This file provides a consistent, simple interface to stream-based data sources.
// It is based on Go's I/O library.
//
#pragma once
#include <string>
#include <unordered_set>
#include "entityx/Entity.h"
#include "entityx/Event.h"
class Groups : public entityx::Receiver<Groups> {
public: