Skip to content

Instantly share code, notes, and snippets.

@eliben
eliben / gist:9158261
Created February 22, 2014 17:12
embedded comment in next prefix
Input code:
x = 1 # told you
y = 2
Breakdown of the lib2to3 parse tree. The thingies with [N children] are nodes. The rest are leaves.
file_input [3 children]
@eliben
eliben / gist:9158301
Created February 22, 2014 17:14
comment after def
def foo(): # told you
y = 2
file_input [2 children]
funcdef [5 children]
NAME('def') [lineno=1, column=0, prefix='']
NAME('foo') [lineno=1, column=4, prefix=' ']
parameters [2 children]
LPAR('(') [lineno=1, column=7, prefix='']
RPAR(')') [lineno=1, column=8, prefix='']
@eliben
eliben / lexer.go
Last active January 26, 2022 04:03
TableGen lexer in Go (lexer.go and an input file)
// Lexer for the TableGen language.
package main
import (
"fmt"
"io/ioutil"
"log"
"time"
"unicode/utf8"
)
#301 Redirects for .htaccess
#Redirect a single page:
Redirect 301 /pagename.php http://www.domain.com/pagename.html
#Redirect an entire site:
Redirect 301 / http://www.domain.com/
#Redirect an entire site to a sub folder
Redirect 301 / http://www.domain.com/subfolder/
diff --git a/lib/CodeGen/CodeGenPrepare.cpp b/lib/CodeGen/CodeGenPrepare.cpp
index dc5f67b..6aa60c6 100644
--- a/lib/CodeGen/CodeGenPrepare.cpp
+++ b/lib/CodeGen/CodeGenPrepare.cpp
@@ -1640,6 +1640,7 @@ bool AddressingModeMatcher::MatchScaledValue(Value *ScaleReg, int64_t Scale,
static bool MightBeFoldableInst(Instruction *I) {
switch (I->getOpcode()) {
case Instruction::BitCast:
+ case Instruction::AddrSpaceCast:
// Don't touch identity bitcasts.
@eliben
eliben / cuda.h
Created October 6, 2014 22:11
Minimal CUDA support header for parsing with Clang
/* Minimal declarations for CUDA support. Testing purposes only. */
#define __constant__ __attribute__((constant))
#define __device__ __attribute__((device))
#define __global__ extern "C" __attribute__((global))
#define __host__ __attribute__((host))
#define __shared__ __attribute__((shared))
#define __launch_bounds__(...) __attribute__((launch_bounds(__VA_ARGS__)))
#define __forceinline__ __attribute__((always_inline))
foo = "\\"
bar = "\n"
manyescapes = "\\\\\\\\"
manyescapes2 = "\n\\\n\\"
@eliben
eliben / thoughts.rst
Last active October 12, 2018 04:53
Thoughts on the Go 2 Error Handling proposal

TL;DR: The proposal looks good, except the handler chaining part, which adds a lot of magical complexity to cater to rare use cases. Chaining can always be added at a later stage without breaking backwards compatibility, if its lack is deemed unbearable.

As I see it, the biggest issues in current Go usage the proposal tackles are:

  1. Repeated sequences of if err != nil {return nil, err} littering Go code
  2. Lack of proper context in propagated errors (see (1) above)

To fix these issues, I believe the proposed check keyword with a single handler per function are sufficient. Using stacks of handlers for proper cleanup is best left to defer, which is already a familiar tool. Thus, handle should only exist as a default "report more context in case of an error and return the error" mechanism. Where a single handler appears insufficient because the nature of error handling required changes throug

package main
import (
"bufio"
"encoding/json"
"fmt"
"log"
"os"
)
Title: Waiting for goroutines to finish
URL slug: waitgroup
Description: A WaitGroup provides a simple way to wait for a collection of goroutines to perform a task.