Converting Words/Numbers to Discord “Letter/Number Emojis”

So i am a beginner to python (and programming overall) and i decided that it would be funny if i wrote a program that could convert Letters/Numbers to these “Letter Emojis” in Discord. It works but i am quite unsure if this is the best way to do it. There are also some bugs caused by adding spaces before actually typing Letters/Numbers. I commented it as precisely as I could to make the Code as understandable as possible

from tkinter import *   root = Tk()   # defines the funtion click which gets called when the submitButton1 is pressed def click():     # makes sure the list is empty in case the user presses the button again to convert something new     result.clear()     # saves the text which is entered in the textentry box, this later gets converted to "Discord Letters"     entered_text=textentry.get()     # deletes the output box in case the user presses the button again to convert something new     output.delete(1.0, END)     # the function to convert a String to "Discord Letters"     discord(entered_text)     # loop which gets the length of the string typed in the textentry box and then outputs it to the output textbox     for i in range(len(entered_text)):         output.insert(END, result[i])   # A List in which the converted Letters are stored it's later used to output the converted Letters in a Textbox result = []   # the function to convert a String to "Discord Letters" def discord(word):     # List of numbers from 0-9 , is used to check the string for numbers and then convert them     # to "Discord Digits" since they have a different syntax in discord than Letters     chars = set('0123456789')     s = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',          'w', 'x', 'y', 'z'}     # In case the User enters spaces they get removed since they just cause trouble     word = word.replace(" ", "")     word = word.lower()     w = word     for i in range(len(w)):         # checks if the string has a number and outputs accordingly         if any((c in chars) for c in w[i]):             list_one = ["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", ]             result.append(':' + list_one[int(w[i])] + ":" + " ")         # checks if the string has letter and outputs accordingly (might be unnecessary)         elif any((c in s) for c in w[i]):             result.append(':regional_indicator_' + w[i] + ":" + " ")         else:             # In case the user inputs something wrong             print("False Input")   root.title("Discord Letter Converter") # TextInput textentry = Entry(root, width=20, bg="white") textentry.pack() # submitButton submitButton1 = Button(root, text="Submit", width=6, command=click)# submitButton1.pack() # TextOutput output = Text(root, width=75, height=6, wrap=WORD, background="white") output.pack() root.mainloop() ``` 

Converting a Linear Fractional Transformation as a Hyperbola

I’m trying to show algebraically that a Linear Fractional Transformation of the form $ $ f(x)=\frac{(ax+b)}{(cx+d)}$ $ can be written as hyperbolas of the form $ $ (x-h)(y-k)=m$ $ I started by expanding the hyperbola equation to get $ $ xy-hy-kx+hk=m$ $ and then manipulated the LFT equation into $ $ cxy-ax+d=b$ $ This looks promising because all I need is another y term in the LFT equation and I can divide all constants by c and I will have something in the same form as the hyperbola equation but I have no clue how to get an extra y term.

The other consideration I had was to set h=0. If I did this I would be able to get the hyperbola equation into the form $ $ xy-kx=m$ $ and the LFT into the form $ $ cxy-ax=b-d$ $ Is there a different way to show they are same without having to set h=0?

Is there a less than $O(n)$ algorithm for converting UTF-8 character offsets to byte offsets, in a gap buffer?

A Gap Buffer is a variation on a dynamically-sized array, but with a gap inside it. The gap makes editing operations around the gap more efficient. Deletion before the gap can be implemented by simply making the gap larger for example.

UTF-8 is a variable width encoding for text. The first bits of the first byte of a character describes how many bytes are in the character, to a maximum of four.

When describing a cursor position in a string, (specifically a position between characters), we can use a pair consisting of the line number, (let’s say we start at zero), and the horizontal character offset (how many characters to the right the cursor is from the position to the left of the first character on the line). It is useful to use this representation to position a cursor.

However, in order to move the byte offsets that determine where the buffer’s gap is we need to convert the line number and character offset to a byte index.

The best way I currently know how to do this is the following $ O(n)$ algorithm:

