This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns graph) | |
(defrecord Node [properties]) | |
(defn new-node | |
[properties] (Node. properties)) | |
(defrecord Edge [node properties weight]) | |
(defn new-edge | |
([node] (Edge. node {} 0)) | |
([node properties] (Edge. node properties 0)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn roll-dice [sides] | |
(let [dice (map inc (take sides (range)))] | |
(rand-nth dice))) | |
(roll-dice 6) ;; => random number between 1 and 6 | |
;; This is much better: | |
(defn roll-dice [sides] | |
(inc (rand-int sides))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
def to_base_ten(str_num): | |
i = 0 | |
base10 = 0 | |
for num in reversed(str_num): | |
base10 += int(num) * pow(3, i) | |
i += 1 | |
return base10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"/> | |
<title>Forms test</title> | |
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" /> | |
</head> | |
<body> | |
<div class="container"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
// Add ECMA262-5 method binding if not supported natively | |
// | |
if (!('bind' in Function.prototype)) { | |
Function.prototype.bind= function(owner) { | |
var that= this; | |
if (arguments.length<=1) { | |
return function() { | |
return that.apply(owner, arguments); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var sw = new Object(); | |
sw.square = function (x) { return x * x; } | |
sw.cube = function (x) { return x * (x * x); } | |
var x = 2 | |
var name = 'square'; | |
sw[name](x) // => 4 |
NewerOlder