Skip to content

Instantly share code, notes, and snippets.

View kastnerp's full-sized avatar
:octocat:
Focusing

Patrick Kastner kastnerp

:octocat:
Focusing
View GitHub Profile
@kastnerp
kastnerp / gist:c5f079b2f396dd7d7e91a00528d00a58
Created July 6, 2019 13:01
DataTree to List of Lists (works only in scripting component)
public static List<List<T>> ToListOfLists<T>(DataTree<T> tree)
{
List<List<T>> list = new List<List<T>>();
foreach (List<T> b in tree.Branches)
{
list.Add(b);
}
return list;
}
@kastnerp
kastnerp / .htaccess
Created August 4, 2019 14:15 — forked from ScottPhillips/.htaccess
Common .htaccess Redirects
#301 Redirects for .htaccess
#Redirect a single page:
Redirect 301 /pagename.php http://www.domain.com/pagename.html
#Redirect an entire site:
Redirect 301 / http://www.domain.com/
#Redirect an entire site to a sub folder
Redirect 301 / http://www.domain.com/subfolder/
@kastnerp
kastnerp / .htaccess
Created August 4, 2019 14:15 — forked from ScottPhillips/.htaccess
Common .htaccess Redirects
#301 Redirects for .htaccess
#Redirect a single page:
Redirect 301 /pagename.php http://www.domain.com/pagename.html
#Redirect an entire site:
Redirect 301 / http://www.domain.com/
#Redirect an entire site to a sub folder
Redirect 301 / http://www.domain.com/subfolder/
@kastnerp
kastnerp / residuals.py
Last active February 27, 2022 19:44
Plotting OpenFOAM residuals with Python
# https://bit.ly/plot-openfoam-residuals
import pandas as pd
import matplotlib.pyplot as plt
data = pd.read_csv("residuals.dat",skiprows=1, delimiter='\s+').iloc[:, 1:].shift(+1,axis=1).drop(["Time"], axis= 1)
plot = data.plot(logy= True, figsize=(15,5))
fig = plot.get_figure()
ax = plt.gca()
ax.legend(loc='upper right')
ax.set_xlabel("Iterations")
@kastnerp
kastnerp / call_w_conda.bat
Last active June 28, 2020 19:56
Source Anaconda environment and call Python script
call C:\ProgramData\Anaconda3\Scripts\activate.bat C:\ProgramData\Anaconda3
python residuals.py
@kastnerp
kastnerp / list_to_tree.py
Created August 27, 2020 16:04 — forked from piac/list_to_tree.py
Transforms DataTrees in Grasshopper to nestings of lists, and vice versa
def list_to_tree(input, none_and_holes=True, source=[0]):
"""Transforms nestings of lists or tuples to a Grasshopper DataTree"""
from Grasshopper import DataTree as Tree
from Grasshopper.Kernel.Data import GH_Path as Path
from System import Array
def proc(input,tree,track):
path = Path(Array[int](track))
if len(input) == 0 and none_and_holes: tree.EnsurePath(path); return
for i,item in enumerate(input):
if hasattr(item, '__iter__'): #if list or tuple
@kastnerp
kastnerp / pptx2pdf.bat
Created November 14, 2020 19:30
Windows script: Converting all *.pptx in a folder to *.pdf
REM https://stackoverflow.com/questions/45348197/convert-multiple-powerpoint-files-to-pdf-using-cmd
@if (@X)==(@Y) @end /* JScript comment
@echo off
cscript //E:JScript //nologo "%~f0" %*
exit /b %errorlevel%
@if (@X)==(@Y) @end JScript comment */
@kastnerp
kastnerp / area-projection-factor.ipynb
Created May 7, 2021 15:02
area-projection-factor
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@kastnerp
kastnerp / lambda_pandas.py
Last active May 21, 2021 03:41
Lambda function with pandas that takes two input which themselves are columns in the DataFrame
df = pd.DataFrame([[4, 9]] * 3, columns=['A', 'B'])
def do_stuff(x,y):
return x*y
df['new']= df.apply(lambda x: do_stuff(x['A'],x['B'] ), axis= 1)
print(df)
@kastnerp
kastnerp / Wordpress cronjobs with wp cron
Last active October 11, 2021 19:49
This automatically updates everything from themes, plugins, translations, etc.
# Type `crontab -e` and append this line and make sure to adapt your worpress path
0 3 * * * cd /var/www/virtual/$USER/html/wordpress/; wp cron event run --all >/dev/null 2>&1