Skip to content

Instantly share code, notes, and snippets.

@dbehnke
dbehnke / earthdate.py
Created January 1, 2014 02:43
My stardate inspired way to tell time... just for fun.. not to be used seriously.
from datetime import datetime
from datetime import timedelta
import time
def getearthdate(dt_now):
dt_begin = datetime(dt_now.year, 1, 1)
dt_end = datetime(dt_now.year + 1, 1, 1)
delta_year_length = dt_end - dt_begin
import org.joda.time._
val typedef = Seq("string", "datetime")
val data = Seq("hi","014-01-07T15:57:52.253-05:00")
val x: Seq[Any] = (for(i <- 0 to data.length - 1)
yield({
if (i <= typedef.length)
typedef(i) match {
case "datetime" => new DateTime(data(i))
@dbehnke
dbehnke / async_server.py
Created January 28, 2014 05:49
Fun with Asyncore and Python 3.3
import asyncore
import asynchat
import time
connections_processed = 0
class AServerHandler(asynchat.async_chat):
# def __init__(self, sock, addr, sessions, log):
@dbehnke
dbehnke / requirements.txt
Last active August 22, 2021 21:36
Severe weather alert grab from NOAA - http://alerts.weather.gov/
feedparser
requests
@dbehnke
dbehnke / app.js
Last active August 29, 2015 13:56
create a simple static web server for development with node.js
/*
Simple test webserver for static content - the docs are bigger than the code!
1. install node and npm: http://nodejs.org/
2. create a directory where you want your little web server
3. cd to that directory
4. save this file you are reading to that directory as app.js
5. npm install express
6. mkdir public
@dbehnke
dbehnke / trusty-post-install.sh
Created March 5, 2014 17:54
Ubuntu 14.04 LTS (Trusty) Post Install Tasks
#!/bin/bash
#Post Install for Ubuntu 14.04 LTS (Trusty)
#copy and paste and run - don't run this script directly
#you are going to need to reboot after each part.
echo "Don't run this script directly, copy and paste"
echo "the parts you will use! See the file's comments for information."
echo ""
echo "The script will run part 1 for you.. then read the file for rest!"
@dbehnke
dbehnke / client.py
Created March 18, 2014 19:08
Python AsyncIO Client and Server Example using StreamReader and StreamWriter
"""
client.py - AsyncIO Server using StreamReader and StreamWriter
This will create 200 client connections to a server running server.py
It will handshake and run similar to this:
Server: HELLO
Client: WORLD
@dbehnke
dbehnke / server.go
Created March 31, 2014 15:16
a work in progress.. simple tcp server in go.
package main
import (
"bufio"
"fmt"
"log"
"math/rand"
"net"
"time"
)
@dbehnke
dbehnke / gorilla-go-json-rpc-test.go
Created April 11, 2014 02:09
JSON RPC with Go and Gorilla
package main
/*test with curl
curl -X POST -H "Content-Type: application/json" \
-d '{"method":"HelloService.Say","params":[{"Who":"Test"}], "id":"1"}' \
http://localhost:10000/rpc
*/
import (
"github.com/gorilla/rpc"
@dbehnke
dbehnke / chanmutex.go
Created June 23, 2014 21:10
Multiple go routines handling a single channel.
package main
//http://play.golang.org/p/kLmBrJYchH
import (
"fmt"
"time"
)
func mychan(id string, c chan string) {