Skip to content

Instantly share code, notes, and snippets.

View riyaz-ali's full-sized avatar
:octocat:

Riyaz Ali riyaz-ali

:octocat:
View GitHub Profile
@riyaz-ali
riyaz-ali / xirr.sql
Created December 9, 2021 09:04
Calculating Extended Internal Rate of Return in sqlite
-- The following snippet calculates the extended internal rate of return
-- for an investment, provided the list of transactions made during the time.
--
-- It expects a table `transactions` to be present (of-course feel free to rename)
-- with two columns, date and amount, where date is the date of the transaction
-- and amount being the amount of the transaction. Each outflow (like, money put into the investment)
-- must be a negative value and each inflow (like, money take out from investment) must be positive.
--
-- P.S. This snippet depends on POWER(...) function from [https://github.com/nalgeon/sqlean].
-- Either import that or provide your own.
@riyaz-ali
riyaz-ali / README.md
Created March 14, 2020 18:21
Waveshare 2.9-inch E-paper display driver in Golang

Waveshare E-paper

This gist contains driver for Waveshare's 2.9-inch E-paper display module.

Usage

// This examples runs on Raspberry Pi 3 board and uses "github.com/stianeikeland/go-rpio/v4" as GPIO library
// You can use any other library too as long as it satify the types defined in gpio.go
@riyaz-ali
riyaz-ali / epd2in9.go
Created March 11, 2020 06:56
Waveshare E-Paper 2.9inch Driver in Golang
package main
import (
"github.com/stianeikeland/go-rpio/v4"
"log"
"time"
)
const (
RST = rpio.Pin(17)
@riyaz-ali
riyaz-ali / FTPUploadTest.java
Created February 20, 2018 05:09
Patching TLS session resumption on Apache Commons Net FTPSClient
import org.apache.commons.net.PrintCommandListener;
import org.apache.commons.net.ftp.FTP;
import org.apache.commons.net.ftp.FTPFile;
import org.apache.commons.net.ftp.FTPSClient;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.file.FileSystems;
import java.nio.file.Path;
@riyaz-ali
riyaz-ali / querystring.js
Last active October 24, 2017 08:05
A simple Object-to-querystring serializer
function isObject(val) {
// adapted from https://github.com/jonschlinkert/isobject and https://github.com/jonschlinkert/is-plain-object
return(val != null && typeof val === 'object' && Array.isArray(val) === false) === true &&
Object.prototype.toString.call(val) === '[object Object]';
};
function toQueryString(obj, format) {
return Object.keys(obj)
.filter(key => (obj[key] != null) || (obj[key] != undefined))
.map(key => {
@riyaz-ali
riyaz-ali / Middleware.js
Created August 8, 2017 08:58
A Promise-based middleware implementation in ES6
//- A Promise-based middleware implementation
let nextTick = 'undefined' !== typeof process
? process.nextTick
: 'undefined' !== typeof setImmediate
? setImmediate
: setTimeout;
class Middleware {
/** create a new Middleware */
@riyaz-ali
riyaz-ali / imad_profile.html
Created July 26, 2017 07:37
HTML Source of my IMAD profile available on http://riyazkagzi17.imad-b.hasura-app.io/
<!DOCTYPE html>
<html lang="en">
<head>
<title>Riyaz's IMAD Profile</title>
<!-- some meta information about this page -->
<meta charset="utf-8">
<!-- prevent resizing the screen, used for mobile-first website -->
<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
<!-- Using Boostrap provided by Hasura --> <!-- Bootstrap? see https://getbootstrap.com-->
/**
* Activity class consuming the encrypted database
*/
package com.riyazali.example
//- other imports
import net.sqlcipher.database.SQLiteDatabase;
//- SQLiteOpenHelper
@riyaz-ali
riyaz-ali / Middleware.js
Last active February 13, 2018 17:51 — forked from darrenscerri/Middleware.js
A very minimal Javascript (ES5) Middleware Pattern Implementation
let Middleware = function() { };
// executes the middlewares supplying initial args to the first middleware
// this function returns a Promise which gets resolved after the last middleware is executed
Middleware.prototype.exec = function() {
let args = Array.prototype.slice.call(arguments);
let that = this
return new Promise(function(resolve /*,reject */){
let pr = this;
let end = function(){
@riyaz-ali
riyaz-ali / DI.js
Created March 16, 2017 08:41
A simple Javascript service dependency injection script in es6
let __DI_impl = {
__deps: {}, /* Object containing registered dependencies */
/* register dependency */
register: function(func, args){
let f;
if(!!args)
f = func.bind.apply(func, [func, ...args]);
// ^^^^ ^^^^
// Context for apply & bind