Skip to content

Instantly share code, notes, and snippets.

Chris Lewis cflewis

Block or report user

Report or block cflewis

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View go2_file_abstraction.md

Non-Local File Systems Should Be Supported

TL;DR

Files are all over the Internet, and Go should provide a reasonable abstraction in its stdlib to handle this.

Problem

Files are everywhere. Local disk is the obvious place. But they're also in storage buckets like Google Cloud Storage and Amazon S3. They're in code repositories like GitHub and Google Source. They're in personal storage like Dropbox and Evernote. They're on other machines or filesystems on corporate Intranets. Tests which write to disk are much less error-prone if they write to volatile memory, such as a RAMFS.

Go 1's os package provides an os.File struct. The implicit assumption is that local disk storage is the only thing the stdlib should care about, and that external packages should provide access to these other sources. In 2007, this would have been a reasonable approach. In 2017, files are increasingly unlikely to be local.

View BUILD
java_toolchain(
name = "java8",
encoding = "UTF-8",
source_version = "8",
target_version = "8",
misc = [
"-extra_checks:on",
],
)
View haskell-wordcount.hs
import Data.Char
import Data.String.Utils
import Data.Maybe
import qualified Data.Map as M
import System.Environment
import Control.Parallel
import Control.Parallel.Strategies
import Control.Monad
type WordCount = M.Map String Int
View gist:3849926
protected function targetButton_dragDropHandler(event:DragEvent):void
{
var draggedButton:Button = event.dragInitiator as Button;
var droppedOnButton:IVisualElement = event.currentTarget as IVisualElement;
var newButton:Button = new Button();
var parent:Group = droppedOnButton.parent as Group;
// Set up the new button
newButton.label(draggedButton.label);
newButton.color(draggedButton.color);
@cflewis
cflewis / json.go
Created Sep 24, 2012
Parse JSON example
View json.go
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
"os"
)
View gist:3778196
package main
import (
"fmt"
"io/ioutil"
"log"
"net/http"
"os"
)
@cflewis
cflewis / gist:1244092
Created Sep 27, 2011
Docgen, a silly personal script to handle pre and post processing of Pandoc files
View gist:1244092
#! /usr/bin/env python
import re
import subprocess
import tempfile
import sys
import os
class Processor(object):
def __init__(self):
pass
View Kitty.scala
package com.cflewis.lyss.kitty_server
import akka.actor.Actor
import akka.actor.Actor._
import akka.config.Supervision._
case class Cat(name: String, color: String, description: String)
case class OrderCat(name: String, color: String, description: String)
case class ReturnCat(cat: Cat)
case class CloseShop()
View Starcraft.scala
class StarcraftResourceGame extends EgyptModel {
val name = "Starcraft Resource Game"
def get_crystal = {
require(crystals > 0)
crystals--
}
def get_gas = {
require(gas > 0)
View ZipEntry.java
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
You can’t perform that action at this time.