A example of use of C# class properties to convert temperatures in Celsius, Fahrenheit or Kelvin. The temperature is encapsulated and stored in a internal representation, in this example, in Celcius (private double c). Each conversion is accessible by getting or setting a property. using System; public class Temperature { private double c; [...]
28 September, 2011 - 11:43 pm
Tags: configuration, Heroku, Ruby, ubuntu
Posted in english | 1 comment
As root execute: apt-get update apt-get install build-essential ruby rails rubygems1.8 apt-get install ruby1.8-dev libopenssl-ruby Chance PATH at /etc/environment: PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/var/lib/gems/1.8/bin" Update your current environment: source /etc/environment Install the Heroku gem: sudo gem install heroku Run Heroku authentication configuration: heroku auth:login Enter the credentials for your Heroku account. Done!
This was a project that me and Marco Diego created during our graduation for the Computer Graphics course. It is a ray tracing engine build from scratch in C. It was great exercise of experimentation on how implement object-oriented design patterns in ANSI C. Later Marco continued it in his master’s degree thesis implementing more [...]
2 June, 2011 - 5:27 pm
Tags: clouds, HTML5, JavaScript, Pixelart
Posted in english | 6 comments
If you are reading this text, sorry, your browser don’t support HTML5 Canvas (or maybe I did something wrong). var canvas;var ctx;var background;var width=300;var height=200;var cloud;var cloud_x;function init(){canvas=document.getElementById(“cloud_demo_canvas”);width=canvas.width;height=canvas.height;ctx=canvas.getContext(“2d”);background=new Image();background.src=’http://silveiraneto.net/wp-content/uploads/2011/06/forest.png’;cloud=new Image();cloud.src=’http://silveiraneto.net/wp-content/uploads/2011/06/cloud.png’;cloud.onload=function(){cloud_x=-cloud.width};return setInterval(main_loop,10)}function update(){cloud_x+=0.3;if(cloud_x>width){cloud_x=-cloud.width}}function draw(){ctx.drawImage(background,0,0);ctx.drawImage(cloud,cloud_x,0)}function main_loop(){draw();update()}init(); Code: var canvas; var ctx; var background; var width = 300; var height = 200; var cloud; var cloud_x; [...]
Context ctx = getContext(); Display display = ((WindowManager)ctx.getSystemService(ctx.WINDOW_SERVICE)).getDefaultDisplay(); int width = display.getWidth(); int height = display.getHeight(); Yes, there are easier ways to retrieve the screen width on Android but there are cases that this long code is the only solution. You may already have the Context. WindowManager or the Display and so it would be [...]
29 April, 2010 - 10:29 am
Tags: Class, Java, method, programming, Reflection
Posted in english | 2 comments
import java.lang.reflect.*; public class Foo { public void bar(int param){ System.out.println(param); } public static void main(String args[]){ Object f = new Foo(); try { Method m = f.getClass().getMethod("bar", int.class); m.invoke(f, 42); } catch (Exception e){ System.err.println(e); } } } $ java Foo 42
8 April, 2010 - 1:09 pm
Tags: getruntime, Java, programming, runtime
Posted in english | No comments
I don’t like the approach of calling native shell commands in any language instead of using multi platform libraries, but here is a little prof of concept Java program to call native commands. import java.io.*; import java.util.*; public class Exec { public static void main(String args[]) throws IOException { Process proc = Runtime.getRuntime().e xec(args); BufferedReader [...]
Iterating over a HashMap using the enhanced loop (foreach) in Java is a good way to keep your code smaller, more legible and usually more semantically coherent. import java.util.HashMap; import java.util.Map; class Foo {} public class Main { public static void main(String args[]){ Map<Byte, Foo> mHash; mHash = new HashMap<Byte, Foo>(); [...]
This is a simple program I wrote called Who Am I that shows informations about the device which it is running. Which can be useful for developers and maybe advanced users. Download: WhoAmI.tar.bz2 – Eclipse project. It’s configured for Android platform 4 (1.6) but should work without problems in newer Android platform versions. WhoAmI.apk – [...]
27 February, 2010 - 9:39 pm
Tags: caps lock, Java, programming, socket, upcase
Posted in english | 3 comments
Here is a simple server for those who are starting studying sockets or just needs a simple socket server example for reuse while writing your own behavior. Features: A client should enter a string and the server would answer the same string, with each symbol in up case, when possible. Default port at 8080. One [...]
14 August, 2008 - 11:42 am
Grande Silveira!
Curti o visual novo do Blog, mais limpo que o antigo.
E que venha o NetBeans 6.5! Estou aguardando ansiosamente :)
Aquele abraço