JDK 15.0.1, 11.0.9, 8u271, and 7u281 Have Been Released!
The Java SE 15.0.1, 11.0.9, 8u271, and 7u281 update releases are now available. You can download the latest JDK releases from the Java SE Downloads page. OpenJDK 15.0.1 is available on http://jdk.java.net/15/. New Features, Changes, and Notable Bug Fixes For information about the new features, chang...
Posted by: xSicKxBot - 12-19-2022, 10:32 AM - Forum: Python
- No Replies
This is How I Played a Sinus Tone in My Jupyter Notebook (Python)
5/5 – (1 vote)
What/Why? I want to write a simple Python script that warns me if crypto price data (e.g., BTC) crosses a certain threshold. This can be useful for trading or some other apps, so I thought it would be fun to do it.
The tutorial in front of you simply documents my learnings on creating a sinus tone in my Jupyter Notebook—so it may benefit you as well.
If you want the whole tutorial on my mini project, you can check it out here on the Finxter blog:
Challenge: Write Python code in a Jupyter Notebook that creates a sinus tone when executed.
Solution
The easy way to solve this challenge is the following.
This code creates a sine wave with a frequency of 500 Hz and plays it in the IPython environment. The wave is created using the NumPy library by specifying the frequency and the length of the wave (15000*2). The rate of the wave is set to 10000 Hz and autoplay is set to True so that the wave will start playing immediately.
import numpy as np
from IPython.display import Audio # Create the tone as a NumPy Sinus Wave
wave = np.sin(2*np.pi*500*np.arange(15000*2)/15000) # Play the Sinus Wave (tone)
Audio(wave, rate=10000, autoplay=True)
This generates the following beep sound in your Jupyter Notebook:
What happens if you change the rate argument of the Audio() function call to be 20000 instead of 10000?
# Play the Sinus Wave (tone)
Audio(wave, rate=20000, autoplay=True)
The beep sound tone gets higher:
You can play around with the Jupyter notebook here:
But what if you don’t have a Jupyter notebook but a normal Python script (Win/Linux/macOS)?
In that case, you cannot use the IPython library. Instead, follow the steps outlined in the following tutorial on the Finxter blog—you still can play beep sounds!
This game is free to keep if claimed by December 19, 2022 5:00 PM or in a day
- Click on the GET Button - Verify that the price is zero - Click on the Place Order Button - Thats it, the game will be added to you Epic Games Account
We are welcoming everyone to join our discord[discord.gg]. We are more active there on finding giveaways, small or large, and there are daily raffles you can participate.
Posted by: xSicKxBot - 12-19-2022, 10:30 AM - Forum: Lounge
- No Replies
Fortnite And My Hero Academia: How To Get Deku's Smash Mythic Weapon
My Hero Academia has arrived in Fortnite, and over the next two weeks, it's going to have a huge impact on how you play. That's because this collab isn't just about item shop cosmetics--though it certainly does have those. But on top of that, the island is now home to a new MHA-themed Mythic weapon: Deku's Smash.
Remember how the Kamehameha was basically a giant laser that would melt anything that you pointed it at--provided you could survive the lengthy charge-up time? The Deku's Smash is a pretty similar concept, with the main difference being that it's more like you're throwing a very large bomb.
The deepest, most intricate simulation of a world that's ever been created. The legendary Dwarf Fortress is now on Steam. Build a fortress and try to help your dwarves survive against a deeply generated world.
JDK 15 is live! Download it from the Java SE Downloads page. See the JDK 15 Release Notes for detailed information about this release. The following are some of the important additions and updates in Java SE 15 and JDK 15: Text Blocks, first previewed in Java SE 13, is a permanent feature in this re...
Posted by: xSicKxBot - 12-18-2022, 11:52 AM - Forum: Python
- No Replies
I Made a Python Script That Beeps When BTC or ETH Prices Drop
4.5/5 – (2 votes)
This tutorials shares my experience of creating a simple Python script that warns me if crypto price data (e.g., BTC or ETH) crosses a certain threshold.
Why would I need this? Well, the script can be useful for trading signals if I want to react quickly. While I don’t really trade, this script may be useful to time some buy or sell orders in a volatile market environment.
Besides — it’s fun and easy and quick, 5 minutes tops, so let’s just do it!
Challenge: I want to create a small Python script — that also works for Jupyter notebooks — to play a tone or warning signal as soon as Bitcoin or ETH price cross a certain threshold!
My Python Script if Crypto Prices Drop
This short clip shows you the tone it generates when BTC falls under a certain price — wait for the beep:
You can run the Bitcoin price warning script in your background in a separate browser tab in a Colab Jupyter Notebook (code below).
Okay, let’s build the code in three easy steps.
Step 1: Get Bitcoin, Ethereum, or Crypto Prices in Python
First, install the Historic Crypto library to access live cryptocurrency data.
Jupyter Notebook: !pip install Historic-CryptoShell or Terminal: pip install Historic-Crypto
Second, create a new object of the LiveCryptoData class, passing in the currency pair
'BTC-USD' for Bitcoin and USD
'ETH-USD' for Ethereum and USD
'BTC-ETH' for Bitcoin and Ethereum
Third, use the LiveCryptoData(...).return_data() method to return a DataFrame and store it in a variable called data.
from Historic_Crypto import LiveCryptoData
data = LiveCryptoData('BTC-USD').return_data()
print(data)
Output:
Collecting data for 'BTC-USD'
Checking if user supplied is available on the CoinBase Pro API...
Connected to the CoinBase Pro API.
Ticker 'BTC-USD' found at the CoinBase Pro API, continuing to extraction.
Status Code: 200, successful API call. ask bid volume \
time 2022-12-17 18:36:26.149769+00:00 16720.58 16720.56 28130.05026215 trade_id price size time 2022-12-17 18:36:26.149769+00:00 472092300 16720.58 0.0028569
Fourth, print the first element in the price Series, which represents the current price of Bitcoin in US Dollars. So to get the current price, I simply call:
print(data['price'][0])
# 16722.21
I’m sure the price is completely outdated when you read this.
Okay, now that I have the price data, I’ll create some code to create a warning tone.
Step 2: Play Sinus Tone in Jupyter Notebook
My goal is to play a tone — any audio signal, really — even when the Python script or Jupyter notebook is not in the foreground.
I decided on an audio signal rather than a popup because popups are more intrusive to my workflow, and they may “pop up” in the background without me even seeing it.
Also, I may want to walk around and get some coffee — and still be warned when BTC crosses my threshold!
How to create a sinus wave in a Jupyter Notebook in Python?
This code imports the NumPy library and the IPython.display library. It then creates a waveform with a frequency of 500 Hz and a duration of 2 seconds. The code then plays the waveform using the Audio() function from the IPython.display library. The rate is set to 10,000 Hz and autoplay is set to True so the sound will automatically play when the code is run.
import numpy as np
from IPython.display import Audio wave = np.sin(2*np.pi*500*np.arange(15000*2)/15000)
Audio(wave, rate=10000, autoplay=True)
Note that this code will only work in a Jupyter Notebook. To make a tone in any Python script, you can read the following tutorial on the Finxter blog:
Step 3: Putting It All Together in a Jupyter Notebook
The following script for Jupyter Notebooks runs forever until the current Bitcoin price drops below a user-defined threshold. If it does, it issues an audio wave sound that makes you aware of the event.
!pip install Historic-Crypto
from Historic_Crypto import LiveCryptoData
import numpy as np
from IPython.display import Audio
import time wave = np.sin(2*np.pi*500*np.arange(15000*2)/15000)
threshold = 16710 # usd per btc def get_price(): data = LiveCryptoData('BTC-USD', verbose=False).return_data() return float(data['price'][0]) print('Price warning below', threshold, 'USD per BTC')
print('Starting price', get_price(), 'USD per BTC') while get_price() > threshold: time.sleep(4) Audio(wave, rate=10000, autoplay=True)
You can change the threshold variable that is highlighted in the code above to control the price threshold that will cause the beep sound to play.
Try it yourself in my interactive Jupyter notebook here (Colab):
You can change the price data to Ethereum by using this function instead:
def get_price(): data = LiveCryptoData('ETH-USD', verbose=False).return_data() return float(data['price'][0])
In a similar manner, this will also work for other crypto tickers or trading pairs.
Thanks!
I loved having you here. Feel free to stay updated with all our programming projects and download your coding cheat sheets here:
[www.indiegala.com] ?Sometimes being the bad guy doesn't mean you are a bad guy?...other times you may be the worst calamity threatening the world, known as evil incarnate & a malevolent monster on par to demons. A new villainous eBook bundle is here.
Epic Games is giving away free games every week for a few years
To grab the game for free: Costume Quest 2 - 24 hours only https://store.epicgames.com/en-US/p/costume-quest-2 - Click on the GET Button - Verify that the price is zero - Click on the Place Order Button - Thats it, the game will be added to you Epic Games Account
We are welcoming everyone to join our discord[discord.gg]. We are more active there on finding giveaways, small or large, and there are daily raffles you can participate.