Call the line number and character offset we are looking for the byte offset of, "the target".  Keep track of the current line number and character offset as we go, starting each at 0.  for (the characters before the gap) {     if the current line number and character offset matches the target,         return the byte offset. }  if the space right after the last character before the gap matches the target,     return the byte offset of the start of the gap.  for (the characters after the gap) {     if the current line number and character offset matches the target,         return the byte offset. }  if the space right after the last character after the gap matches the target,     return the byte offset of the end of the buffer.  Otherwise, the cursor is out of bounds. 

This is all under the assumption that the buffer is well-formed. That is, the gap starts immediately after a UTF-8 character, and the gap ends just before another one, or the end of the entire buffer.

Is there a way to do this with a lower computational complexity than $ O(n)$ ? If I try to imagine one, the closest I can get is to try something like binary search, but that seems like finding a pivot point (past maybe the first one which we could cache,) would involve iterating over the buffer anyway, so it wouldn’t actually be $ O(\log n)$ .

Could you please recommend an approach on converting non-unique field to a unique field?

On our prod db we have two tables:

  1. companies
  2. invoices

enter image description here

Relationship: A company has many invoices An invoice belong to a company

The invoices table contains duplicate invoice_number for each company. What is the best approach to make invoice number unique for each company. what ever approach we go with, the changes shouldn’t affect the existing references to the invoice table. It should only affect new invoice records.

Converting SalesForce IDs for Performance Reasons

I’m writing code for a data warehouse that extracts information from SalesForce. The format of the SalesForce IDs is like so:


Where each digit is a base-62 value denoted by:

a-z (26 values, case-sensitive)
A-Z (26 values, case-sensitive)
0-9 (10 values)

26+26+10 = a total of 62 values per digit

I want to convert these into a format that can be efficiently indexed by Postgres for thousands of rows.

I have gotten this far:

select id, array_to_string(array_agg(ascii),'','0')::decimal FROM (        SELECT id, ascii(regexp_split_to_table(id, '')) from example_schema.example_table      ) x group by id 

but it seems super inefficient and also may be hard to reverse in some cases because there’s no delimiter between the codes.

  • Is using a decimal type as an ID/identity efficient?
  • Is there an easier way to convert these to a numeric value that can still be used as a primary key and is a reversible operation if needed?

Here’s the query plan:

GroupAggregate  (cost=109862.92..130267.92 rows=742000 width=51)   Group Key:   ->  Sort  (cost=109862.92..111717.92 rows=742000 width=23)         Sort Key:         ->  Result  (cost=0.00..14875.99 rows=742000 width=23)               ->  ProjectSet  (cost=0.00..3745.99 rows=742000 width=51)                     ->  Seq Scan on account  (cost=0.00..30.42 rows=742 width=19) 

Example output:

001n000000ShgGbAAJ  746565987110310483484848484848110494848 001n000000SIZE7AAP  4848491104848484848488373906955656580 001n000000Sj3NCAAZ  48906565677851106834848484848481104948 001n000000SJK1sAAH  48484911048484848484883747549115656572 

They seem out of order which will cause issues with reversing the operation

Converting Single Liked List to a Doubly Linked List using class inheritance

