Skip to content

Instantly share code, notes, and snippets.

View ranjanprj's full-sized avatar

ranjanprj ranjanprj

  • Pune
View GitHub Profile
@ranjanprj
ranjanprj / Dockerfile
Created May 31, 2024 17:43 — forked from ItsWendell/Dockerfile
Postgres Dockerfile with Custom Extensions using pgxn
## Alternatives: postgres:15-alpine
ARG BASE_IMAGE=postgis/postgis:15-3.4-alpine
## Custom Alpine Postgres docker file with custom extensions
FROM ${BASE_IMAGE} as builder
# Install required dependencies
RUN apk --no-cache add \
python3 \
@ranjanprj
ranjanprj / gist:952254072c69acb092bc01260e7b73dd
Last active June 16, 2021 18:24
Creating a very simple PostgreSQL Extension in C
sudo apt-get update
sudo apt install postgresql-server-dev-12
C File
=========
#include "postgres.h"
#include <string.h>
#include "fmgr.h"
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"iam:CreateInstanceProfile",
"iam:DeleteInstanceProfile",
"iam:GetRole",
"iam:GetInstanceProfile",
@ranjanprj
ranjanprj / PG_EXTN_C_WITH_RUST.md
Last active November 9, 2019 18:10
PostgreSQL Extension in C with Rustlang

Just a small gist to show how you can easily create a Rust shared lib, wrap it with C and call it from PostgreSQL SQL Command.

  1. Prereq : Tested on Ubuntu 18, GCC, postgresql-server-11, postgresql-dev-11, rustlang
  2. Create new project Cargo embed and cd embed
  3. Rename the file src/main.rs to lib.rs
  4. Add following code
#[no_mangle]
pub extern fn double_input(input: i32) -> i32 {
    input * 2
sap.ui.controller("Main", {
/**
* Called when a controller is instantiated and its View controls (if available) are already created.
* Can be used to modify the View before it is displayed, to bind event handlers and do other one-time initialization.
* @memberOf testcockpit.Main
*/
onInit: function() {
// $.ajaxSetup({
// beforeSend: function(oXhr) {
;Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:
;1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...
;By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.
;*** PROBLEM WITH EULER CONDITION THEY SAY 4 MILLION BUT ACTUALLY MEAN 40 MILLION
(defn fibr-sum-even[upto]
(loop [a 0N b 1N sum 0N]
(println (str b " - " sum))
(if (> b upto) sum
(ns euler.core)
;; If we list all the natural numbers below 10 that are multiples of 3 or 5,
;; we get 3, 5, 6 and 9. The sum of these multiples is 23.
;; Find the sum of all the multiples of 3 or 5 below 1000.
(defn p1
[n]
(if (or(= 0 (mod n 3)) (= 0 (mod n 5)) )
/*
A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99.
Find the largest palindrome made from the product of two 3-digit numbers.
*/
/*
The prime factors of 13195 are 5, 7, 13 and 29.
What is the largest prime factor of the number 600851475143 ?
Answer:
*/
/*
If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.
Find the sum of all the multiples of 3 or 5 below 1000.
*/
function sum_of_mul(num){
var sum = 0;