Skip to content

Instantly share code, notes, and snippets.

View rudrathegreat's full-sized avatar
🎥
Running a YouTube Channel!

Rudra Sekhri rudrathegreat

🎥
Running a YouTube Channel!
View GitHub Profile
@lambdamusic
lambdamusic / Snipplr-25250.py
Created February 7, 2013 21:26
Python: Python: error handling
## Error handling in Python is done through the use of exceptions that are caught in try blocks and handled in except blocks. If an error is encountered, a TRy block code execution is stopped and transferred down to the except block, as shown in the following syntax:
try:
f = open("test.txt")
except IOError:
print "Cannot open file."
## In addition to using an except block after the try block, you can also use the finally block. The code in the finally block will be executed regardless of whether an exception occurs.
f = open("test.txt")
@jednano
jednano / gitcom.md
Last active May 31, 2023 08:23
Common git commands in a day-to-day workflow

Git Cheat Sheet

Initial Setup

Create an empty git repo or reinitialize an existing one

git init
@itsmattsoria
itsmattsoria / gistfil1.textile
Last active July 3, 2024 05:36
Mac Terminal Cheat Sheet

SHORTCUTS

Key/Command Description
Tab Auto-complete files and folder names
Ctrl + A Go to the beginning of the line you are currently typing on
Ctrl + E Go to the end of the line you are currently typing on
Ctrl + U Clear the line before the cursor
Ctrl + K Clear the line after the cursor
Ctrl + W Delete the word before the cursor
Ctrl + T Swap the last two characters before the cursor
@Overdrivr
Overdrivr / Plot.py
Created February 4, 2016 13:38
PyQtGraph animated sine and cosine functions - real smooth
# -*- coding: utf-8 -*-
from pyqtgraph.Qt import QtGui, QtCore
import numpy as np
from numpy import arange, sin, cos, pi
import pyqtgraph as pg
import sys
class Plot2D():
def __init__(self):
self.traces = dict()
@CMCDragonkai
CMCDragonkai / Matplotlib Backends.md
Last active February 12, 2023 13:22
Matplotlib Backends #matplotlib #python

Matplotlib Backends

Matplotlib is a plotting library. It relies on some backend to actually render the plots. The default backend is the agg backend. This backend only renders PNGs. On Jupyter notebooks the matplotlib backends are special as they are rendered to the browser. Generally you will not need to explicitly set the backend on a Jupyter notebook. This does introduce a discrepancy between code that runs in Jupyter and code that runs as a script natively in the Python interpreter. So you need to understand that the 2 environments are not the same

@akey7
akey7 / numpy_array_to_wav_file.py
Created March 31, 2018 02:55
Generate a .wav sound file from a NumPy array.
import numpy as np
from scipy.io.wavfile import write
# Samples per second
sps = 44100
# Frequency / pitch of the sine wave
freq_hz = 440.0
# Duration
@akey7
akey7 / sine_animation.py
Created May 3, 2018 16:14
PY: Animated GIF for sine wave
# See for tiao.io/posts/notebooks/save-matplotlib-animations-as-gifs/ more information and notes below
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import animation, rc
from IPython.display import HTML, Image
# equivalent to rcParams['animation.html'] = 'html5'
rc('animation', html='html5')
fig, ax = plt.subplots()
@akey7
akey7 / find_mode.py
Created October 19, 2018 02:42
Mode finding's in Python lists
def mode(xs):
"""
This returns the mode of the values in xs. xs is a standard
Python list with discrete values, which can be of any hashable
value.
Fo this problem, think about using a dictionary in some way.
What could be the keys? The values? Also remember that dictionaries
are UNORDERED--in other words, there is no guaranteed order.
@akey7
akey7 / find_median.py
Created October 19, 2018 02:44
Find a median in a Pyton list of integers or floats
def median(xs):
"""
When given a standard Python list of numbers, this function will
return the median value. There are a few cases to consider:
1. xs is an empty list: return None
2. A list with one element: returns that element
3. A list with an odd number of elements: Returns the middle value.
@honux77
honux77 / ec2-slack-user-data.sh
Last active November 24, 2018 05:42
slack + AWS example
#!/bin/bash
# put this in ec2 ubuntu user-data
mkdir /home/ubuntu/script/
cat <<'EOF' >> /home/ubuntu/script/slack.sh
#!/bin/bash
ip=`/usr/bin/curl -s -w '\n' http://169.254.169.254/latest/meta-data/public-ipv4`
instance=`/usr/bin/curl -s -w '\n' http://169.254.169.254/latest/meta-data/instance-id`