Skip to content

Instantly share code, notes, and snippets.

@karpanGit
karpanGit / pyspark, reverse the order of a dataframe.py
Created July 23, 2021 05:51
pyspark, reverse the order of a dataframe
# revert the order of a dataframe
from pyspark.sql import SparkSession
import pyspark.sql.functions as f
# create spark session
spark = SparkSession.builder.appName('some name').getOrCreate()
# create a frame
df = spark.createDataFrame([('a',12), ('c',10), ('b',9)], ['col1', 'col2'])
df.show()
@smurching
smurching / parent-and-child-runs.py
Last active February 29, 2024 13:30
creating-child-runs-in-mlflow
import mlflow
# There are two ways to create parent/child runs in MLflow.
# (1) The most common way is to use the fluent
# mlflow.start_run API, passing nested=True:
with mlflow.start_run():
num_trials = 10
mlflow.log_param("num_trials", num_trials)
best_loss = 1e100
@mazzma12
mazzma12 / kml_io.py
Last active February 22, 2024 17:01
IO / Read and write KML file with geopandas and fiona driver
import fiona
import geopandas as gpd
# Enable fiona driver
gpd.io.file.fiona.drvsupport.supported_drivers['KML'] = 'rw'
# Read file
df = gpd.read_file(path, driver='KML')
# Write file
@bschwartz757
bschwartz757 / async.js
Last active November 15, 2023 03:23
Async/await function to fetch data from multiple URLs in parallel
/* Client side, works in Chrome 55 and Firefox 52 without transpilation */
//https://blogs.msdn.microsoft.com/typescript/2016/11/08/typescript-2-1-rc-better-inference-async-functions-and-more/
async function fetchURLs() {
try {
// Promise.all() lets us coalesce multiple promises into a single super-promise
var data = await Promise.all([
/* Alternatively store each in an array */
// var [x, y, z] = await Promise.all([
// parse results as json; fetch data response has several reader methods available:
//.arrayBuffer()
@NlsNi
NlsNi / mail.py
Created February 15, 2017 01:30
send rich text email with python
import smtplib
from email.mime.text import MIMEText
from email.header import Header
def mail(htm):
sender = 'sender@163.com'
receiver = 'receiver@163.com'
subject = 'test'
smtpserver = 'smtp.163.com'
username = 'sender@163.com'
@drmalex07
drmalex07 / setup-example-custom-command.py
Last active December 6, 2022 22:00
Provide a custom setuptools command. #setuptools #distutils #setup.py
from setuptools import setup, find_packages
from distutils.cmd import Command
class Foo(Command):
description = "Run foo command"
user_options = [
('baz=', None, 'Baz Option'),
#!/bin/sh
#
## Making a local repository
#
PKGS_DIR=/home/linuxluser/pkgs/
BASE_DIR=/tmp/repo
SUITE=jessie
COMPONENT=main
@MattDMo
MattDMo / ipy_repl.py
Last active April 3, 2022 23:16
SublimeREPL ipy_repl.py for running IPython/Jupyter in Sublime Text
# from https://gist.github.com/MattDMo/6cb1dfbe8a124e1ca5af
import os
import json
import socket
import threading
activate_this = os.environ.get("SUBLIMEREPL_ACTIVATE_THIS", None)
# turn off pager
@abtrout
abtrout / pass.md
Created July 8, 2014 14:51
Using password-store with git repository synching

Password-store keeps your passwords (or any other sensitive information) saved in GnuPG encrypted files organized in ~/.password-store. For more information about GPG, consult the GNU Privacy Handbook.

Getting started

To get started, install pass and generate a keypair.

$ brew install pass
$ gpg --gen-key
$ gpg --list-keys
@driscollis
driscollis / gist:a42aecb379742d3cd150
Created June 13, 2014 13:36
wxPython ScrolledPanel Example
import wx
import wx.lib.scrolledpanel as scrolled
########################################################################
class MyForm(wx.Frame):
#----------------------------------------------------------------------
def __init__(self):
wx.Frame.__init__(self, None, wx.ID_ANY, "Tutorial", size=(200,500))