2024-11-21

Typesense - Admin API Key

 {

  "description": "Admin key",

  "actions": [

    "*

  ],

  "collections": [

    "*"

  ]

}

Typesense - API Key to search only but everywhere

 {

  "description": "Search-only API key",

  "actions": [

    "documents:search"

  ],

  "collections": [

    "*"

  ]

}


Docker - Determine the version of your mongodb container

docker exec container-name-here mongod --version


npm - Update your system to the latest npm version

npm install -g npm@latest

2024-10-16

2024-08-07

Meteor - Blaze asynchronous helper handling

 {{#let data = (helper_name 'value1' 'value2')}}

    {{#if @pending 'data'}}

        Loading message here... 

    {{/if}}

    {{#if @rejected 'data'}}

        Error message here... 

    {{/if}}

    {{#if @resolved 'data'}}

        Your data-dependent content here...

    {{/if}}

{{/let}}

2024-06-17

MacOS - Terminal recursive unzipping

 # Good one!!

find ~/Documents/unzipTest -type f -name "*.zip" -exec unzip {} -d ~/Documents/unzipTest/ \;


# Alternative

find ~/Documents/unzipTest -type f -name "*.zip" -print0 | xargs -0 -I{} unzip {} -d ~/Documents/unzipTest


find <path_of_your_zips> -type f -name "*.zip" -exec unzip {} -d <out> \;


find <path_of_your_zips> -type f -name "*.zip" -exec unzip {} -d <out> \;


find /Users/ca/Documents/unzipTest/ -type f -name "*.zip" -exec unzip {} -d ~\Documents\unzipTest\ \;


find /Users/ca/Documents/unzipTest -type f -name "*.zip"


2024-05-26

Meteor 3 - Client-side awaiting for server-side methods execution

// This works best!

const res = await Meteor.callAsync("addTestActivity", {});

res; //res is undefined


// This works too

const res = await Meteor.callAsync("addTestActivity", {})

    .then((error, response) => {

        if(error) return error;

        return response;

    }); 

res;



// This works! (though it unnecessaryly wraps a Meteor call synchronous method call in a promise, see above)

const res = await new Promise((resolve, reject) => {

    Meteor.call("addTestActivity", {}, 

        (error, response) => {

            if(error) reject(error);

            resolve(response);

            return response;

        }

    );

});

res; // res is good, the value returned by the method



//This does not work

const res = await Meteor.call("addTestActivity", {}, 

    (error, response) => {

        if(error) return error;

        return response;

    }

)); //res is undefined



// This does not work either (no callback)

const res = await Meteor.call("addTestActivity", {});

res; //res is undefined



// For quick reference, here is the server-side method

import {ValidatedMethod} from "meteor/mdg:validated-method";

import SimpleSchema from 'simpl-schema';

export const addTestActivity = new ValidatedMethod({

    name: "addTestActivity",

    validate: new SimpleSchema({}).validator(),

    async run({}) {

return await activity.insertAsync({x:1, y:2, z:3});

    }

});



2024-04-18

Ollama - JS raw API call

_ask = async (model, prompt) => {

    try {

        const response = await fetch("http://localhost:11434/api/generate", {

            method: "POST",

            headers: {"Content-Type": "application/json"},

            body: JSON.stringify({ model, prompt, stream: false })

        });

        return await response.json();

    } catch (err) {

        console.error('error:', err);

    }

};

2024-03-21

MacOS - List all empty files recursively

find . -maxdepth 1 -type f -name '*.*' -empty

2024-03-03

JavaScript - Paint tables in the log console

 console.table([2,3,4,5,6]);

┌─────────┬────────┐

│ (index) │ Values │

├─────────┼────────┤

│    0    │   1    │

│    1    │   2    │

│    2    │   3    │

│    3    │   3    │

│    4    │   4    │

│    5    │   5    │

│    6    │   6    │

│    7    │   7    │

└─────────┴────────┘

2024-01-23

Bootstrap - Extend link to parent (stretched-link)

 <div class="card" style="width: 18rem;">

  <img src="..." class="card-img-top" alt="...">
  <div class="card-body">
    <h5 class="card-title">Card with stretched link</h5>
    <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
    <a href="#" class="btn btn-primary stretched-link">Go somewhere</a>
  </div>
</div>


https://getbootstrap.com/docs/4.3/utilities/stretched-link/