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:10661092
Created April 14, 2014 16:01
A Google Script for spreadsheets to covert a selection of cells to mins:secs
function sensible_time() {
var sheet = SpreadsheetApp.getActiveSheet();
var data = sheet.getActiveRange().getValues();
for (var i = 0; i < data.length; i++) {
for (var j = 0; j < data[i].length; j++) {
if (data[i][j]) {
var range = sheet.getRange(24+i, j+1);
time = data[i][j];
var mins = ~~(time / 60);
var secs = time % 60;
@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 / finance.js
Last active November 10, 2015 12:13
Personal Finance microservice to write CSV data to Google Sheet
module['exports'] = function echoHttp (hook) {
var body = hook.params; // This gives all the JSON body parameters in an object.
//Using a small security measure ;)
if(body.secret != "dgfdg45345jf0248234234"){
hook.res.end("Unauthorized");
return;
}
var https = require('https'),
@dulichan
dulichan / If.js
Created January 29, 2016 15:32
If— BY RUDYARD KIPLING (in JS)
var you = {};
var others = [];
// If you can keep your head when all about you
// Are losing theirs and blaming it on you,
if (keepYourHead(you)){
looseTheirHead(others);
blame(you);
}
// If you can trust yourself when all men doubt you,
// But make allowance for their doubting too;