Skip to content

Instantly share code, notes, and snippets.

View riyafa's full-sized avatar

Riyafa Abdul Hameed riyafa

View GitHub Profile
@riyafa
riyafa / point_to_point_consumer.bal
Last active March 14, 2019 09:44
A point to point consumer using ActiveMQ Artemis connector for Ballerina
import ballerina/artemis;
import ballerina/io;
@artemis:ServiceConfig{
queueConfig:{
queueName:"my_queue"
}
}
service artemisConsumer on new artemis:Listener({host:"localhost", port:61616}){
resource function onMessage(artemis:Message message) returns error? {
@riyafa
riyafa / point_to_point_producer.bal
Created March 8, 2019 06:35
A point to point producer using ActiveMQ Artemis connector for Ballerina
import ballerina/artemis;
import ballerina/log;
import ballerina/io;
public function main() {
artemis:Producer prod = new({host:"localhost", port:61616}, "my_queue");
map<string> msg = {"Hello":"World", "some":"world"};
byte[] vals = [1,2,2,3,3,2];
var err = prod->send(vals);
err = prod->send(msg);
@riyafa
riyafa / pub_sub_consumer.bal
Last active March 14, 2019 09:44
A publisher subscriber (pub-sub) consumer using ActiveMQ Artemis connector for Ballerina
import ballerina/artemis;
import ballerina/io;
@artemis:ServiceConfig{
queueConfig:{
queueName:"my_queue",
addressName:"my_address",
routingType: artemis:MULTICAST
}
}
@riyafa
riyafa / pub_sub_producer.bal
Created March 11, 2019 08:08
A publisher subscriber (pub-sub) producer using ActiveMQ Artemis connector for Ballerina
import ballerina/artemis;
import ballerina/log;
import ballerina/io;
public function main() {
artemis:Producer prod = new({host:"localhost", port:61616}, "my_address", addressConfig = {routingType:artemis:MULTICAST});
map<string> msg = {"Hello":"World", "some":"world"};
byte[6] vals = [1,2,2,3,3,2];
io:ReadableByteChannel ch = io:openReadableFile("/home/riyafa/abc.pdf");
var err = prod->send(vals);
import ballerina/http;
import ballerina/io;
import ballerina/log;
@http:ServiceConfig {
basePath: "/"
}
service httpService on new http:Listener(9090) {
@http:ResourceConfig {
import ballerina/http;
import ballerina/io;
import ballerina/log;
public function main() {
http:WebSocketClient wsClientEp = new("ws://localhost:9090/ws/xyz/Mawanella?age=26",
config = {callbackService: ClientService, customHeaders:{"X-name":"Riyafa"}, subProtocols:["xml"]});
var err = wsClientEp->pushText("hello");
if (err is error) {
log:printError("Error in sending text", err = err);
@riyafa
riyafa / MatrixMultiplicationRecursive.java
Last active February 24, 2021 16:12
Recursive square matrix multiplication in java using index calculations: https://riyafa.wordpress.com/?p=958
import java.util.Arrays;
public class MatrixMultiplicationRecursive {
public static void main(String[] args) {
int[][] A = new int[][]{{13, -3, -25, 20}, {-3, -16, -23, 18}, {20, -7, 12, -5}, {-22, 15, -4, 7}};
int[][] B = new int[][]{{13, 10, 11, 12}, {13, 14, -23, 18}, {20, -7, 12, -11}, {-12, -13, -14, 7}};
System.out.println(Arrays.deepToString(
multiply(A, B, 0, 0, 0, 0, A.length)
));
@riyafa
riyafa / MatrixMultiplicationStrassen.java
Created October 5, 2019 10:43
Strassen's algorithm for matrix multiplication using index calculations in java: https://riyafa.wordpress.com/?p=965
import java.util.Arrays;
public class MatrixMultiplicationStrassen {
public static void main(String[] args) {
/*int[][] A = new int[][]{{1, 3}, {7, 5}};
int[][] B = new int[][]{{6, 8}, {4, 2}};*/
int[][] A = new int[][]{{13, -3, -25, 20}, {-3, -16, -23, 18}, {20, -7, 12, -5}, {-22, 15, -4, 7}};
int[][] B = new int[][]{{13, 10, 11, 12}, {13, 14, -23, 18}, {20, -7, 12, -11}, {-12, -13, -14, 7}};
System.out.println(Arrays.deepToString(
@riyafa
riyafa / websocket_service_attach.bal
Last active October 14, 2019 14:05
Attach a Ballerina WebSocket service to a http:Listener.
import ballerina/http;
import ballerina/io;
listener http:Listener ep = new (9090);
service wsService = @http:WebSocketServiceConfig {} service {
resource function onText(http:WebSocketCaller wsEp, string text) {
io:println("Sever Received: " + text);
}
resource function onClose(http:WebSocketCaller wsEp, int statusCode, string reason) {
io:println("Connection closed");
@riyafa
riyafa / bing_wallpaper_downloader.py
Last active June 15, 2020 08:50
[Python2] Download weekly Bing wallpapers to a given folder. Can run it as a cron job everyday
import json, os
import os
import time
import urllib
import urllib2
from os.path import expanduser
from datetime import datetime
home_site = "http://bing.com"
weekly_wallpapers_url = home_site + "/HPImageArchive.aspx?format=js&idx=0&n=8&mkt=en-US"