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
public class SpiralMatrix { | |
public static void spiralPrint( int[][] matrix ) { | |
int height = matrix.length; | |
int width = matrix[0].length; | |
int currCol = 0; | |
int currRow = 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
(ns prime) | |
;; (coll, n) -> coll' | |
(defn- prime-check [coll n] | |
(empty? (filter #(zero? (mod n %)) coll))) | |
(defn is-prime? [n] | |
(loop [prime-list [] value 2] | |
(cond | |
;; Have the list, check for prime |
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 hn.realtime | |
(:require [cheshire.core :refer :all])) | |
(def base-url "https://hacker-news.firebaseio.com/v0") | |
(defn get-updates | |
"Return response regardless of condition" | |
[] (parse-string (slurp (str base-url "/updates.json")) true)) | |
(defprotocol IPoller |
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
package id3 | |
/** | |
* Created by: film42 on: 3/6/15. | |
*/ | |
object DecisionTreeUtils { | |
type Vector[A] = List[A] | |
type Matrix[A] = List[Vector[A]] |
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
require 'thread' | |
## | |
## THREADING EXAMPLE | |
## | |
## Ruby's array append is not "thread safe." This means that real | |
## concurrency models will have collision issues. This is not a good | |
## thing, but we'll find we can use real threading constructs to | |
## protect code that isn't "thread safe." Run this code on MRI and | |
## then try running this in jRuby and compare the results. |
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
$ film42@mbp ~/D/D/S/C/t/a/build (master)> | |
valgrind --leak-check=full --dsymutil=yes ./avl_tree_tests | |
==65466== Memcheck, a memory error detector | |
==65466== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al. | |
==65466== Using Valgrind-3.11.0.SVN and LibVEX; rerun with -h for copyright info | |
==65466== Command: ./avl_tree_tests | |
==65466== | |
--65466-- run: /usr/bin/dsymutil "./avl_tree_tests" | |
Running test: Contains Tests | |
Malloc'd tree |
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
-module(erlish). | |
-export([init/0, manager/1, get/1, set/2, keys/0, del/1, expire/2]). | |
manager(State) -> | |
receive | |
{get, Key, Sender} -> | |
Value = case maps:is_key(Key, State) of | |
true -> | |
maps:get(Key, State); | |
_ -> |
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
class BashQueue | |
FIFO_QUEUE = '/tmp/channel' | |
# Setup fifo queue called channel | |
def self.ensure_setup! | |
unless ::File.exist?(FIFO_QUEUE) | |
`mkfifo #{FIFO_QUEUE}` | |
end | |
end |
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
Thread.new do | |
trap(:TRAP) do | |
::Thread.list.each do |thread| | |
puts <<-THREAD_TRACE | |
#{thread.inspect}: | |
#{thread.backtrace.try(:join, $INPUT_RECORD_SEPARATOR)}" | |
THREAD_TRACE | |
end | |
end | |
end |
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
class EnumDeliveryType < ::Protobuf::Enum | |
define :STANDARD, 1 | |
define :PRIORITY, 2 | |
define :NEXT_DAY, 3 | |
define :OVERNIGHT, 4 | |
end | |
# # # # # # # # # # # # # PART 1 # # # # # # # # # # # # # | |
## |