-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
2025-02-04 17:12:23.839215 new snippets
- Loading branch information
1 parent
7c90270
commit 3b62b66
Showing
18 changed files
with
1,665 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#date: 2025-02-04T17:02:23Z | ||
#url: https://api.github.com/gists/2dfe7334a23d544b01b9d601a30e7574 | ||
#owner: https://api.github.com/users/aspose-com-kb | ||
|
||
# Import necessary modules | ||
import requests # For making HTTP requests to fetch webpage content | ||
from io import BytesIO # To handle byte stream data | ||
from aspose.pdf import Document # Import Aspose PDF's Document class for PDF operations | ||
import aspose.pdf as ap # Import Aspose PDF module for additional functionality | ||
|
||
def fetch_web_content_as_stream(webpage_url): | ||
""" | ||
Fetches the content of a webpage and returns it as a byte stream. | ||
Parameters: | ||
webpage_url (str): The URL of the webpage to fetch. | ||
Returns: | ||
BytesIO: A byte stream of the webpage content. | ||
""" | ||
response = requests.get(webpage_url) # Send GET request to the specified URL | ||
response.raise_for_status() # Raise an error if the request fails | ||
return BytesIO(response.content) # Return the content as a byte stream | ||
|
||
def main(): | ||
""" | ||
Main function that converts a webpage into a PDF document. | ||
""" | ||
|
||
# Set Aspose.PDF license (assumes "license.lic" file is available) | ||
license = ap.License() | ||
license.set_license("license.lic") | ||
|
||
# Define the webpage URL to be converted | ||
webpage_url = "https://docs.aspose.com/" | ||
|
||
# Configure HTML-to-PDF conversion options | ||
pdf_options = ap.HtmlLoadOptions(webpage_url) # Create HTML load options with the webpage URL | ||
pdf_options.page_info.width = 1200 # Set PDF page width | ||
pdf_options.page_info.height = 850 # Set PDF page height | ||
|
||
# Fetch webpage content as a byte stream | ||
with fetch_web_content_as_stream(webpage_url) as web_stream: | ||
|
||
# Uncomment the lines below to print and inspect the webpage content | ||
# print(web_stream.read().decode('utf-8', errors='ignore')) | ||
# web_stream.seek(0) # Reset the stream position after reading | ||
|
||
# Create a PDF document from the webpage stream | ||
pdf_document = Document(web_stream, pdf_options) | ||
|
||
# Save the converted PDF document | ||
pdf_document.save("Converted_WebPage.pdf") | ||
|
||
print("URL converted to PDF successfully") | ||
|
||
# Run the main function if the script is executed directly | ||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
//date: 2025-02-04T16:44:18Z | ||
//url: https://api.github.com/gists/e4cd1a83fbe7f5d3ae2d9d425940bcb9 | ||
//owner: https://api.github.com/users/samuelGH2006 | ||
|
||
public class HolaMundo{ | ||
public static void main(string[] args) { | ||
System.out.println("holaMundo"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
#date: 2025-02-04T17:10:33Z | ||
#url: https://api.github.com/gists/5f2c7bf8062fa7d5e820ee1729859c2b | ||
#owner: https://api.github.com/users/stefaniasif | ||
|
||
import numpy as np | ||
import matplotlib.pyplot as plt | ||
import initialize_state_vector as isv | ||
import Load_parameters as lp | ||
|
||
|
||
def Plot_currents(t,x): | ||
|
||
# theta | ||
theta = lp.omega_0 * t | ||
|
||
inv_LD_mat = np.linalg.inv(lp.LD_mat) | ||
inv_LQ_mat = np.linalg.inv(lp.LQ_mat) | ||
|
||
# d-axis currents, e = L*i, i = inv.L * e | ||
x_d = np.vstack((x[0,:], x[2,:], x[3,:])) | ||
i_d_fd_kd = inv_LD_mat.dot(x_d) | ||
|
||
# q-axis currents | ||
x_q = np.vstack((x[1,:], x[4,:])) | ||
i_q_kq = inv_LQ_mat.dot(x_q) | ||
|
||
|
||
# Stator phase currents | ||
|
||
#dq0_inverse = np.array([ | ||
# [np.cos(theta), -np.sin(theta), 1], | ||
# [np.cos(theta - 2*np.pi/3), -np.sin(theta - 2*np.pi/3), 1], | ||
# [np.cos(theta + 2*np.pi/3), -np.sin(theta + 2*np.pi/3), 1] | ||
#]) | ||
|
||
#i_dq0 = np.vstack((i_d, i_q, i_0)) | ||
#i_abc = dq0_inverse.dot(i_dq0) | ||
|
||
# abc stator phase currents after inverse dq0-transformation, i0 = 0 for three phase fault | ||
i_a = np.cos(theta) * i_d_fd_kd[0,:] - np.sin(theta) * i_q_kq[0,:] | ||
i_b = np.cos(theta - 2*np.pi/3) * i_d_fd_kd[0,:] - np.sin(theta - 2*np.pi/3) * i_q_kq[0,:] | ||
i_c = np.cos(theta + 2*np.pi/3) * i_d_fd_kd[0,:] - np.sin(theta + 2*np.pi/3) * i_q_kq[0,:] | ||
|
||
|
||
|
||
|
||
|
||
# Plot results | ||
plt.figure(figsize=(10, 6)) | ||
|
||
# Plot field winding current | ||
plt.subplot(3, 1, 1) | ||
plt.plot(t, i_d_fd_kd[1,:], label=r'$i_{fd}$', color='blue') | ||
plt.xlabel('Time (s)') | ||
plt.ylabel('Current (pu)') | ||
plt.title('Field Winding Current') | ||
plt.legend() | ||
plt.grid() | ||
|
||
## Plot abc stator phase currents | ||
plt.subplot(3, 1, 2) | ||
plt.plot(t, i_a, label=r'$i_a$', color='r') | ||
plt.plot(t, i_b, label=r'$i_b$', color='g') | ||
plt.plot(t, i_c, label=r'$i_c$', color='b') | ||
plt.xlabel('Time (s)') | ||
plt.ylabel('Current (pu)') | ||
plt.title('Stator Phase Currents') | ||
plt.legend() | ||
plt.grid() | ||
|
||
# Plot damper winding currents | ||
plt.subplot(3, 1, 3) | ||
plt.plot(t, i_d_fd_kd[2,:], label=r'$i_{kd}$', color='purple') | ||
plt.plot(t, i_q_kq[1,:], label=r'$i_{kq}$', color='orange') | ||
plt.xlabel('Time (s)') | ||
plt.ylabel('Current (pu)') | ||
plt.title('Damper Winding Currents') | ||
plt.legend() | ||
plt.grid() | ||
|
||
#plt.tight_layout() | ||
plt.show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,178 @@ | ||
//date: 2025-02-04T17:05:45Z | ||
//url: https://api.github.com/gists/02981d86fcf5e6614c0ebf917a44949a | ||
//owner: https://api.github.com/users/yadnyeshkolte | ||
|
||
import org.telegram.telegrambots.bots.TelegramLongPollingBot; | ||
import org.telegram.telegrambots.meta.api.methods.send.SendMessage; | ||
import org.telegram.telegrambots.meta.api.objects.Update; | ||
import java.util.ArrayList; | ||
import java.util.Random; | ||
|
||
public class TelegramATMBot extends TelegramLongPollingBot { | ||
private static final String BOT_TOKEN = "**********" | ||
private static final String BOT_USERNAME = "your_bot_username"; | ||
|
||
// Account Management Variables | ||
private double accountBalance = 15000.0; | ||
private List<Double> transactions = new ArrayList<>(); | ||
private int[] denominations = {200, 100, 50}; | ||
private int[] notesLeft = {5, 10, 10}; | ||
private boolean isAuthorized = false; | ||
|
||
@Override | ||
public void onUpdateReceived(Update update) { | ||
if (update.hasMessage() && update.getMessage().hasText()) { | ||
String messageText = update.getMessage().getText(); | ||
long chatId = update.getMessage().getChatId(); | ||
|
||
switch (messageText) { | ||
case "/start": | ||
sendWelcomeMessage(chatId); | ||
break; | ||
case "/login": | ||
handleLogin(chatId); | ||
break; | ||
case "/withdraw": | ||
handleWithdraw(chatId, update); | ||
break; | ||
case "/deposit": | ||
handleDeposit(chatId, update); | ||
break; | ||
case "/balance": | ||
checkBalance(chatId); | ||
break; | ||
case "/transactions": | ||
viewTransactions(chatId); | ||
break; | ||
} | ||
} | ||
} | ||
|
||
private void sendWelcomeMessage(long chatId) { | ||
String welcome = "Welcome to ATM Bot!\n" + | ||
"Available Commands:\n" + | ||
"/login - Authenticate\n" + | ||
"/withdraw - Withdraw Money\n" + | ||
"/deposit - Deposit Money\n" + | ||
"/balance - Check Balance\n" + | ||
"/transactions - View History"; | ||
sendMessage(chatId, welcome); | ||
} | ||
|
||
private void handleLogin(long chatId) { | ||
// Generate OTP | ||
int otp = generateOTP(); | ||
sendMessage(chatId, "Your OTP is: " + otp); | ||
// Implement OTP verification mechanism | ||
} | ||
|
||
private int generateOTP() { | ||
return new Random().nextInt(9000) + 1000; | ||
} | ||
|
||
private void handleWithdraw(long chatId, Update update) { | ||
if (!isAuthorized) { | ||
sendMessage(chatId, "Please login first!"); | ||
return; | ||
} | ||
|
||
// Implement amount input and validation | ||
double amount = extractAmount(update); | ||
|
||
if (amount % 100 != 0) { | ||
sendMessage(chatId, "Invalid amount. Must be multiple of 100."); | ||
return; | ||
} | ||
|
||
if (amount > accountBalance) { | ||
sendMessage(chatId, "Insufficient funds!"); | ||
return; | ||
} | ||
|
||
// Process withdrawal | ||
processWithdrawal(chatId, amount); | ||
} | ||
|
||
private void processWithdrawal(long chatId, double amount) { | ||
accountBalance -= amount; | ||
transactions.add(-amount); | ||
|
||
// Note dispensing logic | ||
double remainingAmount = amount; | ||
for (int i = 0; i < denominations.length; i++) { | ||
while (notesLeft[i] > 0 && remainingAmount >= denominations[i]) { | ||
remainingAmount -= denominations[i]; | ||
notesLeft[i]--; | ||
} | ||
} | ||
|
||
sendMessage(chatId, "Withdrawn: " + amount + | ||
"\nRemaining Balance: " + accountBalance); | ||
} | ||
|
||
private void handleDeposit(long chatId, Update update) { | ||
if (!isAuthorized) { | ||
sendMessage(chatId, "Please login first!"); | ||
return; | ||
} | ||
|
||
double amount = extractAmount(update); | ||
|
||
if (amount % 100 != 0) { | ||
sendMessage(chatId, "Invalid amount. Must be multiple of 100."); | ||
return; | ||
} | ||
|
||
accountBalance += amount; | ||
transactions.add(amount); | ||
sendMessage(chatId, "Deposited: " + amount + | ||
"\nNew Balance: " + accountBalance); | ||
} | ||
|
||
private void checkBalance(long chatId) { | ||
if (!isAuthorized) { | ||
sendMessage(chatId, "Please login first!"); | ||
return; | ||
} | ||
sendMessage(chatId, "Current Balance: " + accountBalance); | ||
} | ||
|
||
private void viewTransactions(long chatId) { | ||
if (!isAuthorized) { | ||
sendMessage(chatId, "Please login first!"); | ||
return; | ||
} | ||
|
||
StringBuilder transactionHistory = new StringBuilder("Transaction History:\n"); | ||
for (int i = 0; i < transactions.size(); i++) { | ||
transactionHistory.append("#") | ||
.append(i + 1) | ||
.append(": ") | ||
.append(transactions.get(i)) | ||
.append("\n"); | ||
} | ||
sendMessage(chatId, transactionHistory.toString()); | ||
} | ||
|
||
private void sendMessage(long chatId, String text) { | ||
SendMessage message = new SendMessage(); | ||
message.setChatId(String.valueOf(chatId)); | ||
message.setText(text); | ||
try { | ||
execute(message); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
@Override | ||
public String getBotUsername() { | ||
return BOT_USERNAME; | ||
} | ||
|
||
@Override | ||
public String getBotToken() { | ||
return BOT_TOKEN; | ||
} | ||
} } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#date: 2025-02-04T17:08:02Z | ||
#url: https://api.github.com/gists/2873d5a9615400c089a4dad44116fe6a | ||
#owner: https://api.github.com/users/docsallover | ||
|
||
from abc import ABC, abstractmethod | ||
|
||
class Shape(ABC): | ||
@abstractmethod | ||
def area(self): | ||
pass | ||
|
||
class Circle(Shape): | ||
# ... implementation of area() method ... | ||
|
||
class Rectangle(Shape): | ||
# ... implementation of area() method ... |
Oops, something went wrong.