Skip to content

Instantly share code, notes, and snippets.

find . -name "*.php" | while read line; do expand -t 4 $line > $line.new; mv $line.new $line; done
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")
// fire up mongo connection
@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):
// 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
<html>
<head>
<title>WebSocket demo</title>
</head>
<body>
<div>
<form>
<label for="numberfield">Number</label>
<input type="text" id="numberfield" placeholder="12"/><br />
<!DOCTYPE html>
<script src="http://mbostock.github.com/d3/d3.v2.js?2.8.1"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<style>
body {
font: 10px sans-serif;
}
rect {
@geraldstanje
geraldstanje / README.md
Last active August 29, 2015 14:10 — forked from mbostock/.block

This example is the second of three in the Path Transitions tutorial; see the previous example for context.

The desired pairing of numbers for path interpolation is like this:

M x0, y0 L x1, y1 L x2, y2 L x3, y3 L xR, y4
   ↓   ↓    ↓   ↓    ↓   ↓    ↓   ↓
M xl, y0 L x0, y1 L x1, y2 L x2, y3 L x3, y4

Where xl is some negative value off the left side, and xr is some positive value off the right side. This way, the first point ⟨x0,y0⟩ is interpolated to ⟨xl,y0⟩; meaning, the x-coordinate is interpolated rather than the y-coordinate, and so the path appears to slide off to the left. Likewise, the incoming point ⟨xr,y4⟩ is interpolated to ⟨x3,y4⟩.

# Method one - w
w | head -n1 | cut -d":" -f4
# Method two - uptime
uptime | cut -d":" -f4- | sed s/,//g
# Method three - loads.d
sudo loads.d | awk '/./ { printf "%.2f %.2f %.2f\n", $7, $8, $9 }'
1. Dining philosopher
2. Given a random number generator that returns a number between [0,1], how would you build a RNG that accounted for weighting?
3. You have two arrays with N integers in them. Merge those arrays using a recursive algorithm so that the integers in the final array are sorted.
4. generators(in python) and about minesweeper.
5. given a query and a document, highlight the query in the document and return a snippet of the document itself. Don't use existing large 3rd party libraries.
6. Finding the longest palindrome in a given string.
7. query log, and how to get the top K most frequent ones
8. Maximum subarray problem
9. Generate all permutations of an alphanumeric string (lowercase/uppercase only if a letter) 10. How can you improve the service of Y?
11. Pick a random number from weighted list based on weight