id
stringlengths
36
36
text
stringlengths
1
1.25M
26dbb0f9-e0b0-44a5-b884-2dd8aaef463b
void freeCL() { clReleaseKernel(kernel); clReleaseProgram(program); clReleaseCommandQueue(queue); clReleaseContext(context); CL.destroy(); }
8c8236c6-62d1-4a39-8db5-1a3a212785a4
public static void main(String[] args) throws LWJGLException { Particles instance = new Particles(); instance.start(); System.exit(0); }
f6ac8f74-2bda-4dad-8b5f-487f66d9a3a0
static String create(int nParticles, float mindist) { final String kernelSource = "kernel void " + "adv(global float *x, " + " global float *y, " + " global float *vx," + " global float *vy) { " + " unsigned int xid = get_global_id(0); " + " unsigned int xid2 = (xid + 1) % " + nPa...
75d18763-1df1-4195-881f-61008e02a356
void start() throws Exception { initCL(); runCL(); processResults(); freeCL(); }
9d244885-a20c-4a49-a5e5-eb22f178e75a
String packKernel() { final RanGen ranGen = new RanGen(); final float[][] dom = {{-5.12f, 5.12f},{-5.12f, 5.12f}}; final int nTries = 100; final String function = "x*x + y*y"; final String source = KernelBuilder.create(ranGen,function,dom,nTries); return source; }
614b4d90-e3af-4ebd-9f93-3fe076d86110
void initCL() throws LWJGLException { final String source = packKernel(); //buffers x = BufferUtils.createFloatBuffer(nClimbers); y = BufferUtils.createFloatBuffer(nClimbers); ans = BufferUtils.createFloatBuffer(nClimbers); //cl creation CL.create(); platform = CLPlatform.getPlatforms...
fb8e1941-30c0-47ca-84d9-8821445931da
void runCL() { clEnqueueNDRangeKernel(queue, kernel, 1, null, kernel1DGlobalWorkSize, null, null, null); clEnqueueReadBuffer(queue, xMem, 1, 0, x, null, null); clEnqueueReadBuffer(queue, yMem, 1, 0, y, null, null); clEnqueueReadBuffer(queue, ansMem, 1, 0, ans, null, null); clFinish(queue); }
e5931e2e-ba76-4f35-bd34-ba817df74a21
void freeCL() { clReleaseKernel(kernel); clReleaseProgram(program); clReleaseCommandQueue(queue); clReleaseContext(context); CL.destroy(); }
a3eb536c-55ff-4a38-8ac2-96921b77e969
void processResults() throws Exception { System.out.print("x: "); Buffer.print(x); System.out.print("y: "); Buffer.print(y); System.out.print("f(x,y): "); Buffer.print(ans); ValIndex pv = Buffer.min(ans); System.out.println("Min: ((" + x.get(pv.index) + "," + y.get(pv.index) + "), " + pv.val +")"); ...
f3f78db1-8943-4500-ad72-778b56026fe2
public static void main(String[] args) throws Exception { HillClimber instance = new HillClimber(); instance.start(); System.exit(0); }
a9d8c180-fbb6-4455-ad6b-ec87227ba523
static String create(RanGen ranGen, String function, float[][] dom, int nTries) { String kernelSource = "float f(float x, float y) {" + " return " + function + "; " + "}" + "" + "int ran(int state) { " + " return (state * " + ranGen.a + " + " + ranGen.c + ") % " + ranGen.m + "; " + "} " +...
64210eea-7baa-45ca-a4fc-470b385c3a82
public ProfessorResource() { }
5efa6277-9dad-43a0-bc09-9cac09702ae9
@GET @Produces("application/json") public String getJson() { //TODO return proper representation object throw new UnsupportedOperationException(); }
5d87135e-92ec-40f0-9f8a-0848c99ef729
@PUT @Consumes("application/json") public void putJson(String content) { }
7b91021a-2fea-4e80-a286-28b97fecfc5c
@GET @Produces("application/json") public List<Pergunta> getPergunta() { return pjc.findPerguntaEntities(); }
f87f3004-6f78-43a7-b0f1-5b59b555d4af
@Path("{perguntaid}") @GET @Produces("application/json") public void deletePergunta(@PathParam("perguntaid") int id) { pjc.destroy(id); }
f1b153c4-f7fb-4d22-9616-7e75e003ac8a
@PUT @Produces("application/json") public void updatePergunta(Pergunta pergunta) { pjc.edit(pergunta); }
84d100be-8d0e-4a50-896e-b30f8544985d
@POST @Produces("application/json") public void creatPergunta(Pergunta pergunta) { pjc.create(pergunta); }
72cb8f95-d750-4c9c-939a-f0ba2ba5892a
public Pergunta() { }
2acbd0a0-79ab-4149-9f43-e8310f46f98f
public Pergunta(Integer id) { this.id = id; }
edddcee3-408c-4603-8ac5-c643d5f09aea
public Pergunta(Integer id, String pergunta, double resposta) { this.id = id; this.pergunta = pergunta; this.resposta = resposta; }
22de58b7-f38d-4099-868e-4603b4312f98
public Integer getId() { return id; }
1d2e554d-85a6-4062-a761-a4aa4920f6de
public void setId(Integer id) { this.id = id; }
36c21f24-2c4c-4c0a-a0ad-33fb81b15e15
public String getPergunta() { return pergunta; }
c48bdc94-7520-44ff-8f36-a8eee2a659c7
public void setPergunta(String pergunta) { this.pergunta = pergunta; }
446be0d1-2a91-42eb-8e29-1311d22338f0
public double getResposta() { return resposta; }
0bbddcd1-08c0-481f-8b84-6de7cd8645bd
public void setResposta(double resposta) { this.resposta = resposta; }
cba78027-35c4-4c0c-8689-881eb5c4ad2f
@Override public int hashCode() { int hash = 0; hash += (id != null ? id.hashCode() : 0); return hash; }
6d8fb349-1d20-4269-8aed-85494bf6046a
@Override public boolean equals(Object object) { // TODO: Warning - this method won't work in the case the id fields are not set if (!(object instanceof Pergunta)) { return false; } Pergunta other = (Pergunta) object; return (this.id != null || other.id == null) &...
f491846d-2d5f-48fb-b9f7-99852e2c661b
@Override public String toString() { return "Pergunta{" + "id=" + id + ", pergunta=" + pergunta + ", resposta=" + resposta + '}'; }
0be8fe0c-8349-4750-8e8d-542cc3120612
private ConnectionHelper() { String driver = null; try { Class.forName("com.mysql.jdbc.Driver").newInstance(); url = "jdbc:mysql://localhost/directory?user=root"; userName = "root"; password = "ch4v31r0"; url = "jdbc:mysql://localhost:3306/arro...
bfc565eb-aeac-4a15-992b-ed5e8d6a64fb
public static Connection getConnection() throws SQLException { if (instance == null) { instance = new ConnectionHelper(); } try { return DriverManager.getConnection(instance.url,instance.userName, instance.password); } catch (SQLException e) { throw e;...
2d60fb8d-04fe-4a68-aff7-2791a653dd3f
public static void close(Connection connection) { try { if (connection != null) { connection.close(); } } catch (SQLException e) { e.printStackTrace(); } }
1d305055-fc99-4dd0-9f5b-230086549a75
public List<Pergunta> findAll() { List<Pergunta> list = new ArrayList<>(); Connection c = null; String sql = "SELECT * FROM pergunta"; try { c = ConnectionHelper.getConnection(); Statement s = c.createStatement(); ResultSet rs = s.executeQuery(sql); ...
0ff94781-3c56-4408-8718-f5e50bb419b8
public Pergunta create(Pergunta pergunta) { Connection c = null; PreparedStatement ps = null; try { c = ConnectionHelper.getConnection(); ps = c.prepareStatement("INSERT INTO pergunta (pergunta, assunto, resposta) VALUES (?, ?, ?)", new String[]{"ID"})...
2472fb6a-70f9-43c9-a64b-87e05d70bc36
public Pergunta edit(Pergunta pergunta) { Connection c = null; try { c = ConnectionHelper.getConnection(); PreparedStatement ps = c.prepareStatement("UPDATE pergunta SET pergunta=?, assunto=?, resposta=? WHERE id=?"); ps.setString(1, pergunta.getPergunta()); ...
4f883fe5-7636-4149-94f5-de6468b6a295
public boolean destroy(Integer id) { Connection c = null; try { c = ConnectionHelper.getConnection(); PreparedStatement ps = c.prepareStatement("DELETE FROM pergunta WHERE id=?"); ps.setInt(1, id); int count = ps.executeUpdate(); return count =...
c34f48b3-6f0d-4a16-8f69-7606189076f7
public List<Pergunta> findPerguntaEntities() { return findAll(); }
b7934489-22ed-4e5f-a96e-f2da888a4288
protected Pergunta processRow(ResultSet rs) throws SQLException { Pergunta pergunta = new Pergunta(); pergunta.setId(rs.getInt("ID")); pergunta.setPergunta(rs.getString("PERGUNTA")); pergunta.setResposta(Double.parseDouble(rs.getString("RESPOSTA"))); return pergunta; }
721579b3-906e-4a05-bf2c-b680ce4937ab
CrossingRoute() {}
081f3e45-93cf-4694-9ec8-3132a5f9d1b4
public String getAction() { return action; }
835af4e1-5279-4ae0-834a-c5956a012931
public String getController() { return controller; }
3d019769-4b08-4fd4-abc3-417f08c35fc5
public String getName() { if (controller_class_name != null) return controller_class_name; return controller_class_name = guessControllerName(); }
bb728ed5-917d-4091-9b7c-85fcb559ce52
public IRubyObject getPath_info() { return path_info_pattern; }
d6d7705d-3078-4131-84c5-14f0d0fc169c
public IRubyObject getRequest_method() { return request_method_pattern; }
ce7d78db-14ed-4ab8-9873-75dc5bd49388
private String guessControllerName() { String tmp = controller; String scope_name = getScopeName(); if (scope_name != null) tmp = tmp.substring(scope_name.length() + 1); return getCapitalizedControllerName(tmp); }
e49c628b-aed3-4a71-b716-b5c656f44b5a
private String getScopeName() { // controller | action | name | actual controller and action // Acacia/home | index | home_index | HomeController.action('index') // rails/info | properties | rails_info_properties | Rails::InfoController.action('pro...
61657545-3449-4006-b8e3-9c62544fbe75
private String getCapitalizedControllerName(String s) { StringTokenizer st = new StringTokenizer(s, "/"); StringBuffer sb = new StringBuffer(); while(st.hasMoreTokens()) { if (sb.length() > 0) sb.append("::"); String token = st.nextToken(); token = String.form...
7d280425-b0a2-4dec-bdcb-0c7f80422a38
public IRubyObject getParams() { return params; }
34db0cdf-9da2-447d-8e1b-a391d9d1354c
public CrossingServlet() { super(); }
77ab54c2-9bab-4f7f-8925-2d8cc9021bba
@Override public void init(ServletConfig config) throws ServletException { container = CrossingHelpers.initialize(config); routes = CrossingHelpers.parseRoutes(container); }
1efe6872-1c90-4e83-b5c0-ec437c140dd2
@Override public String getServletInfo() { return "Base Servlet for Rails Crossing"; }
46cce8cc-0384-46c2-af6b-64418675058c
@Override public void destroy() { if (container != null) container.terminate(); }
84a6eb97-c3fe-477e-917f-b842f2605df1
protected Map<String, Object> getEnvMap(HttpServletRequest request) throws IOException { return CrossingHelpers.getEnvMap(request); }
5cc88ffe-5fb1-4e7e-9b58-570d829d63c7
protected CrossingRoute findMatchedRoute(String request_uri, String method) { return CrossingHelpers.findMatchedRoute(container, routes, request_uri, method); }
ab8c849d-b0d1-40a6-ad67-5723b42d5fff
protected void dispatch(HttpServletRequest request, HttpServletResponse response) throws IOException { String method = null; if (request.getParameter("_method") != null) { method = request.getParameter("_method").toUpperCase(); } else { method = request.getMethod().toUppe...
a38f9dbe-8526-4be6-a4c7-756f102b64c5
protected CrossingResponse dispatch(HttpServletRequest request) throws IOException { CrossingRoute route = findMatchedRoute(request.getRequestURI(), request.getMethod()); Map<String, Object> env = getEnvMap(request); return CrossingHelpers.dispatch(container, request.getContextPath(), route, env...
eb94f725-6ba2-4740-8e3b-32d72d50e3ce
CrossingResponse() {}
02fa2c68-e113-4c1f-9803-2556e1cee8c6
public String getBody() { return addContextPath(); }
78141ea5-6b6c-4a10-9018-a5829d68545d
public Map getFlash() { return flash; }
ed7aa46b-609a-4148-bec4-2f8b9ec8a349
public Map<String, String> getResponseHeader() { return responseHeader; }
cc5ec0e5-3c7f-45cf-8ded-e3b4cc21b0b7
public int getStatus() { return status; }
be96f12f-b4dc-4d02-9478-f50eee79579d
private String addContextPath() { Matcher matcher = pattern.matcher(body); boolean result = matcher.find(); StringBuffer sb = new StringBuffer(); while(result) { String matched = matcher.group(); String replacement = ""; if (matched.contains("/styleshe...
13cdba48-3bba-4e97-8bce-c0c52b08aa11
@Override public void init(ServletConfig config) { String rails_path = config.getInitParameter("rails_path"); asset_dir_name = config.getServletContext().getRealPath("/WEB-INF/" + rails_path) + "/public"; }
ccccfa71-ae9a-4293-a184-f498cd4744b6
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String file_name = getRealPathToFile(request); response.setContentType(getContentTypeFromFilename(file_name)); PrintWriter out = response.getWriter(); ...
fb9c26fb-8f56-4621-91f3-af6ed8ef276c
private String getContentTypeFromFilename(String file_name) { String extension = file_name.substring(file_name.lastIndexOf(".") + 1).toLowerCase(); if ("html".equals(extension) || "htm".equals(extension)) return "text/html"; else if ("css".equals(extension)) return "text/css"; else if ("...
66bc5d85-17e3-4e5c-91e5-249b01bb7241
private String getRealPathToFile(HttpServletRequest request) { String context_path = request.getContextPath(); String request_uri = request.getRequestURI(); return asset_dir_name + request_uri.substring(context_path.length()); }
a48f7331-c036-43ae-b0d3-8eb9141fbec2
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response); }
b8e9e79b-b94e-4ace-95d0-f0be9c1e7cf7
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response); }
ecd8c4fc-928c-4d46-a2f5-7ecc7f7f594e
@Override public String getServletInfo() { return "Short description"; }// </editor-fold>
15a98fae-3c56-4074-a9e5-d136acd5a3ba
public static void main(String[] args) { Magpie maggie = new Magpie(); System.out.println (maggie.getGreeting()); Scanner in = new Scanner (System.in); String statement = in.nextLine(); while (!statement.equals("Bye")) { System.out.println (maggie.getResponse(statement)); statement = in.nextLin...
9c660dd6-f1ee-45d8-abe6-cdb345f3a02f
public String getGreeting() { return "Hello, let's talk. Tell me about yourself..."; //user will be more inclined to talk about their pet or family }
62de502a-9217-4d55-b06b-42c6708ae32f
private int findKeyword(String statement, String goal) { return findKeyword (statement, goal, 0); }
66eb5d0d-f39e-4354-a04b-06049c7aeb65
public String expandContraction(String statement) { String temp = statement; //expands can't <- exception while (findKeyword(temp, "can't") >= 0) { int psn = findKeyword(temp, "can't"); //the position of the contraction String beginning = temp.substring(0,psn); //the piece before the cont...
261618e1-989d-480e-b3ae-d5394a062d11
private int findKeyword(String statement, String goal, int startPos) { String phrase = statement.trim(); int psn = phrase.toLowerCase().indexOf(goal.toLowerCase(), startPos); while (psn >= 0) { String before = " ", after = " "; if (psn > 0) { ...
bf1f90ce-c7d9-462a-bd64-407c80092a32
public String getResponse(String statement) { String response = ""; if (statement.trim().length() == 0) //varying responses for blank answers { final int blankhuman = 5; double r = Math.random(); int blankreply = (int)(r * blankhuman); if (blankreply == 0) {response = "SAY ...
896d2a22-1e50-473d-8b55-a2cb694ab8b6
private String transformIWantToStatement(String statement) { // Remove the final period, if there is one statement = statement.trim(); String lastChar = statement.substring(statement .length() - 1); if (lastChar.equals(".")) { statement = statemen...
3fb2162b-704f-4495-af6f-0b66eeeb7d9b
private String transformYouMeStatement(String statement) { // Remove the final period, if there is one statement = statement.trim(); String lastChar = statement.substring(statement .length() - 1); if (lastChar.equals(".")) { statement = statement....
afabbd2d-1057-477a-ad98-ab6e7751853d
private String transformIsStatementtoquestion(String statement) { // Remove the final period, if there is one statement = statement.trim(); String lastChar = statement.substring(statement .length() - 1); if (lastChar.equals(".")) { statement = sta...
e4a8f083-18d2-49ab-bd3a-e44c6d92212f
private String getRandomResponse () { Random r = new Random (); return randomResponses [r.nextInt(randomResponses.length)]; }
60d0cc0e-04d8-4774-b362-6667ee226460
public String getGreeting() { return "Hello, let's talk."; }
3f9a4b93-5412-4ea3-89ff-5770c81269ae
public String getResponse(String statement) { String response = ""; if (statement.length() == 0) { response = "Say something, please."; } else if (findKeyword(statement, "no") >= 0) { response = "Why so negative?"; } else if (findKeyword(statement, "mother") >= 0 || findKeyword(statement, "f...
df280d10-dcc6-423b-a4b4-2d4052dd692d
private String transformIWantToStatement(String statement) { // Remove the final period, if there is one statement = statement.trim(); String lastChar = statement.substring(statement .length() - 1); if (lastChar.equals(".")) { statement = statement.substring(0, statement .length() - 1); } in...
dad6d93b-8219-4735-becb-5d62e1685566
private String transformYouMeStatement(String statement) { // Remove the final period, if there is one statement = statement.trim(); String lastChar = statement.substring(statement .length() - 1); if (lastChar.equals(".")) { statement = statement.substring(0, statement .length() - 1); } i...
17223ee9-849b-47c9-8121-148ae5a9018f
private int findKeyword(String statement, String goal, int startPos) { String phrase = statement.trim(); // The only change to incorporate the startPos is in the line below int psn = phrase.toLowerCase().indexOf(goal.toLowerCase(), startPos); // Refinement--make sure the goal isn't part of a word while...
874520db-b170-474a-82cc-6eb0c78c25a0
private int findKeyword(String statement, String goal) { return findKeyword (statement, goal, 0); }
be76d7a5-991b-4ac5-b8ef-b0574db6f80b
private String getRandomResponse() { final int NUMBER_OF_RESPONSES = 4; double r = Math.random(); int whichResponse = (int)(r * NUMBER_OF_RESPONSES); String response = ""; if (whichResponse == 0) { response = "Interesting, tell me more."; } else if (whichResponse == 1) { response = "Hmmm."; ...
a50361bf-e4f0-44e3-a83c-a56c48c346ac
public static void main(String[] args) { Magpie4 maggie = new Magpie4(); System.out.println (maggie.getGreeting()); Scanner in = new Scanner (System.in); String statement = in.nextLine(); while (!statement.equals("Bye")) { System.out.println (maggie.getResponse(statement)); statement = in.nextL...
0941e01b-f870-403c-bd49-586eb3eff9d9
public static void main(String[] args) { Magpie2 maggie = new Magpie2(); System.out.println (maggie.getGreeting()); Scanner in = new Scanner (System.in); String statement = in.nextLine(); while (!statement.equals("Bye")) { System.out.println (maggie.getResponse(statement)); statement = in.nextL...
5a422cb7-f226-4f70-b68b-1b3ef806a029
public String getGreeting() { return "Hello, let's talk."; }
bcf0a898-d91a-4349-8513-325414882f23
public String getResponse(String statement) { String response = ""; if (statement.indexOf("no") >= 0) { response = "Why so negative?"; } else if (statement.indexOf("mother") >= 0 || statement.indexOf("father") >= 0 || statement.indexOf("sister") >= 0 || statement.indexOf("brother") >= 0) { ...
2170ab92-01b4-4838-8b00-cebc330300dc
private String getRandomResponse() { final int NUMBER_OF_RESPONSES = 4; double r = Math.random(); int whichResponse = (int)(r * NUMBER_OF_RESPONSES); String response = ""; if (whichResponse == 0) { response = "Interesting, tell me more."; } else if (whichResponse == 1) { response = "Hmmm."; ...
e0803c0b-2afc-4267-baa7-cc806a5fad87
public static void main(String[] args) { String sample = "The quick brown fox jumped over the lazy dog."; // Demonstrate the indexOf method. int position = sample.indexOf("quick"); System.out.println ("sample.indexOf(\"quick\") = " + position); // Demonstrate the toLowerCase method. String lowerCas...
388acace-816d-4d68-b9b5-1c66ef1b2086
public String getGreeting() { return "Hello, let's talk."; }
c471172d-adfb-4ec5-b017-f76137da0a74
public String getResponse(String statement) { String response = ""; if (statement.length() == 0) { response = "Say something, please."; } else if (findKeyword(statement, "no") >= 0) { response = "Why so negative?"; } else if (findKeyword(statement, "mother") >= 0 || findKeyword(statement, "fa...
5488a08a-3e31-4d0d-a174-a623e5c5f212
private int findKeyword(String statement, String goal, int startPos) { String phrase = statement.trim(); // The only change to incorporate the startPos is in // the line below int psn = phrase.toLowerCase().indexOf( goal.toLowerCase(), startPos); // Refinement--make sure the goal isn't part of a //...
f57a7d2b-77b6-4b3c-9763-23396d83f634
private int findKeyword(String statement, String goal) { return findKeyword(statement, goal, 0); }
13f2598f-14df-42bb-9317-f4c70edd4c01
private String getRandomResponse() { final int NUMBER_OF_RESPONSES = 4; double r = Math.random(); int whichResponse = (int) (r * NUMBER_OF_RESPONSES); String response = ""; if (whichResponse == 0) { response = "Interesting, tell me more."; } else if (whichResponse == 1) { response = "Hmmm."; ...
451b107c-1dd9-4e8d-a8e3-ae99809efa88
public static void main(String[] args) { Magpie3 maggie = new Magpie3(); System.out.println (maggie.getGreeting()); Scanner in = new Scanner (System.in); String statement = in.nextLine(); while (!statement.equals("Bye")) { System.out.println (maggie.getResponse(statement)); statement = in.nextL...
c6543f89-15de-4bb0-8df3-7cffc890be2d
public String getGreeting() { return "Hello, let's talk."; }