I managed to create the single linked list using the following class named node:

  class node{ protected: int info;  //value int lenght; node *next; node *head; 

(In public I have the working funcitons). And the other class double_node:

class double_node : public node{ node *prev; 

My issue here is using the add function in the double_node class, where I have two problems (modified it alteast 10 times but I’ll post the one with all errors I got, because I’m not sure the other versions fixed any of them):

void add (int x){     double_node *p = new double_node(x); // constructor makes next = NULL & info = x     if (head == NULL)         {             p->prev = NULL;             head = p;         }     else     {         double_node* q = head; //#1st issue, no idea how to initialize a pointer with head         while (q->next!= NULL)         {             q = q->next; //#2nd issue         }         q->next= p;         p->prev= q;     } } 

Both errors are : invalid conversion from ‘node*’ to ‘double_node*’ [-fpermissive].

Any ideeas to fix this? Or maybe another way to create the doubly linked list?

Thanks in advance!

Converting VBA Add-In to C# VSTO. Code following button click event

This is my first program with C# and VS and was originally a VBA Add-In I wrote. I have embarked on this as a learning exercise. The code does work and provides the desired output in a new workbook.

The code below is called from a button on a custom ribbon created in Excel. It collects data from other workbooks w/o opening them and compiles the data into a new workbook so it can be easily reviewed.

Some of the things I am looking for in the review are but not limited to:

  • Proper class design
  • Proper use of static vs non-static
  • Have best practices been followed regarding connections

I am aware that the exception handling needs improvement. Part of me thinks that warrants a question unto itself but making it more explicit is on my todo list.

Below is the only part of the code that is in the VSTO project and has been truncated.

// Ribbon Callbacks try {     switch (control.Id)     {         case "fullReport":             FullReport.FullReportMain(Globals.ThisAddIn.Application);             break;     } } catch (Exception ex) {     DialogResult dialogResult = MessageBox.Show(ex.Message, "System Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } 

The separate project in the same solution to be reviewed.

using System; using System.Data; using System.Data.OleDb; using System.Globalization; using System.Linq; using Excel = Microsoft.Office.Interop.Excel;  namespace BfMetricsAddIn {     /// <summary>     /// Static Class for FullReport button.     /// </summary>     public static class FullReport     {         private const string MNewbornsWS = "Newborns_3";  #if DEBUG          /// <summary>         /// Main for the FullReport.         /// </summary>         /// <param name="xlApp">Excel application</param>         public static void FullReportMain(Excel.Application xlApp) #else         /// <summary>         /// Main for the FullReport.         /// </summary>         /// <param name="xlApp">Excel Application</param>         public static void FullReportMain(Excel.Application xlApp) #endif         { #if DEBUG             string[] pathArray = XlFileDialog.SelectFiles(); #else             string[] pathArray = XlFileDialog.SelectFiles(xlApp); #endif             BreastFeedingData[] breastFeedingDataArr = new BreastFeedingData[pathArray.Length];              for (int i = 0; i < pathArray.Length; i++)             {                 DataTable dataTable = CreateDataTable(pathArray[i]);                 breastFeedingDataArr[i] = new BreastFeedingData(dataTable);             }              // Sort Array by date.             BreastFeedingData[] sorted = breastFeedingDataArr.OrderBy(c => c.FileDate).ToArray();              // Create a new workbook             ReportWorkbook repWorkbook = new ReportWorkbook(xlApp, sorted);              try             {                 // Add data to newly created workbook                 repWorkbook.AddData();             }             catch (Exception)             {                 repWorkbook.Workbook.Close(false);                 throw;             }              // Save new workbook             string savePath = string.Format(             CultureInfo.CurrentCulture, @"C:\Users\{0}\Documents\BFMetrics\ReportFiles", Environment.UserName);              // Save in default location             const string fileName = @"\" + "BFMetricsReport";             repWorkbook.Workbook.SaveAs(savePath + fileName);         }          /// <summary>         /// Create a DataTable from Excel workbook         /// </summary>         /// <param name="fileName">full path of Excel worksheet.</param>         /// <returns>DataTable from Excel workbook.</returns>         private static DataTable CreateDataTable(string fileName)         {             DataTable dt = null;             OleDbConnection myConnection = null;             try             {                 string connectionString = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" + fileName +                     ";Extended Properties='Excel 12.0 xml;HDR=Yes;IMEX=1'";                  myConnection = new OleDbConnection(connectionString);                 myConnection.Open();                  const string sheetName = MNewbornsWS + "$  ";                  OleDbDataAdapter myCommand = new OleDbDataAdapter("select * from [" + sheetName + "]", myConnection);                 dt = new DataTable();                 myCommand.Fill(dt);             }             catch (Exception)             {                 throw;             }             finally             {                 myConnection.Close();             }              return dt;         }     } } 
using System; using System.Globalization; using Excel = Microsoft.Office.Interop.Excel; using FileDialog = Microsoft.Office.Core.FileDialog; using Office = Microsoft.Office.Core;  namespace BfMetricsAddIn {     /// <summary>     /// The file dialog box selector in Excel.     /// </summary>     public static class XlFileDialog     {         /// <summary>         /// Debugging preselected files.         /// </summary>         /// <returns>Predefined Array for testing.</returns>         public static string[] SelectFiles()         {             string folderPath = string.Format(                 CultureInfo.CurrentCulture, @"C:\Users\{0}\Documents\BFMetrics\OriginalMonthFiles\", Environment.UserName);              // Debugging file paths             string[] pathArray = new string[3];             pathArray[0] = folderPath + "BreastfeedingMetrics(Nov18).xlsx";             pathArray[1] = folderPath + "BreastfeedingMetrics(Dec18).xlsx";             pathArray[2] = folderPath + "BreastfeedingMetrics(Aug18).xlsx";             return pathArray;         }          /// <summary>         /// User selects files to collect data from.         /// </summary>         /// <param name="xlApp">Excel Application</param>         /// <returns>Array of full file path strings.</returns>         public static string[] SelectFiles(Excel.Application xlApp)         {             FileDialog dialog = xlApp.FileDialog[Office.MsoFileDialogType.msoFileDialogOpen];             dialog.AllowMultiSelect = true;             dialog.Filters.Add("Excel Files", "*.xlsx", 1);             dialog.InitialFileName = string.Format(                 CultureInfo.CurrentCulture, @"C:\Users\{0}\Documents\BFMetrics\OriginalMonthFiles", Environment.UserName);              if (dialog.Show() > 0)             {                 string[] pathArray = new string[dialog.SelectedItems.Count];                  for (int i = 1; i < dialog.SelectedItems.Count; i++)                 {                     pathArray[i - 1] = dialog.SelectedItems.Item(i);                 }                  if (pathArray.Length > 0)                 {                     return pathArray;                 }                  throw new ArgumentException($  "{pathArray} has a length of zero.");             }             else             {                 throw new ArgumentException("File selection canceled by user.");             }         }     } } 
namespace BfMetricsAddIn {     /// <summary>     /// Excel workbook that will hold monthly stats report.     /// </summary>     public class ReportWorkbook     {         private readonly Excel.Application xlApp;         private readonly BreastFeedingData[] sorted;         private Excel.Worksheet worksheet;          /// <summary>         /// Initializes a new instance of the <see cref="ReportWorkbook"/> class.         /// </summary>         /// <param name="xlApp">An current instance of the Excel Application.</param>         /// <param name="sorted">Array of BreastFeedingData objects sorted by date.</param>         public ReportWorkbook(Excel.Application xlApp, BreastFeedingData[] sorted)         {             this.xlApp = xlApp;             this.sorted = sorted;             this.Workbook = this.xlApp.Workbooks.Add(Type.Missing);         }          /// <summary>         /// Gets created workbook.         /// </summary>         public Excel.Workbook Workbook { get; }          /// <summary>         /// Adds the data to the workbook         /// </summary>         public void AddData()         {             this.worksheet = this.Workbook.ActiveSheet;             this.worksheet.Name = "StatReport";             string[] rowNames = new string[]                 { "Date", "One Hour Feeding", "Skin to Skin", "Initiation Rate", "Exclusivity Rate", "Number of Babies" };              for (int r = 0; r < rowNames.Length; r++)             {                 this.worksheet.Cells[r + 1, 1].Value = rowNames[r];             }              for (int c = 0; c < this.sorted.Length; c++)             {                 int r = 1;                 this.worksheet.Cells[r++, c + 2].Value = "'" + this.sorted[c].FileDate.ToString("MMMyy", CultureInfo.CurrentCulture);                 this.worksheet.Cells[r++, c + 2].Value = this.sorted[c].OneHourFeeding;                 this.worksheet.Cells[r++, c + 2].Value = this.sorted[c].SkinToSkin;                 this.worksheet.Cells[r++, c + 2].Value = this.sorted[c].InitiationRate;                 this.worksheet.Cells[r++, c + 2].Value = this.sorted[c].ExclusivityRate;                 this.worksheet.Cells[r++, c + 2].Value = this.sorted[c].NumberOfNewborns;                 r = 1;             }              // Formatting             Excel.Range xlDataRange = this.worksheet.Range[                 this.worksheet.Cells[1, 2], this.worksheet.Cells[6, this.sorted.Length + 2]];              // Format doubles to percentage             Excel.Range xlDoublesRange = this.worksheet.Range[                 this.worksheet.Cells[2, 2], this.worksheet.Cells[5, this.sorted.Length + 2]];             xlDoublesRange.NumberFormat = "##%";              // Set Alignment to center             xlDataRange.HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;              // AutoFit first column             Excel.Range rowNameColumn = this.worksheet.Columns[1];             rowNameColumn.EntireColumn.AutoFit();         }     } } 
using System; using System.Data;  namespace BfMetricsAddIn {     /// <summary>     /// One month of breast feeding data.     /// </summary>     public class BreastFeedingData     {         // Column names         private const string MFullName = "Full Name";          private const string MMRN = "MRN";         private const string MOHFColumnName = "Time to First Feeding (min)";         private const string MSTSColumnNameC = "Skin to Skin within 1 hour - Cesarean (1=Yes, 0=No)";         private const string MSTSColumnNameV = "Skin to Skin within 1 hour - Vaginal (1=Yes, 0=No)";         private const string MIRColumnName = "Ever Breastfed? (1=Yes, 0=No)";         private const string MERColumnName = "Exclusive?  (1=Yes, 0=No)";         private const string MDDColumName = "Discharge Date/Time";          // Constants for String to search for in row         private const string MNBCountRowName = "Mother/Infant - Count distinct";          private const string MNBStatRowName = "Mother/Infant - Total";          private DateTime fileDate;         private double oneHourFeeding;         private double skinToSkin;         private double initiationRate;         private double exclusivityRate;         private int numberOfNewborns;          /// <summary>         /// Initializes a new instance of the <see cref="BreastFeedingData"/> class.         /// </summary>         /// <param name="dt">DataTable created from Excel workbook</param>         public BreastFeedingData(DataTable dt)         {             this.ReadFromDataTable(dt);         }          /// <summary>         /// Gets the number of newborns for the month.         /// </summary>         public int NumberOfNewborns         {             get => this.numberOfNewborns;             internal set             {                 if (value == 0)                 {                     throw new ArgumentOutOfRangeException($  "_numberOfNewborns = {value}");                 }                 else                 {                     this.numberOfNewborns = value;                 }             }         }          /// <summary>         /// Gets the number of newborns fed within the first hour.         /// </summary>         public double OneHourFeeding         {             get => (double)this.oneHourFeeding / this.NumberOfNewborns;              internal set             {                 if (value == 0)                 {                     throw new ArgumentOutOfRangeException($  "_oneHourFeeding = {value}");                 }                 else                 {                     this.oneHourFeeding = value;                 }             }         }          /// <summary>         /// Gets the number of newborns with skin to skin within the first hour.         /// </summary>         public double SkinToSkin         {             get => (double)this.skinToSkin / this.NumberOfNewborns;              internal set             {                 if (value == 0)                 {                     throw new ArgumentOutOfRangeException($  "_skinToSkin = {value}");                 }                 else                 {                     this.skinToSkin = value;                 }             }         }          /// <summary>         /// Gets the number of newborns that have breast fed this month.         /// </summary>         public double InitiationRate         {             get => (double)this.initiationRate / this.NumberOfNewborns;              internal set             {                 if (value == 0)                 {                     throw new ArgumentOutOfRangeException($  "_initiationRate = {value}");                 }                 else                 {                     this.initiationRate = value;                 }             }         }          /// <summary>         /// Gets the number of newborns that have only breast fed this month.         /// </summary>         public double ExclusivityRate         {             get => (double)this.exclusivityRate / this.NumberOfNewborns;              internal set             {                 if (value == 0)                 {                     throw new ArgumentOutOfRangeException($  "_exclusivityRate = {value}");                 }                 else                 {                     this.exclusivityRate = value;                 }             }         }          /// <summary>         /// Gets the month and year associated with the data.         /// </summary>         public DateTime FileDate         {             get => this.fileDate;              internal set             {                 if (value == DateTime.MinValue)                 {                     throw new ArgumentOutOfRangeException($  "_fileDate = {value}");                 }                 else                 {                     this.fileDate = value;                 }             }         }          private void ReadFromDataTable(DataTable dt)         {             int oHFCounter = 0;             bool firstRowFlag = false;             bool keyValueFlagA = false;             bool keyValueFlagB = false;              try             {                 foreach (DataRow row in dt.Rows)                 {                     bool isSuccess;                      if (!firstRowFlag)                     {                         string strDateTime = row[MDDColumName].ToString();                         isSuccess = DateTime.TryParse(strDateTime, out DateTime dateTime);                          if (isSuccess)                         {                             this.FileDate = dateTime;                         }                          firstRowFlag = true;                     }                      // keyValue is the first column value.                     string keyValue = row[MFullName].ToString();                      string oneHourFeeding = row[MOHFColumnName].ToString();                     isSuccess = int.TryParse(oneHourFeeding, out int oHFItem);                      if (isSuccess && oHFItem <= 60 && oHFItem > 0)                     {                         oHFCounter++;                     }                      if (keyValue.Equals(MNBCountRowName, StringComparison.Ordinal))                     {                         keyValueFlagA = true;                          string numberOfNewborns = row[MMRN].ToString();                         isSuccess = int.TryParse(numberOfNewborns, out int intNumberOfNewborns);                          if (isSuccess)                         {                             this.NumberOfNewborns = intNumberOfNewborns;                         }                     }                      if (keyValue.Equals(MNBStatRowName, StringComparison.Ordinal))                     {                         keyValueFlagB = true;                          string s2sV = row[MSTSColumnNameV].ToString();                         isSuccess = int.TryParse(s2sV, out int ints2sV);                          string s2sC = row[MSTSColumnNameC].ToString();                         isSuccess = int.TryParse(s2sV, out int ints2sC);                          if (isSuccess)                         {                             this.SkinToSkin = ints2sC + ints2sV;                         }                          string initiationRate = row[MIRColumnName].ToString();                         isSuccess = int.TryParse(initiationRate, out int intInitiationRate);                          if (isSuccess)                         {                             this.InitiationRate = intInitiationRate;                         }                          string exclusivityRate = row[MERColumnName].ToString();                         isSuccess = int.TryParse(exclusivityRate, out int intExclusivityRate);                          if (isSuccess)                         {                             this.ExclusivityRate = intExclusivityRate;                         }                     }                 }                  if (!keyValueFlagA || !keyValueFlagB)                 {                     throw new ArgumentException($  "Both values must be true. keyValueFlagA: {keyValueFlagA} keyValueFlagB: {keyValueFlagB}.");                 }                  this.OneHourFeeding = oHFCounter;             }             catch (Exception)             {                 throw;             }         }     } } ``` – Get Paid for your opinions! Highest Converting Survey Site in Clickbank

Promote the newest and highest converting survey site in clickbank!

Our $ 1 trial is converting like nothing you have promoted before! Get 70% recurring commissions!


Converts on any traffic! Works great on international or any kind of traffic!

Our program is currently converting 1 sale out of 50 visitors. So if you send us 200 clicks a day expect 3-4 sales!

Everyday thousands of people are looking for ways to make… – Get Paid for your opinions! Highest Converting Survey Site in Clickbank

converting infopath (xml) file into PDF and sending email

we trying to explore infopath(xml) files convert into PDF. We had SharePoint list with custom infopath. Daily users submit the form for access. our goal was when user submitted the form, its need to convert into PDF form and then that PDF file need to send IT Team via email. Means first xml file need to convert PDF and then sending email with PDF file. Is it possible to infopath only (or) SharePoint workflow need it? Can anyone share guidance how to achieve our request.Thanks in Advance.