Skip to content

Instantly share code, notes, and snippets.

View learner-long-life's full-sized avatar

Paul Pham learner-long-life

View GitHub Profile
@learner-long-life
learner-long-life / gist:8057238
Created December 20, 2013 16:22
Supposed improvement in Python file-reading speed, submitted by one of my students
inputfile = open(filename)
#...
# I swear enumerate() makes this faster.
for i, line in enumerate(inputfile):
if readnext == True: # Previous line started with an '@'
# linescounted += 1 # For line count check.
for bp in line.rstrip():
if bp == 'G':
@learner-long-life
learner-long-life / google-type.css
Last active August 29, 2015 14:12
D3 analog clock from Eric Bullington
body { margin: 0; padding: 0; zoom: 1; }
h1, h2, p { margin: 0; padding: 0; }
.strike { text-decoration: line-through; }
.avatar img { width: 30px; height: 30px; -webkit-border-radius: 15px; -moz-border-radius: 15px; border-radius: 15px; }
.caption { margin: 0 0 60px 20px; }
.caption a { font: 14px/16px 'Unica One', Helvetica, Arial, sans-serif; letter-spacing: .1em; color: #999; text-transform: uppercase; text-decoration: none; }
.caption a:hover { background-color: #ddd; }
public class FizzBuzz {
public static void main(String[] args) {
for (int i = 0; i < 100; i++) {
if (i % 3 == 0) {
System.out.println("fizz");
} else if (i % 5 == 0) {
System.out.println("buzz");
} else if ((i % 3 == 0) && (i % 5 == 0)) {
// First, checks if it isn't implemented yet.
// from http://stackoverflow.com/questions/610406/javascript-equivalent-to-printf-string-format
if (!String.prototype.format) {
String.prototype.format = function() {
var args = arguments;
return this.replace(/{(\d+)}/g, function(match, number) {
return typeof args[number] != 'undefined'
? args[number]
: match
;
class Node
def initialize(data)
@left = nil
@right = nil
@data = data
end
def setLeft(leftChild)
@left = leftChild
<div id="first">
This is a first div
</div>
@learner-long-life
learner-long-life / gist:38f207816554b8bbffef58aa7cfebcf1
Created May 5, 2017 01:18
How to iterate over a Jackon JsonNode / Java Map Entry iterator in Scala
import scala.collection.JavaConverters._
import com.fasterxml.jackson.core.JsonFactory
import com.fasterxml.jackson.databind.JsonNode
import com.fasterxml.jackson.databind.node.{JsonNodeFactory, MissingNode, ObjectNode}
val jf = new JsonFactory(true)
val o = new ObjectNode(jf)
o.put("yellow","banana")
for (v <- o.fields.asScala) { println(v.getKey(),v.getValue()) }
0xc4d410134bb9e5cd73079604cda6faeafe0e64c0
0xb2e9fe08ca9a0323103883fe12c9609ed380f475