Skip to content

Instantly share code, notes, and snippets.

@esafwan
esafwan / FrappeCallIntercept.js
Created April 28, 2024 20:31
Override frappe call to intercept the call and act on basis of it.
/**
* Extends the functionality of Frappe's assignment feature for Leads.
*
* Problem:
* When a document like a Lead is assigned to a user via the sidebar, the information about the assignment
* (who it was assigned to, who assigned it, and when) is not stored in a way that can be easily displayed
* on Kanban cards or list columns. It only results in a ToDo list item without these details on the Lead itself.
*
* Solution:

To connect to Frappe's WebSocket and receive real-time updates when a document of a particular DocType is saved, you can use the socket.io-client library in your React Native app. Here's an example of a single-component app that demonstrates how to connect to the WebSocket, authenticate with an API key, and receive updates for a specific DocType:

import React, { useState, useEffect } from 'react';
import { StyleSheet, Text, View } from 'react-native';
import io from 'socket.io-client';

const API_KEY = 'your_api_key'; // Replace with your actual API key
const SITE_NAME = 'your_site_name'; // Replace with your site name
const DOCTYPE = 'your_doctype'; // Replace with the DocType you want to monitor

For use in prompt for AI for code related to frappe realtime and websocket

Realtime (socket.io) Frappe ships with an API for realtime events based on socket.io. Since socket.io needs a Node server to run, we run a Node process in parallel to the main web server.

Client APIs (JavaScript) frappe.realtime.on

@esafwan
esafwan / img.typ
Last active April 19, 2024 21:06
Typst catlog
#let img(image_path, img_width: auto, img_height: auto, img_alt: none, img_fit: "cover") = [
#image(image_path, width: img_width, height: img_height, alt: img_alt, fit: img_fit)
]
#let fig(image_path, img_width: auto, img_height: auto, img_alt: none, img_fit: "cover", img_caption: none) = [
#figure(
image(image_path, width: img_width, height: img_height, alt: img_alt, fit: img_fit),
caption: [
img_caption
]
@esafwan
esafwan / Simple typst handbook.md
Created April 19, 2024 15:36
short & Simple Typst Guide (WIP)

Image in Typst:

image in typst(raster/vector.Support: PNG, JPEG, GIF & SVG. Params:

image(
str,
format: autostr,
width: autorelative,
height: autorelative,
alt: nonestr,
@esafwan
esafwan / Read Me.md
Created April 16, 2024 05:16
Output directory tree as text with python

Python code for displaying the directory structure of a specific directory. It allows users to view the contents of a directory up to two levels deep, organizing and listing all subdirectories and files neatly.

Example Use Case:

Imagine you have a project directory for a web application, and you want to quickly understand how the files and folders are organized within this directory without diving into each folder manually. You can use this script to print out a structured list of all the directories and files, up to two levels deep.

Directory Structure Example:

Suppose your project directory is structured as follows:

@esafwan
esafwan / prompt.md
Last active April 11, 2024 21:00
Prompt to ask ChatGPT, Gemini, Mistral etc Typst syntax.

Typst: markup-based typesetting for sciences, alternative to LaTeX/Word. Easy, fast, versatile, outputs PDFs. Typst is similar to LaTex. It is not html. Ideal for essays, scientific papers, documents with math. LaTeX-like commands with simpler syntax, content blocks in square brackets, arguments (positional/named), data types, control flow, variable storage with #let, importing templates, direct Unicode input in math, customizable styles and document appearance, bibliography in YAML/BibTeX, CSL for citation styles, web app or local compiler usage. To specify page size (e.g., A4, US Letter) or margins in Typst, you use #set page() with named arguments for paper size and margins. This is fundamental for document setup, especially in contexts like visual design, where paper format is critical. For example, setting to A4 with custom margins:#set page(paper: "a4", margin: (x: 2cm, y: 3cm))Features: simple markup for headings (using "="), italics (using "_"), lists (using "+" for numbered and "-" for bulleted

@esafwan
esafwan / FrappeSearchEnhancement.md
Created January 9, 2024 21:25
Extending Frappe or ERPNext global search function to add additional filter

Extending the Frappe Search Method for using additional filters

Limitations of the Existing Search Method

The original search method in Frappe's __global_search table allowed for basic full-text search but lacked the ability to filter items based on specific attributes like whether an item is a variant or a parent item. This limitation made it challenging to perform more targeted queries, particularly for scenarios where such distinctions are crucial.

Read more about search over rest api here.

Enhancements Made

To address this, we added two new optional filtering parameters to the search function:

@esafwan
esafwan / Frappe_Realtime.md
Created November 21, 2023 02:42
Frappe Framework/ERPNext Realtime Publish with Socket.io

Realtime Communication in Frappe Framework

Frappe Framework, a full-stack web application framework written in Python and JavaScript, offers a powerful feature for realtime communication. This feature is built on the popular library socket.io, which enables real-time, bidirectional, and event-based communication between the browser and the server.

Overview of Realtime Communication in Frappe

Realtime communication in Frappe is event-based. This means that you can publish and subscribe to events. An event can be anything from a change in the database to a user action.

Publishing Events

@esafwan
esafwan / API.md
Last active October 31, 2023 05:45

Exposing API for Xtreme as per their document.

The key things I gathered are:

  • The API needs to provide transaction, item, and payment details in XML or JSON format
  • Transaction details include location, terminal, receipt info, amounts, currency etc.
  • Item details include item code, name, price, tax info etc.
  • Payment details include payment mode, currency, amounts etc.

The sample XML and JSON show the expected structure of the data that needs to be passed via the API. It looks like the API needs to be accessible via a URL with date parameters to fetch data.