Skip to content

Instantly share code, notes, and snippets.

@ahmedelgabri
Last active December 22, 2020 08:46
Show Gist options
  • Save ahmedelgabri/8122545 to your computer and use it in GitHub Desktop.
Save ahmedelgabri/8122545 to your computer and use it in GitHub Desktop.

Revisions

  1. ahmedelgabri revised this gist Dec 26, 2013. 2 changed files with 3 additions and 3 deletions.
    2 changes: 1 addition & 1 deletion gistfile1.md
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,7 @@ A Modified function of Paul Irish's [StaticServer shell function](https://github
    ### How it works

    ```shell
    $ staticServer <lang> <port>
    $ staticServer <lang> <port> #port is optional, default is 8000
    ```

    Here is an example of how to use it
    4 changes: 2 additions & 2 deletions gistfile2.sh
    Original file line number Diff line number Diff line change
    @@ -4,9 +4,9 @@ staticServer() {
    open "http://localhost:${port}/"

    if [[ "$1" == "ruby" ]]; then
    ruby -run -ehttpd . -p$2
    ruby -run -ehttpd . -p$port
    elif [[ "$1" == "php" ]]; then
    php -S localhost:$2
    php -S localhost:$port
    else
    # Set the default Content-Type to `text/plain` instead of `application/octet-stream`
    # And serve everything as UTF-8 (although not technically correct, this doesn’t break anything for binary files)
  2. ahmedelgabri revised this gist Dec 25, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    ## Static server shell function

    A Modified function of Paul Irish's [StaticServer shell function](https://github.com/paulirish/dotfiles/blob/master/.functions#L25-L32) according to [this gist](https://gist.github.com/willurd/5720255) You can run static servers for many languages.
    A Modified function of Paul Irish's [StaticServer shell function](https://github.com/paulirish/dotfiles/blob/master/.functions#L25-L32), according to [this gist](https://gist.github.com/willurd/5720255) You can run static servers for many languages.

    ### How it works

  3. ahmedelgabri created this gist Dec 25, 2013.
    16 changes: 16 additions & 0 deletions gistfile1.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    ## Static server shell function

    A Modified function of Paul Irish's [StaticServer shell function](https://github.com/paulirish/dotfiles/blob/master/.functions#L25-L32) according to [this gist](https://gist.github.com/willurd/5720255) You can run static servers for many languages.

    ### How it works

    ```shell
    $ staticServer <lang> <port>
    ```

    Here is an example of how to use it
    ```shell
    $ staticServer ruby 9000
    ```

    I'm a shell newbie so I'm sure this can be done in a better way, so fork it, modify it & make it better.
    15 changes: 15 additions & 0 deletions gistfile2.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    # Start an HTTP server from a directory, optionally specifying the port
    staticServer() {
    local port="${2:-8000}"
    open "http://localhost:${port}/"

    if [[ "$1" == "ruby" ]]; then
    ruby -run -ehttpd . -p$2
    elif [[ "$1" == "php" ]]; then
    php -S localhost:$2
    else
    # Set the default Content-Type to `text/plain` instead of `application/octet-stream`
    # And serve everything as UTF-8 (although not technically correct, this doesn’t break anything for binary files)
    python -c $'import SimpleHTTPServer;\nmap = SimpleHTTPServer.SimpleHTTPRequestHandler.extensions_map;\nmap[""] = "text/plain";\nfor key, value in map.items():\n\tmap[key] = value + ";charset=UTF-8";\nSimpleHTTPServer.test();' "$port"
    fi
    }