Skip to content

Instantly share code, notes, and snippets.

@geraldstanje
geraldstanje / gist:f69e7d7bca7749b73172
Created October 9, 2014 18:08
XML into MongoDB - quick and dirty
// reference: https://gist.github.com/bufferine/1330475
import net.liftweb.json.Xml // converts XML to JSON
import com.mongodb.casbah.Imports._ // To put stuff in Mongo
import com.mongodb.casbah.MongoDB // To connect to Mongo
import com.mongodb.util.JSON // To parse JSON into a MongoDBObject
import net.liftweb.json._ // To output Lift JSON as actual JSON
import scala.xml.XML // To load XML
// load the XML
val xml = XML.load("http://www.w3schools.com/xml/note.xml")
@geraldstanje
geraldstanje / gist:f108a515718b4342dde7
Created October 12, 2014 18:37
jQuery table draw
<!DOCTYPE html>
<html>
<head>
<style>
#placeholderJavaScript * {
border: 1px solid green;
}
#placeholderjQuery * {
border: 1px solid blue;
@geraldstanje
geraldstanje / gist:e76575ec584aef138c6f
Created October 13, 2014 08:39
send xmlhttprequest
function requestDocument() {
var fileInput = $("select[name=requirements]").val()
if (fileInput.length == 0 || fileInput == "Select a document...") {
alert("Please select a file");
return;
}
var xhr = new XMLHttpRequest();
func uploadHandler(w http.ResponseWriter, r *http.Request) {
body, err := ioutil.ReadAll(r.Body)
if err != nil {
fmt.Println("bad request sent")
w.WriteHeader(400)
return
}
filename := string(body)
@geraldstanje
geraldstanje / bf2c.py
Last active August 29, 2015 14:07 — forked from jdp/bf2c.py
#!/usr/bin/env python
import argparse
import sys
def tokenize(source):
return list(source)
def parse(tokens):
import matplotlib.pyplot as plt
unit_test = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
area = []
threads_num_max = 10
for i in range(0,len(unit_test)):
area.append([])
for thread_num in range(1,threads_num_max+1):
area[i].append((thread_num, unit_test[i] * thread_num))
// Playbook: http://play.golang.org/p/kp5uL_mMGk
// Note: Type assertion like "someVariable.(string)" is useful when you are dealing with interface{} (empty interface)
package main
import (
"fmt"
"strconv"
)
@geraldstanje
geraldstanje / test.py
Last active August 29, 2015 14:07 — forked from leavittx/test.py
import sys
sys.path.insert(0,"../..")
import readline
import os
import ply.lex as lex
import ply.yacc as yacc
import numpy
@geraldstanje
geraldstanje / gist:67dae5e56e6a3ab1b590
Created October 27, 2014 10:05
create/draw graph
package main
import (
"fmt"
"io"
"os"
"strconv"
)
type Graph struct {
package main
import "fmt"
import "sort"
type Dict map[int64]float64
// A slice of Pairs that implements sort.Interface to sort by Key.
type PairList []Pair