Skip to content

Instantly share code, notes, and snippets.

View quephird's full-sized avatar

danielle quephird

View GitHub Profile
(require ['clojure.string :as 'str])
(def cpu (atom {:x 1 :cycles 0}))
(def log (atom [1]))
(def crt (atom []))
(defn draw-pixel []
(let [x (get-in @cpu [:x])
(require ['clojure.string :as 'str])
(def head (atom [0 0]))
(def tail (atom [0 0]))
(def visited-tail-positions (atom #{[0 0]}))
(defn get-x [atom]
(get @atom 0))
(require ['clojure.string :as 'str])
(defn to-vec-of-ints [line]
(->> line
(map #(Integer/parseInt (str %)))
vec))
(defn to-grid [trees]
(->> trees
(map to-vec-of-ints)
(require ['clojure.string :as 'str])
;; The file system is represented by a deep hashmap
;; of file and directory names as keys, and either a
;; file size or list of subdirectory names and files as
;; their values.
(def file-system (atom {"/" {}}))
;; The current directory is always a vector of names.
;; For example, the path "/foo/bar/baz" is represented by
(require ['clojure.string :as 'str])
(def stacks
{1 ["Q" "M" "G" "C" "L"]
2 ["R" "D" "L" "C" "T" "F" "H" "G"]
3 ["V" "J" "F" "N" "M" "T" "W" "R"]
4 ["J" "F" "D" "V" "Q" "P"]
5 ["N" "F" "M" "S" "L" "B" "T"]
6 ["R" "N" "V" "H" "C" "D" "P"]
7 ["H" "C" "T"]

Sometimes you just want to be able to modularize/namespace your code without having to make a full-fledged library out of it. Go seems to discourage this sort of this as of 1.16 and wants you make a separate remote repo to house such code, and then you can import it into your main project. Unless I'm missing something, this feels like Go discourages local namespacing of code within a single project. But there is a way to accomplish this even if it's not considered idiomatic.

  • Relative to the root directory of your project, first create a new directory within your main project to house a local module, in this example zomg.
  • Then from within that directory create a new file, say, zomg.go, and put the following in it:
#version 100
precision mediump float;
uniform float u_time;
uniform vec2 u_resolution;
#define FIREWORK_COUNT 5.0
#define FIREWORK_DURATION_IN_SECONDS 10.0
#define PI 3.1415926
use std::io::stdin;
fn what_is_your_name() -> String {
println!("Hello! What's your name?");
let mut your_name = String::new();
stdin()
.read_line(&mut your_name)
.expect("You forgot to enter something!!!");
your_name

SQLite, JDBC, Clojure, and Booleans

Most RDBMS' do not support a native Boolean type; Postgres is one of the few that actually does, allowing the programmer use a native Boolean type in both their application code and database code. Oracle, and many others, does not at all, and so most programmers resort to some sort of convention whereby the set of values of a Boolean-like column is restricted to 1 or 0, or 'T' or 'F', or 'Y', or 'N'.

SQLite is in a third category; it does support a Boolean type but the boolean keyword is actually a synonym for the tinyint type, and the values are actually managed in the database as 1 for true, and 0 for false. Moreover, when you query the database, you only get back out the tinyint representations. This complicates matters if you wish to take advantage of the boolean type in the database and in your application code without having to constantly transform values both in and out of it.

Here's an example; let's create a brand new database: