Skip to content

Instantly share code, notes, and snippets.

View javajosh's full-sized avatar

javajosh javajosh

View GitHub Profile
import java.io.*;
import java.util.*;
public class Substrings {
static boolean DEBUG = false;
static Set<String> substrings(String source){
Set<String> substrings = new TreeSet<>();
for (int i = 0; i < source.length(); i++) {
for (int j = i + 1; j <= source.length(); j++) {
import java.util.*;
/**
* Construct a tree like this one:
* <pre>
* 1
* / \
* 2 3
* / \ \
* 4 5 6
** Visualizing Binary Trees in ASCII **
1 Let's try something different. The left child goes to the right.
/ \
2 3 <--- No room for 3.left 1 2 4 7
/ \ \ 3 9
4 5 6 5 <-- The oddness is here because we had to skip a row.
/ \ 6 But there is no ambiguity!
7 8 <--- Width totally determined by leaves! 8
@javajosh
javajosh / logger.java
Created June 23, 2017 00:07
java.util.logger simple example
private final static Logger LOGGER = Logger.getLogger(Main.class.getName());
private static void setupLogger(){
FileHandler fileTxt = null;
try {
fileTxt = new FileHandler("runtime.log");
} catch (IOException ignored) {}
SimpleFormatter formatterTxt = new SimpleFormatter();
fileTxt.setFormatter(formatterTxt);
LOGGER.severe("Severe Log");
LOGGER.addHandler(fileTxt);
create table jemp (a json, b int);
drop table jemp;
select * from jemp;
-- Define a virtual index https://dev.mysql.com/doc/refman/5.7/en/create-table-secondary-indexes.html
create table jemp (a json, b int generated always as (a->'$.a'), index i (b));
insert into jemp (a) values ('{"a":123}');
-- https://dev.mysql.com/doc/refman/5.7/en/json.html MySQL 5.7.8
select JSON_TYPE("1");
select JSON_ARRAY(1, "", NOW());
function makeList(n){
var head = {'i':0};
var prev = head;
var current;
for (var i = 1; i < n; i++) {
current = {'i': i};
prev.next = current;
prev = current;
};
%%%-------------------------------------------------------------------
%%% @author Josh Rehman
%%% @copyright (C) 2017, JavaJosh Enterprises
%%% @doc
%%%
%%% @end
%%% Created : 27. Feb 2017 6:54 PM
%%%-------------------------------------------------------------------
-module(l2).
-author("Josh Rehman").
%%%-------------------------------------------------------------------
%%% @author Josh Rehman
%%% @copyright (C) 2017, JavaJosh Enterprises
%%% @doc
%%%
%%% @end
%%% Created : 27. Feb 2017 5:28 PM
%%%-------------------------------------------------------------------
-module(l).
-author("Josh Rehman").
@javajosh
javajosh / pattern.erl
Created February 27, 2017 04:24
Assignment 1
%%%-------------------------------------------------------------------
%%% @author Josh Rehman
%%% @copyright (C) 2017, JavaJosh Enterprises, Inc.
%%% @doc https://www.futurelearn.com/courses/functional-programming-erlang/1/assignments/161825/submission/new
%%%
%%% @end
%%% Created : 26. Feb 2017 6:02 PM
%%%-------------------------------------------------------------------
-module(pattern).
-author("Josh Rehman").
%%%-------------------------------------------------------------------
%%% @author josh
%%% Created : 25. Feb 2017 10:44 AM
%%%-------------------------------------------------------------------
-module(tail).
-author("josh").
-export([fib/3, fib/1, loop/1, perfect/1, lp/1]).
%Hmm..there seems to be a bug in this one.
fib(N) -> fib(N,0,1).