Skip to content

Instantly share code, notes, and snippets.

View agerwick's full-sized avatar

Ronny Ager-Wick agerwick

View GitHub Profile
@agerwick
agerwick / pandas_pyspark_dataframe_syntax_comparison.txt
Created March 11, 2024 14:09
Pandas Dataframe --> Apache Spark Dataframe
Syntax comparison between Pandas and Apache Spark Dataframes
Creating DataFrames:
Pandas:
pd.DataFrame(data=None, index=None, columns=None, dtype=None, copy=False)
Spark:
spark.createDataFrame(data, schema=None, samplingRatio=None, verifySchema=True)
Aggregation and Grouping:
Pandas:
@agerwick
agerwick / gist:60bb891d0385168f5027c4efd9481888
Created May 12, 2016 13:17
creating encrypted lvm partitions
First, create an ext4 /boot partition (sda1), and an empty partition for encrypted LVM (sda2)
ubuntu-mate@ubuntu-mate:~$ sudo cryptsetup luksFormat /dev/sd
sda sda1 sda2 sdb sdb1
ubuntu-mate@ubuntu-mate:~$ sudo cryptsetup luksFormat /dev/sda2
WARNING!
========
This will overwrite data on /dev/sda2 irrevocably.
@agerwick
agerwick / test.txt
Created November 9, 2014 10:10
Can't access methods within a Sinatra::Base class
$ irb
2.0.0-p353 :001 > require 'sinatra/base'
=> true
2.0.0-p353 :002 > class PlainClass
2.0.0-p353 :003?> def say_cheese
2.0.0-p353 :004?> "cheese"
2.0.0-p353 :005?> end
2.0.0-p353 :006?> end
=> nil
2.0.0-p353 :007 > class SinatraClass < Sinatra::Base
@agerwick
agerwick / copy-files-matching-pattern-preserving-path.sh
Last active December 18, 2015 16:29
Bash script for copying all files in a directory tree matching one or more specified patterns (such as *.txt) to another tree, creating any directories not already existing. Copies only the path below the source directory to the destination.
#!/bin/bash
# copy-files-matching-pattern-preserving-path
# Bash script for copying all files in a directory tree matching one or more specified patterns (such as *.txt) to another tree, creating any directories not already existing.
# Copies only the path below the source directory, and only creates directories with files matching the pattern.
# (c)2013 Ronny Ager-Wick, released under GPLv3
options=$1
if [[ "${options:0:1}" = "-" ]]; then
# first char is dash
if [[ "$options" = "-n" ]]; then
@agerwick
agerwick / esniper-script-collection
Last active December 14, 2015 23:58
Esniper script collection
Esniper script collection
Ever dreamt of importing esniper's logs to your spreadsheet? Wouldn't anybody dream of that? Well you don't have to dream any longer! This is a collection of esniper related scripts, which I'm releasing under GPL v.3.0.
Prerequisites:
Your esniper auction files are in ~/esniper-auctions (any temporary ones can be kept in subdirectories) and have .esniper as extension.
All these scripts are in the same directory.
You have a ~/.esniper-logs directory for the log files used by these routines (note the leading dot).
How it works:
@agerwick
agerwick / subclasses.rb
Last active December 14, 2015 22:29
Listing all subclasses of a class, excluding the class itself. This is useful for listing all Models of a database adapter, such as Ohm::Model.subclasses and ActiveRecord::Base.subclasses .
class Class
def subclasses
class_hash = {}
ObjectSpace.each_object do |obj|
if Class == obj.class
# remove first item from ancestors, which is the class itself - it's wrong to say a class is a subclass of itself
if obj.ancestors[1..-1].include? self
class_hash[obj] = true
end
end
@agerwick
agerwick / find-my-ip-address
Created October 29, 2012 00:43
command line tool for finding your public IP address
#!/bin/sh
dig myip.opendns.com @resolver1.opendns.com +short
@agerwick
agerwick / rsymlink
Created October 28, 2012 16:34
rsymlink - recursively create symlinks with relative paths