Skip to content

Instantly share code, notes, and snippets.

View vrootic's full-sized avatar
🏠
Working from home

Vic vrootic

🏠
Working from home
View GitHub Profile
@vrootic
vrootic / effective_python_item3.py
Created November 3, 2015 15:08
Know the Difference Between bytes, str, unicode.
# Python3: bytes(raw 8-bit values), str V.S. Python2: str(raw 8-bit values), unicode
# In Python3
def to_str(bytes_or_str):
if isinstance(bytes_or_str, bytes):
value = bytes_or_str.decode('utf-8')
else:
value = bytes_or_str
return value # Instance of str
@vrootic
vrootic / PySide installation issue
Created October 8, 2015 07:48
Solving PySide installation issue
If you encountered some installation issue, try to use `pyside_postinstall.py -install` to solve this issue.
@vrootic
vrootic / calculator.py
Last active August 29, 2015 14:22
Use PyQT to form a calculator
#!/usr/bin/env python
import sys
import calendar
import time
import math
from PyQt4.QtGui import *
from PyQt4.QtCore import *
total_x, total_y, total_yerr = draw_errorbar()
color = ['c', 'g', 'w', 'k']
label = ("1 day pattern", "1 week pattern", '2 weeks pattern', '3 weeks pattern')
hatch = ['', 'x', 'o', '/']
fig, ax = plt.subplots()
width = 0.2
widths = [-0.4, -0.2, 0, 0.2]
for i in range(4):
ax.bar(np.array(total_x[i]) + widths[i], total_y[i], width,
In [37]: a = iter(range(45))
In [38]: zip(*[a, a, a])
Out[38]:
[(0, 1, 2),
(3, 4, 5),
(6, 7, 8),
(9, 10, 11),
(12, 13, 14),
(15, 16, 17),
In [54]: a = [i for i in range(10)]
In [58]: zip(*[iter(a), iter(a), iter(a), iter(a), iter(a)])
Out[58]:
[(0, 0, 0, 0, 0),
(1, 1, 1, 1, 1),
(2, 2, 2, 2, 2),
(3, 3, 3, 3, 3),
(4, 4, 4, 4, 4),
(5, 5, 5, 5, 5),
(6, 6, 6, 6, 6),
#include <stdio.h>
#define SQUARE(a) (a * a)
int main() {
printf("%d\n", SQUARE(4));
int x = 3;
printf("%d\n", SQUARE(++x));
return 0;
}
#!/usr/bin/env python
import numpy as np
import pandas as pd
import data_generator as dg
def reduce_data():
result = []
for day in dg.group_data():
@vrootic
vrootic / gist:197a0716d92bbc74f420
Created September 30, 2014 10:31
RtlSdr Installation guide
1. brew install libusb
2. brew install librtlsdr
3. brew install python
4. pip install pyrtlsdr
5. pip install numpy
6. pip install pandas
7. git clone https://github.com/roger-/pyrtlsdr.git
8. cd pyrtlsdr && python demo_waterfall.py
@vrootic
vrootic / cdf.py
Created September 19, 2014 05:10
import numpy as np
import matplotlib.pyplot as plt
data = []
with open("output.txt", "r") as f:
for line in f.readlines():
data.append(float(line))
x = []