Skip to content

Instantly share code, notes, and snippets.

@dhoss
dhoss / BaseService.java
Last active May 16, 2016 18:54
dao base class
public abstract class BaseService {
protected void create(GenericTablePojo tableObject) {
GenericRecord g = buildRecordObject(tableObject);
g.store();
}
protected void update(GenericTablePojo tableObject) {
GenericRecord g = buildGenericRecord(tableObject);
g.store();
@dhoss
dhoss / Main.java
Last active November 24, 2015 21:07
foo.bar
import java.util.*;
class Main {
public static void main(String[] args) {
int[] nums1 = new int[] {
1, 2, 1
};
int[] nums2 = new int[] {
1, 0
};
@dhoss
dhoss / commit.html.erb
Last active October 5, 2015 21:06
sequel models
<div class="table-responsive">
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>Commit ID</th>
<th>Message</th>
<th>Author</th>
<th>Commit Timestamp</th>
</tr>
</thead>
play.api.http.HttpErrorHandlerExceptions$$anon$1: Execution exception[[BatchUpdateException: Batch entry 606 insert into "commit" ("git_id","message","author","email","author_timestamp","repository","created_at","updated_at") values ('32f824a6767071eb6991eec3bfc591eddda6a2f2','logback config','d***','D***','2015-02-23 14:34:08.000000 -07:00:00','dna****','2015-09-17 14:54:03.978000 -06:00:00','2015-09-17 14:54:03.978000 -06:00:00') was aborted. Call getNextException to see the cause.]]
with table_stats as (
select psut.relname,
psut.n_live_tup,
1.0 * psut.idx_scan / greatest(1, psut.seq_scan + psut.idx_scan) as index_use_ratio
from pg_stat_user_tables psut
order by psut.n_live_tup desc
),
table_io as (
select psiut.relname,
sum(psiut.heap_blks_read) as table_page_read,
@dhoss
dhoss / DAL.scala
Created August 26, 2015 19:41
returning Object?
def commitsFor(project: String, page: Option[Int] = None, limit: Option[Int] = None) = { //: Future[List[scala.collection.immutable.Map[String, List[Commit]]]] = {
// grab repos for a project name. need to make this async.
// need to return project from API if no projects exist, then queue up a db population
// need to account for nonexistent projects as well
Logger.info("DAL commitsFor " + project)
// make me non-blocking
val projectId = Await.result(db.run(Projects.filter(_.name === project).map(_.id).result), 2 seconds).headOption
val repoQuery = Repositories.filter(_.project === projectId).map(_.name)
@dhoss
dhoss / DALSpec.scala
Created August 25, 2015 19:30
reducing with... stuff
"retrieve the correct page when specified" in new WithApplication
with RepositoryTable
with CommitTable
with ProjectTable
with WithDatabaseConfig
with DBCleanup
with DBFixtures {
import driver.api._
//create an instance of the table
val Projects = TableQuery[Projects]
def crawlProjectRepos(project: String) = {
Logger.info("crawling " + project + " by API")
// a list of Futures containing a Tuple2 of a repository name and a Future[WSResponse]
val repoList = reposFor(project).map { repo =>
(repo, callApi(buildCommitUrl(project, repo)))
}
Logger.debug("REPOS FOR" + reposFor(project))
Future.traverse(repoList) (
repoCommits =>
@dhoss
dhoss / Client.scala
Created August 5, 2015 17:30
got: scala.concurrent.Future[List[List[models.Commit]]] want: scala.concurrent.Future[List[models.Commit]]
def crawlProjectRepos(project: String) = {
Logger.info("crawling " + project + " by API")
// a list of Futures containing a Tuple2 of a repository name and a Future[WSResponse]
val repoList = reposFor(project).map { repo =>
(repo, callApi(buildCommitUrl(project, repo)))
}
Future.traverse(repoList) (
repoCommits =>
repoCommits._2.filter(_.status==200).map { res =>
@dhoss
dhoss / Client.scala
Last active August 29, 2015 14:26
need to retain the repository name as well as the WSResponse
case class RepositoryCommitResponse(repository: String, response: Future[WSResponse])
val repos = reposFor(project) // just a list of strings: List("repo1", "repo2", "repo3")
val futureRepoList = repos.map { repo => Future{RepositoryCommitResponse(repo, callApi(buildCommitUrl(project, repo)))} }
Logger.info("FUTURE REPO LIST " + futureRepoList)
val goodRepos = Future.sequence(futureRepoList) map { fr =>
fr.map(_.response.filter(_.status==200))
}
for ( r <- goodRepos ) {
for (rr <- r) {