id
stringlengths
36
36
text
stringlengths
1
1.25M
1e513ef3-c49e-46fd-94ed-96f6e7437c78
@Override public String getCommandName() { return "servers"; }
fe777405-6685-479b-b27a-7e5e2c7af074
@Override public void exec(String channel, String sender, String commandName, String[] args, String login, String hostname, String message) { try { SourceServer tf4 = new SourceServer("tf4.joe.to"); tf4.initialize(); System.out.println(tf4.getServerInfo()); this.bot.sendMessage(channel, "[TF4] Map: " + tf4.getServerInfo().get("mapName") + " Players: " + tf4.getServerInfo().get("numberOfPlayers") + " / " + tf4.getServerInfo().get("maxPlayers")); } catch (TimeoutException e) { this.bot.sendMessage(channel, "[TF4] Error: Timed out."); e.printStackTrace(); } catch (SteamCondenserException e) { this.bot.sendMessage(channel, "[TF4] Error: I don't even know what went wrong."); e.printStackTrace(); } try { SourceServer tf5 = new SourceServer("tf5.joe.to"); tf5.initialize(); System.out.println(tf5.getServerInfo()); this.bot.sendMessage(channel, "[TF5] Map: " + tf5.getServerInfo().get("mapName") + " Players: " + tf5.getServerInfo().get("numberOfPlayers") + " / " + tf5.getServerInfo().get("maxPlayers")); } catch (TimeoutException e) { this.bot.sendMessage(channel, "[TF5] Error: Timed out."); e.printStackTrace(); } catch (SteamCondenserException e) { this.bot.sendMessage(channel, "[TF5] Error: I don't even know what went wrong."); e.printStackTrace(); } }
df31bd16-8c33-4605-94b9-fcfc4823d8a2
public NoteCommand(Meowzy bot) { this.bot = bot; }
62529589-f461-4ba4-a3ef-607fa07334b0
@Override public String getCommandName() { return "note"; }
efbae7fc-79a1-4226-b378-867505230d72
@Override public void exec(String channel, String sender, String commandName, String[] args, String login, String hostname, String message) { if(this.bot.isInChannel(channel, args[0])) { this.bot.sendMessage(channel, "There's a proper bot in the channel, use them instead!"); return; } bot.sql.addNote(channel, sender, message); }
55cfec0b-b97a-46ba-aeff-1a440a46305f
public EulerTest() { tol = 0.0001; }
c86e0976-e827-4bc6-8539-284fd0df56ad
@BeforeClass public static void setUpClass() { }
99951b44-5460-41db-9401-56f60734daa4
@AfterClass public static void tearDownClass() { }
52a7611e-66ea-4d4e-87eb-efdd33a6dc50
@Before public void setUp() { }
806a42de-5f33-4083-8145-3d7803e37991
@After public void tearDown() { }
f6d6327a-dfd6-45df-a953-518d7ade8b8f
@Test public void solveTest() { Euler e = new Euler(); double[][] expResult = { {0,1}, {0.5,5.25}, {1,5.875}, {1.5,5.125} }; DifferentialEquation f1 = new F1(); double[] initialCondition = {0,1}; double lastX = 1.5; double step = 0.5; double[][] result =e.solve( f1, initialCondition,lastX,step); assertArrayEquals(expResult, result); }
eb7a0b4b-bfc0-431d-96cb-9b7c369c7044
@Test public void solveODETest(){ Euler e = new Euler(); double[][] expResult ={ {0,4,6}, {0.5,3,6.9}, {1,2.25,7.715}, {1.5,1.6875,8.44525} }; DifferentialEquation y1 = new Y1(); DifferentialEquation y2 = new Y2(); ODESystem sis = new ODESystem(y1,y2); double[] initialCondition = {0,4,6}; double lastX = 1.5; double step = 0.5; double[][] result = e.solveOde(sis,initialCondition, lastX, step); // assertArrayEquals(expResult, result ); for( int i = 0; i < result.length; i++){ double[] res = result[i]; double[] expres = expResult[i]; double x = res[0]; double yr1 = res[1]; double yr2 = res[2]; double expx = expres[0]; double expy1 = expres[1]; double expy2 = expres[2]; assertEquals(expx, x,tol); assertEquals(expy1, yr1,tol); assertEquals(expy2, yr2,tol); } }
b96e2d34-1ddf-43d0-9d1e-53488b81b68f
public DifferentialEquationTest() { tol = 0.0001; }
75b99aa7-5331-4459-ad90-1273d31ba5e3
@BeforeClass public static void setUpClass() { }
20202a03-eb2f-4c90-8d22-0e6e5918e102
@AfterClass public static void tearDownClass() { }
a4c8625b-6c0c-44d6-a94b-0f792f55bc1e
@Before public void setUp() { }
6a1df859-585c-40da-9365-3657262ed4b6
@After public void tearDown() { }
8e06032d-8f48-4027-b28f-1d6e0f4669ac
@Test public void dydxTest(){ DifferentialEquation f1 = new F1(); double expResult = 8.5; double result = f1.dydx(0,1); assertEquals(expResult, result, tol); }
f7a1cd21-1b76-4496-869b-873c7dde71b5
public RungeKutta4Test() { tol = 0.001; }
4930d812-82c1-43fe-b31b-4a60fe35b305
@BeforeClass public static void setUpClass() { }
79b66b40-4fcc-4b83-9297-bfce3dfc2ccb
@AfterClass public static void tearDownClass() { }
05a3d247-077a-4059-bc24-567ad6045160
@Before public void setUp() { }
7657a823-e13f-414e-a6ff-a4f9f27618a5
@After public void tearDown() { }
17a6f90c-7584-48de-a00c-7106f979bb05
@Test public void testSolve() { System.out.println("solve"); DifferentialEquation diferentialEquation = new Fcubica(); double[] initialCondition = {0,1}; double lastX = 0.5; double step = 0.5; RungeKutta4 instance = new RungeKutta4(); double[][] expResult = { {0,1}, {0.5,3.21875} }; double[][] result = instance.solve(diferentialEquation, initialCondition, lastX, step); assertArrayEquals(expResult, result); }
164a2885-769c-495c-adce-aad2b73c0c10
@Test public void testSolveOde() { System.out.println("solveOde"); Y1 f1 = new Y1(); Y2 f2 = new Y2(); ODESystem sis = new ODESystem(f1,f2); double[] initialCondition = {0,4,6}; double lastX = 2.0; double step = 0.5; RungeKutta4 instance = new RungeKutta4(); double[][] expResult = { {0,4,6}, {0.5,3.115234,6.857670}, {1.0,2.426171,7.632106}, {1.5,1.889523,8.326886}, {2.0,1.471577,8.9466865} }; double[][] result = instance.solveOde(sis, initialCondition, lastX, step); // assertArrayEquals(expResult, result); for( int i = 0; i < result.length; i++){ double[] res = result[i]; double[] expres = expResult[i]; double x = res[0]; double yr1 = res[1]; double yr2 = res[2]; double expx = expres[0]; double expy1 = expres[1]; double expy2 = expres[2]; assertEquals(expx, x,tol); assertEquals(expy1, yr1,tol); assertEquals(expy2, yr2,tol); } }
bfd12123-48db-4230-982e-3609d79f3aef
@Override public double dydx(double x, double... y) { return 4 - 0.3 * y[1] - 0.1 * y[0]; }
a24542c1-a5b5-4cf4-aaf0-59fa54982564
public ODESystem(DifferentialEquation... odes){ ode.addAll(Arrays.asList(odes)); }
70b5f624-999f-4aa7-b2f3-9d18735ce0f7
public DifferentialEquation getDifferentialEquation(int index){ return ode.get(index); }
763b8991-c7b6-4642-ad50-335235696f55
public int getNumberOfDifferentialEquations(){ return ode.size(); }
868ef5f1-37ca-40b8-a729-8067bebce931
public void addODE(DifferentialEquation eq){ ode.add(eq); }
60653bb6-1633-47f2-9ae6-b602f0dc8d41
@Override public double dydx(double x,double... y) { return -2 * Math.pow(x,3) + 12 * Math.pow(x,2) - 20 * x + 8.5; }
569b6236-fb63-4e5b-aeb6-e92351a8811d
public double dydx(double x, double... y) ;
1418ed74-6556-46c7-ab94-4ced2881b211
@Override public double dydx(double x, double... y) { return -0.5 * y[0]; }
0f044eab-15ca-40be-a0f6-9e1f98a859bc
@Override public double dydx(double x, double... y) { return -2 * Math.pow(x,3) + 12 *Math.pow(x,2) - 20 * x + 8.5; }
f08fd127-e481-4987-ba98-09eb4c0a8cbc
public double[][] solve(DifferentialEquation diferentialEquation, double[] initialCondition, double lastX, double step ) { double x = initialCondition[0]; double y = initialCondition[1]; int n = (int) ((lastX - x)/ step) +1; double[][] result = new double[n][2]; result[0] = initialCondition; for(int i = 1; i < n; i++){ double k1 =diferentialEquation.dydx(x, y); double k2 = diferentialEquation.dydx(x + step / 2,y + k1 * step /2); double k3 = diferentialEquation.dydx(x+ step / 2, y + k2 * step /2); double k4 = diferentialEquation.dydx(x + step, k3 * step); double m = (1d/6d) * (k1 + 2 * k2 + 2 * k3 + k4); y = y + m* step; x = i * step; double[] e = {x,y}; result[i] = e; } return result; }
bdc57d0e-2cd4-458f-a687-e1ef0f0ba5a9
public double[][] solveOde(ODESystem sis, double[] initialCondition, double lastX, double step) { double x = initialCondition[0]; int numberOfDependentVar = sis.getNumberOfDifferentialEquations(); double[] y = new double[numberOfDependentVar]; for(int i = 0 ; i < numberOfDependentVar; i++){ y[i] = initialCondition[i+1]; } int n = (int) ((lastX - x)/ step) +1; double[][] result = new double[n][y.length + 1]; result[0] = initialCondition; for(int i = 1 ; i < n; i++){ //k1 double[]k1 = new double[y.length]; for ( int j = 0; j < y.length; j++){ k1[j] =sis.getDifferentialEquation(j).dydx(x, y); } double[] yfork2 = new double[y.length]; for(int j = 0; j < y.length; j++){ yfork2[j] = y[j] + k1[j]* step / 2d; } double xfork2 = x +step /2d; //k2 double[] k2 = new double[y.length]; for(int j = 0; j<y.length; j++){ k2[j] = sis.getDifferentialEquation(j).dydx(xfork2, yfork2); } double[] yfork3 = new double[y.length]; for(int j = 0; j < y.length; j++){ yfork3[j] = y[j] + k2[j]* step / 2d; } double xfork3 = x +step/2d; //k3 double[] k3 = new double[y.length]; for(int j = 0; j<y.length; j++){ k3[j] = sis.getDifferentialEquation(j).dydx(xfork3, yfork3); } double[] yfork4 = new double[y.length]; for(int j = 0; j < y.length; j++){ yfork4[j] = y[j] + k3[j]* step; } double xfork4 = x +step; //k4 double[] k4 = new double[y.length]; for(int j = 0; j<y.length; j++){ k4[j] = sis.getDifferentialEquation(j).dydx(xfork4, yfork4); } double[] newY = new double[y.length]; for(int j = 0; j < y.length; j++){ double m = (1d/6d) * (k1[j] + 2 * k2[j] + 2 * k3[j] + k4[j]); newY[j] = y[j] + m* step; } y = newY; x = i * step; double[] a = new double[y.length + 1]; a[0] = x; System.arraycopy(y, 0, a, 1, y.length); result[i] = a; } return result; }
2c47e49c-6cb2-4aee-8ff1-9050b7326700
public double[][] solve(DifferentialEquation diferentialEquation, double[] initialCondition, double lastX, double step ) { double x = initialCondition[0]; double y = initialCondition[1]; int n = (int) ((lastX - x)/ step) +1; double[][] result = new double[n][2]; result[0] = initialCondition; for(int i = 1; i < n; i++){ y = y + diferentialEquation.dydx(x, y) * step; x = i * step; double[] e = {x,y}; result[i] = e; } return result; }
8cfc4fcf-1ca3-425d-a84a-475dd62a19ab
public double[][] solveOde(ODESystem sis, double[] initialCondition, double lastX, double step) { double x = initialCondition[0]; int numberOfDependentVar = sis.getNumberOfDifferentialEquations(); double[] y = new double[numberOfDependentVar]; for(int i = 0 ; i < numberOfDependentVar; i++){ y[i] = initialCondition[i+1]; } int n = (int) ((lastX - x)/ step) +1; double[][] result = new double[n][y.length + 1]; result[0] = initialCondition; for(int i = 1 ; i < n; i++){ double[] newY = new double[y.length]; for ( int j = 0; j < y.length; j++){ newY[j] = y[j] + sis.getDifferentialEquation(j).dydx(x, y) * step; } y = newY; x = i * step; double[] a = new double[y.length + 1]; a[0] = x; System.arraycopy(y, 0, a, 1, y.length); result[i] = a; } return result; }
50febb1b-3242-43b3-8bc9-9a115cae725b
public Person(String name) { this.name = name; }
78e1abeb-75c2-4835-a5bb-60bfa2b519bb
protected Person() { }
b8dd54a3-bccc-461c-8862-ea1cf0a85ecc
public Long getId() { return id; }
d285d5ea-64ee-45e1-8441-317a6a95fded
public String getName() { return name; }
0d2db31e-4535-4648-a82b-7db32ba43c3a
@Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((id == null) ? 0 : id.hashCode()); return result; }
42070d9a-22a3-4e6e-bf09-fcbf6de671c6
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; Person other = (Person) obj; if (id == null) { if (other.id != null) return false; } else if (!id.equals(other.id)) return false; return true; }
3564b586-c3bf-4234-91cc-71ced352e98f
@Override public String toString() { return "Person [id=" + id + ", name=" + name + "]"; }
f634f2db-2353-412a-ba22-89399b381044
protected Team() { }
d790d43a-3926-4b19-aaed-0f9320cb7577
public Team(Long id) { this.id = id; }
379e88c8-edac-43aa-92aa-8fb95ed5af37
public Team(Long id, String name, List<Person> people) { this.id = id; this.name = name; this.people = people; }
2829771e-cb6a-4487-83a2-ffcd91279dcc
public Long getId() { return id; }
ef6f2558-82a9-45d2-9860-7d3ebccb047c
public String getName() { return name; }
21a2a826-7c61-490f-b4df-bb2ab4b86daa
public List<Person> getPeople() { return people; }
444b8d02-5aba-47c2-a0a9-7b1ec28f3557
public TeamDAO() { }
671d0adb-65c3-4c24-8f09-b9c5ca127b6f
@Autowired public TeamDAO(SessionFactory factory) { this.factory = factory; }
c578aea0-7dc4-49e1-a444-8e985d50d407
public Team load(Long id) { return (Team) getSession().load(Team.class, id); }
767862e1-84d6-4b12-b493-bf4770a53988
public void delete(Team team) { getSession().delete(team); }
86ba4eae-06bb-4ab9-bbfb-d6f87ad2b51d
public Session getSession() { return factory.getCurrentSession(); }
3db67f42-22ab-489e-a854-4680a7f23df3
public void save(Team team) { getSession().save(team); }
fa8ec963-6ef6-4e80-bb96-dc6e4ed24d0a
public void clear() { getSession().flush(); getSession().clear(); }
30cabc6d-82b0-48b1-af14-f213a75d4a1e
public PersonDAO(){}
e4850f5c-71f5-4a23-9c9b-99600a89a172
@Autowired public PersonDAO(SessionFactory factory) { this.factory = factory; }
1ac1cc26-b9a0-4d63-9d84-72732fb83b5a
@SuppressWarnings("unchecked") public List<Person> list() { return getSession().createCriteria(Person.class).list(); }
3668d5ef-1ea7-4435-9690-0b6cc1498277
public Session getSession() { return factory.getCurrentSession(); }
467f7e6f-d960-4bb3-ad7f-7250879763fb
@Test public void shouldRemovedAllEntityWithObjectDetached() { teamDAO.delete(new Team(1L)); assertTrue("Should Removed all people from detached object", personDAO.list().isEmpty()); }
5fdcbd7c-a0b1-4e12-a1d3-3f310b633a27
@Test public void shouldRemoveAllEntityWithObjectManaged() { teamDAO.delete(teamDAO.load(1L)); assertTrue("Should Removed all people from managed object", personDAO.list().isEmpty()); }
a39bcfac-9f84-434b-9eab-d9a462993103
@Before public void setUp() { teamDAO.save(new Team(1L, "Team", Arrays.asList(new Person("Person One"), new Person("Person Two")))); teamDAO.clear(); }
6bdadb9f-7c1a-470e-8b7a-f2387e1f47e5
public WorkerRunnable(CrawlerContext context) { this.context = context; }
65ab3680-656b-4f80-83d4-9c93bbe85ce4
public void run() { while(!context.shouldStop()) { CrawlerTask task = context.getTask(); if(task == null) { continue; } while(true) { try { task.execute(context); break; } catch (IOException e) { } } context.finishTask(task); } }
a63a6a76-bff5-4bd4-a8a0-365b6e074cef
public ProcessPlayer(String url) { this.url = url; }
5ff562fc-e391-4709-a1b2-0ad1078194b0
public void execute(CrawlerContext crawlerContext) throws IOException { Document doc = Jsoup.connect(url).get(); Element nameElement = doc.select("#tombstone h1 *").first(); String playerName = fixString(nameElement.ownText()); crawlerContext.addPlayerName(playerName); }
fb1f99d5-4c32-4049-a3dc-be4481977d34
private static String fixString(String s) { return s.replace(String.valueOf((char)160), " ").trim(); }
50ccc632-8caf-4a6e-abab-67523783d48f
public ProcessLetter(String url, boolean processPagination) { this.url = url; this.processPagination = processPagination; }
ae651f1e-6f50-425a-86ff-ce7a81fad834
public void execute(CrawlerContext crawlerContext) throws IOException { Document doc = Jsoup.connect(url).get(); Elements elements = doc.select("table.data > tbody > tr a[href*=player]"); for(Element e : elements) { crawlerContext.submitTask(new ProcessPlayer(e.attr("abs:href"))); } if(!processPagination) { return; } elements = doc.select(".pageNumbers > a"); Set<String> urls = new HashSet<String>(); for(Element e : elements) { urls.add(e.attr("abs:href")); } for(String url : urls) { crawlerContext.submitTask(new ProcessLetter(url, false)); } }
a28bb264-3eba-4b5b-91dc-ec7c52bcfd7f
public void submitTask(CrawlerTask task) { synchronized(this) { tasks.add(task); } }
a9b9eb06-0df8-45e2-af32-2b8b04f59e6b
public CrawlerTask getTask() { synchronized(this) { CrawlerTask task = tasks.poll(); if(task == null) { return null; } pendingTasks.add(task); return task; } }
46d20f01-ecb6-4d2f-ad0b-1ea15295b67e
public void finishTask(CrawlerTask task) { synchronized(this) { pendingTasks.remove(task); } }
79ec8be5-da01-4f6b-803c-aa252100eca2
public boolean shouldStop() { synchronized(this) { return tasks.isEmpty() && pendingTasks.isEmpty(); } }
4ab589bc-1741-4208-9412-48ef1e0a1ba9
public void addPlayerName(String playerName) { synchronized(players) { players.add(playerName); System.out.printf( "Got player '%s' [%d]\n", playerName, players.size()); } }
36a51d26-8ea4-4093-9fac-c55f3f237e68
public ProcessAbc(String url) { this.url = url; }
19a2a2ba-068e-4204-8b2c-cbe474577cc7
public void execute(CrawlerContext crawlerContext) throws IOException { Document doc = Jsoup.connect(url).get(); Elements elements = doc.select("#playerSearch > .lastInitial > a"); for(Element e : elements) { crawlerContext.submitTask(new ProcessLetter(e.attr("abs:href"), true)); } }
3aa9da99-f690-4955-b17d-d3242f78bed0
public static void main(String[] args) throws IOException, InterruptedException { CrawlerContext context = new CrawlerContext(); context.submitTask(new ProcessAbc("http://www.nhl.com/ice/playersearch.htm")); long startTime = System.currentTimeMillis(); int numberOfThreads = 80; List<Thread> workerThreads = new ArrayList<Thread>(); for(int i = 0; i < numberOfThreads; ++i) { Thread thread = new Thread(new WorkerRunnable(context)); thread.start(); workerThreads.add(thread); } for(Thread thread : workerThreads) { thread.join(); } long duration = System.currentTimeMillis() - startTime; System.out.printf("Finished in %d seconds\n", duration / 1000); }
eef21b5f-633b-4f3c-9bef-8d9251773867
void execute(CrawlerContext crawlerContext) throws IOException;
20d53a47-b720-4bdc-8ea1-679a46cc4a68
public AppTest( String testName ) { super( testName ); }
5142b154-3e7d-4ebd-b6e7-9a96cd72b4e4
public static Test suite() { return new TestSuite( AppTest.class ); }
b40ea41c-9da5-4ab1-a693-53d395578168
public void testApp() { assertTrue( true ); }
51be87a4-0849-4327-9eaf-88a222c3fc81
public void afterJob(JobExecution jobExecution) { if (jobExecution.getStatus() == BatchStatus.COMPLETED) { logger.info("Job completed: " + jobExecution.getJobId()); } else if (jobExecution.getStatus() == BatchStatus.FAILED) { logger.info("Job failed: " + jobExecution.getJobId()); } }
e21b5480-ee6e-455b-866a-29919a33a626
public void beforeJob(JobExecution jobExecution) { if (jobExecution.getStatus() == BatchStatus.COMPLETED) { logger.info("Job completed: " + jobExecution.getJobId()); } else if (jobExecution.getStatus() == BatchStatus.FAILED) { logger.info("Job failed: " + jobExecution.getJobId()); } }
ee751318-48de-4d97-91ce-c6a0370d187b
public void onReadError(Exception ex) { logger.error("Encountered error on read", ex); }
44947113-6171-410f-9c67-cc679725be2c
public void onWriteError(Exception ex, Object item) { logger.error("Encountered error on write", ex); }
5982d6b3-e305-4543-8331-54a678250acd
public void setTaskStartMessage(String taskStartMessage) { this.taskStartMessage = taskStartMessage; }
366aba7e-71a2-42d4-ad8c-afc3b5f3188e
public RepeatStatus execute(StepContribution arg0, ChunkContext arg1) throws Exception { System.out.println(taskStartMessage); return RepeatStatus.FINISHED; }
fca1dc7b-be51-4cb4-9d03-9cb95e00baa4
public RepeatStatus execute(StepContribution arg0, ChunkContext arg1) throws Exception { System.out.println(Calendar.getInstance().getTime()); return RepeatStatus.FINISHED; }
49a7c3e9-5835-4ad2-811a-2a1b6fc58b34
public void write(List items) throws Exception { for (Iterator<Ledger> iterator = items.iterator(); iterator.hasNext();) { Ledger item = iterator.next(); itemDAO.save(item); } }
dc08c3f3-b641-45ad-ad53-295343bbc4a3
public int getId() { return id; }
34c22bb3-0069-4814-992f-b52ce331818c
public void setId(int id) { this.id = id; }
624c13c9-ca3f-4682-afb8-91d41f0f88b5
public Date getReceiptDate() { return receiptDate; }
bc74d763-0278-4b86-8dcd-86d7c3cbc869
public void setReceiptDate(Date receiptDate) { this.receiptDate = receiptDate; }
c65ce3f7-5f01-4b1a-8035-782ab126f138
public String getMemberName() { return memberName; }
427e67e7-6e08-4237-975e-81ba1d6959ab
public void setMemberName(String memberName) { this.memberName = memberName; }
b1873006-022f-4481-986f-aa0e4f43ef5c
public String getCheckNumber() { return checkNumber; }
edfb0711-9843-4855-a72d-66fd4f5544c5
public void setCheckNumber(String checkNumber) { this.checkNumber = checkNumber; }