Skip to content

Instantly share code, notes, and snippets.

View dulichan's full-sized avatar

Dulitha Wijewantha (Chan) dulichan

View GitHub Profile
@dulichan
dulichan / gist:8968945
Created February 13, 2014 02:57
Example of Jaggery GET with Callback
var url = "https://api.twitter.com/1/statuses/user_timeline.json";
var data = { include_entities:true,include_rts:true,screen_name:"wso2",count:1 };
var twitterJson = get(url, data ,"json", function(data, xhr){
print(data);
});
@dulichan
dulichan / gist:9577696
Created March 16, 2014 02:28
Get the runtime server address for jaggery application in the carbon environment
var getAddress = function(transport){
var process = require("process"),
host = process.getProperty('server.host'),
ip = process.getProperty('carbon.local.ip');
var log = new Log();
var port;
if(transport=="http"){
port = process.getProperty('mgt.transport.http.proxyPort');
if(!port){
//can use http.port as well
@dulichan
dulichan / gist:af557800b10f54c1f942
Last active August 29, 2015 14:01
Information extracted from an Rpie in JSON
{
"memory_info": {
"sdram_p_volate": 1.23,
"sdram_c_volate": 1.2,
"used_memory": 150163456,
"shared_memory": 0,
"total_memory": 459505664,
"sdram_i_volate": 1.2,
"cached_memory": 100642816,
"memory_buffers": 15024128,
@dulichan
dulichan / gist:05f62f2db585b5e962b3
Last active August 29, 2015 14:04
Reading a DHT11 sensor and publishing a MQTT message
public void run() {
dhtSensor.read();
float temperature = dhtSensor.getTemperature(false);
int humidity = dhtSensor.getHumidity();
try {
String message = "Temperature:" + Float.toString(temperature);
String humidityMsg = "Humidity:" + Integer.toString(humidity);
mqttClient.publish(1,message.getBytes());
} catch (MqttException e) {
e.printStackTrace();
@dulichan
dulichan / gist:65164276cfca48e236ed
Created July 18, 2014 03:31
Actuator code in the Raspberry Pi (stripped down version)
public class Receiver{
final GpioController gpio;
final GpioPinDigitalOutput pin;
{
gpio = GpioFactory.getInstance();
pin = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_00, "Relay");
}
public void run(String message){
System.out.println("Message received "+message);
@dulichan
dulichan / callback-example.js
Created October 9, 2014 02:28
Promises Example (uses bluebird)
var Promise = require('bluebird')
var fs = require('fs');
Promise.promisifyAll(fs);
fs.readFile("bb", function(err, data) {
if (err) return next(err);
fs.writeFile("bba", data, function() {
console.log("File written");
});
});
@dulichan
dulichan / LocalizationManagerUtil.java
Created December 19, 2014 01:28
Proposal idea for a localization manager
/*
The objective of this class is to manage localization options in CDM.
2 types Use cases:-
1) Localize the product based on a configuration
2) Localize components based on user preference.
Use case 2:- Localize the license file
*/
<div class="header">
<h1>Jaggery intro</h1>
<ul ng-repeat="todo in todos">
<li><input type="checkbox" ng-model="todo.status"> <span ng-model="todo.text">{{todo.text}}</span></li>
</ul>
</div>
@dulichan
dulichan / _resource_mismatch_handler_.xml
Created September 16, 2015 11:37
Returning 404 response for WSO2 ESB instead of 202
<!-- Exact sequence name as below should be there. This name is used inside the API implementation in Synapse -->
<sequence xmlns="http://ws.apache.org/ns/synapse" name="_resource_mismatch_handler_">
<log level="full"/>
<property name="HTTP_SC" value="404" scope="axis2"></property>
<respond/>
<drop></drop>
</sequence>
@dulichan
dulichan / gist:1710636
Created January 31, 2012 14:02
J2me Splitter class
public class Splitter {
public String[] split(String original, String separator) {
Vector nodes = new Vector();
// Parse nodes into vector
int index = original.indexOf(separator);
while (index >= 0) {
nodes.addElement(original.substring(0, index));
original = original.substring(index + separator.length());
index = original.indexOf(separator);
}