Skip to content

Instantly share code, notes, and snippets.

private static void transferStreams(Socket socket) throws IOException,
InterruptedException {
InputStream input1 = System.in;
OutputStream output1 = socket.getOutputStream();
InputStream input2 = socket.getInputStream();
PrintStream output2 = System.out;
Thread thread1 = new Thread(new StreamTransferer(input1, output1));
Thread thread2 = new Thread(new StreamTransferer(input2, output2));
thread1.start();
thread2.start();
@rafalrusin
rafalrusin / filtering.java
Created December 17, 2011 23:02
DataTables JEE
private boolean filter(String sSearch, List<Object> list) {
if (sSearch.equals("")) {
return true;
}
return list.toString().contains(sSearch);
}
...
List<List<Object>> filteredList = new ArrayList<List<Object>>();
for (int i = 0; i < myList.size(); i++) {
@rafalrusin
rafalrusin / fbtest.c
Created December 15, 2011 20:22
Linux Frame Buffer Test
#include <linux/fb.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>
#include <sys/mman.h>
private void drawTree(RBNode n, float x1, float x2, float y1, float y2) {
if (n != null) {
if (n.left != null) {
drawConnection((x1 + x2)/2.0f, y1, (x2 - x1)*1.f/4.0f + x1, y2);
}
if (n.right != null) {
drawConnection((x1 + x2)/2.0f, y1, (x2 - x1)*3.f/4.0f + x1, y2);
}
drawNode("" + n.value, n.isBlack, (x1 + x2)/2.0f, y1);
drawTree(n.left, (x2 - x1)*0.f/4.0f + x1, (x2 - x1)*2.f/4.0f + x1, y2, y2 + (y2-y1));
@rafalrusin
rafalrusin / calculator.lex
Created October 3, 2011 19:22
calculator
%{
#include "calculator.tab.h"
using namespace std;
%}
%%
[ \t] ;
\+ { return PLUS; }
\- { return MINUS; }
\* { return MUL; }
\/ { return DIV; }
@rafalrusin
rafalrusin / iterating.java
Created June 12, 2011 21:55
GIS data visualization
File file = new File("110m_cultural\\110m_admin_0_countries.shp");
FileDataStore store = FileDataStoreFinder.getDataStore(file);
SimpleFeatureSource featureSource = store.getFeatureSource();
SimpleFeatureCollection c = featureSource.getFeatures();
SimpleFeatureIterator featuresIterator = c.features();
Coordinate[] coords;
Geometry polygon;
Point centroid;
Bounds bounds;
while (featuresIterator.hasNext()) {
@rafalrusin
rafalrusin / model.xml
Created March 22, 2011 22:44
UI Refresh based on Model items
<netflow.model.Model id="1">
<nodes id="2">
<netflow.model.MShape id="3">
<flow>10.0</flow>
<capacity>10.0</capacity>
<name>node-1</name>
<type>SOURCE</type>
<x>171.0</x>
<y>142.0</y>
</netflow.model.MShape>
@rafalrusin
rafalrusin / affine
Created March 7, 2011 21:12
bisect.fx
var u:Point2D = a.findBoundaryPoint(b.position, a.position);
var v:Point2D = b.findBoundaryPoint(a.position, b.position);
var l:Float = Math.sqrt(pointsLenSqr(u, v));
content = [
Path {
transforms: [
Affine {
mxx: (v.x-u.x)/l