Skip to content

Instantly share code, notes, and snippets.

@nickyfoto
nickyfoto / ffmpeg.md
Created April 25, 2021 02:19 — forked from steven2358/ffmpeg.md
FFmpeg cheat sheet
@nickyfoto
nickyfoto / double_for_loop.py
Created January 26, 2020 21:44
one line double for loop in python
r = []
for i in range(1, 6):
for j in range(7, 9):
r.append((i, j))
print(r)
print(list((i, j) for i in range(1, 6) for j in range(7,9)))
# [(1, 7), (1, 8), (2, 7), (2, 8), (3, 7), (3, 8), (4, 7), (4, 8), (5, 7), (5, 8)]
# [(1, 7), (1, 8), (2, 7), (2, 8), (3, 7), (3, 8), (4, 7), (4, 8), (5, 7), (5, 8)]
@nickyfoto
nickyfoto / plot_emoji.py
Last active April 26, 2024 10:52
example using plotly to plot emojis
# sample example using plotly to plot emojis
import plotly.express as px
import pandas as pd
d = {"1": ["😀", "🥰", "😗"],
"2": [1,2,3]
}
px.scatter(pd.DataFrame(d), x="1", y="2")
@nickyfoto
nickyfoto / notebook_to_md
Created November 15, 2019 18:07
jupyter to markdown command
convert ipynb to md
jupyter nbconvert --to markdown /path/to/example_notebook.ipynb
append md to post.md
cat example_notebook.md | tee -a exampleblog/_posts/YYYY-MM-DD-example-post.md
@nickyfoto
nickyfoto / s.py
Created October 14, 2019 15:17
Python set operation
# https://www.geeksforgeeks.org/python-set-operations-union-intersection-difference-symmetric-difference/
A = {0, 2, 4, 6, 8}
B = {1, 2, 3, 4, 5}
# union
print("Union :", A | B)
# intersection
print("Intersection :", A & B)
@nickyfoto
nickyfoto / LIS.py
Created April 26, 2019 01:40
Length of Longest Increasing Subsequence
def LIS(a):
"""Longest Increasing Subsequences"""
L = [1] * len(a)
for i in range(len(a)):
for j in range(i):
if a[j] < a[i] and L[i] < 1+L[j]:
L[i] = 1 + L[j]
return max(L)
a = [5,7,4,-3,9,1,10,4,5,8,9,3]
LIS(a)
@nickyfoto
nickyfoto / fibM.py
Created April 25, 2019 15:01
Calculate nth Fibonacci number using memoization
def fibM(n, d={0: 0, 1: 1}):
"""Memoization Fib"""
if n-2 in d and n-1 in d:
return d[n-2] + d[n-1]
else:
d[n-1] = d[n-3] + d[n-2]
return fibM(n-1, d)
fib(25)
@nickyfoto
nickyfoto / fibD.py
Last active April 25, 2019 14:42
Dynamically calculate nth Fibonacci number
def fibD(n):
"""DP Fib"""
f = [0, 1]
for i in range(2, n+1):
f.append(f[i-2]+f[i-1])
return f[n]
fib(25)
@nickyfoto
nickyfoto / fibR.py
Last active April 25, 2019 14:32
Recursively calculate nth Fibonacci number
def fibR(n):
"""recursive fib"""
if n == 0:
return 0
if n == 1:
return 1
return fibR(n-1) + fibR(n-2)
fibR(25)
@nickyfoto
nickyfoto / efs.md
Last active April 24, 2019 16:41
ubuntu mount efs