Skip to content

Instantly share code, notes, and snippets.

View gidili's full-sized avatar
🐢
Probably eating pizza 🍕

Giovanni Idili gidili

🐢
Probably eating pizza 🍕
View GitHub Profile
@gidili
gidili / allocateBuffers.java
Created April 9, 2013 10:18
allocateBuffers
private void allocateBuffers(){
// host allocated pointers (used to write values -- see lines 81/82 in setModels below)
_positionPtr = Pointer.allocateFloats(_particleCount * 4);
_velocityPtr = Pointer.allocateFloats(_particleCount * 4);
// alternative buffer defining
_acceleration = _context.createFloatBuffer(Usage.InputOutput, _particleCount * 4 * 2);
_gridCellIndex = _context.createIntBuffer(Usage.InputOutput, _gridCellCount + 1);
_gridCellIndexFixedUp = _context.createIntBuffer(Usage.InputOutput, _gridCellCount + 1);
_neighborMap = _context.createFloatBuffer(Usage.InputOutput, _particleCount * SPHConstants.NEIGHBOR_COUNT * 2);
@gidili
gidili / runSort.java
Created March 10, 2013 15:50
Alternate sorting for PCI-SPH runSort step
public int runSort(){
// get values out of buffer
Pointer<Integer> particleInd = _particleIndex.read(_queue);
_queue.finish();
int[] particleIndex = new int[_particleCount * 2];
// copy to array of primitives
for(int i = 0;i< _particleCount*2;i++){
particleIndex[i] = particleInd.get(i);
@gidili
gidili / random_masking.js
Created January 31, 2013 16:53
random string masking in javascript
String.prototype.replaceAt=function(index, char) {
return this.substr(0, index) + char + this.substr(index+char.length);
}
var REPLACEMENT_CHAR = "*";
var TO = 5;
var FROM = 4;
var str = "Hello World";
@gidili
gidili / profanity_check.js
Created January 31, 2013 16:46
simple javascript profanity check
// extend strings with the method "contains"
String.prototype.contains = function(str) { return this.indexOf(str) != -1; };
// profanities of choice
var profanities = new Array("ass", "cunt", "pope");
var containsProfanity = function(text){
var returnVal = false;
for (var i = 0; i < profanities.length; i++) {
if(text.toLowerCase().contains(profanities[i].toLowerCase())){
@gidili
gidili / InvokeServlet.js
Created August 30, 2012 13:42
invoke servlet and transform json string into object
// servlet is local to the app
String requestURL = request.getRequestURL().toString();
String servletPath = request.getServletPath();
String serverPath = requestURL.substring(0,requestURL.indexOf(servletPath));
URL url = new URL(serverPath + "/getScores");
URLConnection conn = url.openConnection();
conn.setConnectTimeout(12000);
InputStream is = conn.getInputStream();
@gidili
gidili / TryParseInt.java
Created July 30, 2012 15:10
TryParse Integer in java
public static Integer TryParseInt(String someText) {
try {
return Integer.parseInt(someText);
} catch (NumberFormatException ex) {
return null;
}
}
@gidili
gidili / RandomNumberGenerator.java
Created July 30, 2012 14:09
Random Number Generator in java
import java.util.Random;
public class RandomNumberGenerator {
public static final int MIN = 0;
public static final int MAX = 1000000;
public static int GenerateRandomNumber(){
Random rand = new Random();
// nextInt is normally exclusive of the top value,
@gidili
gidili / flot_chrome_issue.js
Created July 14, 2012 15:50
Shows an issue on chrome when too many points are displayed
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Flot Examples</title>
<script type="text/javascript" src="js/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="js/jquery.flot.js"></script>
</head>
<body>
<h1>Flot Examples</h1>
@gidili
gidili / reproduce_flot_issue.html
Created July 14, 2012 00:40
reproduces a visual issue with flot on chrome
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<script src="./js/jquery-1.7.2.min.js"></script>
<script src="./js/jquery.flot.js"></script>
<script type="text/javascript">
var plot = null;
var flotOptions = { yaxis: { min: -30, max: 125 }, xaxis: { show: false, min: 0, max: 100 }, series: { shadowSize: 0 }, grid: { backgroundColor: { colors: ["#fff", "#eee"] } } };
function refreshChart(points)
@gidili
gidili / flot_realtime_example.js
Created July 13, 2012 18:40
flot_realtime_example
var plot = null;
var flotOptions = { yaxis: { min: -30, max: 125 }, xaxis: { min: 0, max: 100, show: false }, series: { shadowSize: 0 }, grid: { backgroundColor: { colors: ["#fff", "#eee"] } } };
function refreshChart(data)
{
if(data != null){
var points = [];
for(var i=0; i< data[0].length; i++){ points.push([data[0][i], data[1][i]]); }