Skip to content

Instantly share code, notes, and snippets.

View jamesmcm's full-sized avatar

James McMurray jamesmcm

View GitHub Profile
@jamesmcm
jamesmcm / binary_tree_bfs.rs
Created January 14, 2020 21:33
binary_tree_bfs.rs
// Definition for a binary tree node.
#[derive(Debug, PartialEq, Eq)]
pub struct TreeNode {
pub val: i32,
pub left: Option<Rc<RefCell<TreeNode>>>,
pub right: Option<Rc<RefCell<TreeNode>>>,
}
impl TreeNode {
#[inline]
@jamesmcm
jamesmcm / move_child.rs
Created December 6, 2019 00:41
move_child.rs
struct Node {
value: Symbol,
children: (Option<Box<Node>>, Option<Box<Node>>),
}
let movechild = ((&root).as_ref().unwrap().children).1;
(&mut root).as_mut().unwrap().children.1 = Some(Box::new(Node::new(symbol, (movechild, None))));
@jamesmcm
jamesmcm / split_with_matches_broken.rs
Created December 5, 2019 20:55
split_with_matches_broken.rs
fn split_with_matches<F>(s: &str, f: F) -> Vec<&str> where
F: Fn(char) -> bool {
let mut out: Vec<&str> = vec![];
let mut curstring: String = String::new();
for c in s.chars() {
if f(c) {
out.push(&curstring);
out.push(&c.to_string());
} else {
curstring.push(c);
@jamesmcm
jamesmcm / abstract_type.scala
Created November 15, 2019 21:31
abstract_type.scala
abstract class SpaceObject() {
type T <: SpaceObject
def ===(that: T): Boolean
}
class Sphere(val transform: Matrix, val material: Material) extends SpaceObject {
type T = Sphere
@jamesmcm
jamesmcm / scalaq.scala
Created October 12, 2019 17:54
scalaq.scala
def encodePair(pair: (Char, Char)): (Char, Char) = {
(findLetterInSquare(pair._1), findLetterInSquare(pair._2)) match {
case ((A, B), (A, D)) => (indexToLetter((A, (B+1)%5)), indexToLetter((A, (D+1)%5))) // same row
case ((A, B), (C, B)) => (indexToLetter(((A + 1)%5, B)), indexToLetter(((C+1)%5, B))) // same column
case ((A, B), (C, D)) => (indexToLetter((A, D)),indexToLetter((C, B)))
}
}
@jamesmcm
jamesmcm / sum_matrices.scala
Created October 8, 2019 19:50
sum_matrices.scala
def sum_vector(x: Array[Int], y: Array[Int]): Array[Int] = {
(x zip y).map((a: (Int, Int)) => a._1 + a._2)
}
def sum_matrix(x: Array[Array[Int]], y: Array[Array[Int]]): Array[Array[Int]] = {
(x zip y).map((a: (Array[Int], Array[Int])) => sum_vector(a._1, a._2))
}
@jamesmcm
jamesmcm / manhole2.log
Created March 19, 2018 07:25
manhole2.log
jenkins@ip-172-31-13-221:/home/james$ netcat -U /tmp/manhole-19489
######### ProcessID=19489, ThreadID=139875607566080 #########
File: "/usr/lib/python3.6/threading.py", line 884, in _bootstrap
self._bootstrap_inner()
File: "/usr/lib/python3.6/threading.py", line 916, in _bootstrap_inner
self.run()
File: "/home/jenkins/datawarehouse/env/lib/python3.6/site-packages/manhole/__init__.py", line 234, in run
self.connection_handler(self.client)
File: "/home/jenkins/datawarehouse/env/lib/python3.6/site-packages/manhole/__init__.py", line 302, in handle_connection_repl
postgres_1 | ERROR: relation "organizations" does not exist at character 293
postgres_1 | STATEMENT: SELECT organizations.updated_at AS organizations_updated_at, organizations.created_at AS organizations_created_at, organizations.id AS organizations_id, organizations.name AS organizations_name, organizations.slug AS organizations_slug, organizations.settings AS organizations_settings
postgres_1 | FROM organizations
postgres_1 | WHERE organizations.slug = 'default'
postgres_1 | LIMIT 1
server_1 | [2017-01-26 21:30:43,708] ERROR in app: Exception on /login [GET]
server_1 | Traceback (most recent call last):
server_1 | File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1988, in wsgi_app
server_1 | response = self.full_dispatch_request()
server_1 | File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1641, in full_dispatch_request
[archie@archie redash]$ sudo docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
be4ee11ece36 mariadb "docker-entrypoint.sh" 15 minutes ago Up 15 minutes 0.0.0.0:3306->3306/tcp redash_mysql_1
47dbdab08ecc redis:2.8 "docker-entrypoint.sh" 15 minutes ago Up 15 minutes 6379/tcp redash_redis_1
e13258baa4ef postgres:9.3 "/docker-entrypoint.s" 15 minutes ago Up 15 minutes 5432/tcp redash_postgres_1
redash:
image: redash/redash:latest
ports:
- "5000:5000"
links:
- redis
- postgres
environment:
REDASH_LOG_LEVEL: "INFO"
REDASH_REDIS_URL: "redis://redis:6379/0"