Skip to content

Instantly share code, notes, and snippets.

@jlollis
jlollis / python_lists.py
Created March 22, 2019 04:56
Python list basics
# Create an empty list using square brackets.
numbers = []
print(numbers) # Output: []
# Create an empty list using list().
numbers = list()
print(numbers) # Output: []
# Create a list of numbers.
numbers = [1, 2, 3]
@jlollis
jlollis / python_sets.py
Created March 22, 2019 04:54 — forked from ShyamaSankar/python_sets.py
A cheat sheet for Python sets.
# Create an empty set using the constructor method.
numbers = set()
print(numbers) # Output: set()
# Note: {} creates a dictionary in Python.
print(type({})) # Output: <class 'dict'>
# set() constructor function takes an iterable as input.
numbers = set([1, 2])
print(numbers) # Output: {1, 2}
string_set = set("hello")
@jlollis
jlollis / python_tuples.py
Created March 22, 2019 04:54 — forked from ShyamaSankar/python_tuples.py
Cheat sheet for Python tuples
#### Tuple creation #####
# Create a tuple, also called tuple packing.
numbers = 1, 2
print(numbers) # Output: (1, 2) <- Note that it is represented with an enclosing paranthesis
# Create tuple with paranthesis.
numbers = (1, 2, 3)
print(numbers) # Output: (1, 2, 3)
# Create an empty tuple.
numbers = ()
print(numbers) # Output: ()
@jlollis
jlollis / fish.sim
Created March 21, 2019 05:12 — forked from sinclairtarget/fish.sim
Simula Demonstration
Simulation Begin
! We will use this as input to Normal() below ;
Integer seed;
! Utility method for logging messages along with the current simulation
time ;
Procedure log(message); Text message; Begin
OutFix(Time, 2, 0);
OutText(": " & message);
OutImage;
@jlollis
jlollis / 01. Gemfile
Created March 1, 2019 11:02 — forked from schleg/01. Gemfile
Setup for Devise + Omniauth
gem 'pg'
group :development do
gem 'ruby-debug'
end
gem 'rake', '~> 0.8.7'
gem 'devise'
gem 'oa-oauth', :require => 'omniauth/oauth'
gem 'omniauth'
gem 'haml'
gem 'dynamic_form'
@jlollis
jlollis / keypress.rb
Created February 21, 2019 16:30 — forked from acook/keypress.rb
Read keypresses from user in terminal, including arrow keys using pure Ruby. This has since been folded into a much more robust gem called Remedy. https://rubygems.org/gems/remedy & https://github.com/acook/remedy
require 'io/console'
# Reads keypresses from the user including 2 and 3 escape character sequences.
def read_char
STDIN.echo = false
STDIN.raw!
input = STDIN.getc.chr
if input == "\e" then
input << STDIN.read_nonblock(3) rescue nil
@jlollis
jlollis / gist:d70f3759fccf95dffa1f4b130c5104b4
Created February 19, 2019 20:11 — forked from nicc/gist:667755
Ruby's Enumerable #map and #select methods implemented with #inject
# The idea is just to illustrate that Ruby's #map and #select Enumerable methods
# are simply specific flavours of a fold operation, which Ruby implements as #inject.
# I've implemented #map and #select using #inject, and at the end I implemented #inject
# recursively. Ruby does #inject with Array#each, for very good reason. The recursive
# implementation is really just to illustrate the core Functional Programming concept
# which it derives from.
# We'll start simple. Map without applying a function:
[1,2,3,4,5].inject([]) {|memo, obj| memo << obj }
@jlollis
jlollis / Wolf
Created February 19, 2019 05:28
Play the Orginal Wolfenstein 3D on Linux
#!/bin/bash
sudo apt-get update
sudo apt-get install dosbox wget
mkdir -p wolf3d
cd wolf3d
wget http://image.dosgamesarchive.com/games/1wolf14.zip
unzip *.zip
dosbox INSTALL.EXE
echo "After setup cd into the new wolf3d directory"
@jlollis
jlollis / Wolf
Created February 19, 2019 05:28
Play the Orginal Wolfenstein 3D on Linux
#!/bin/bash
sudo apt-get update
sudo apt-get install dosbox wget
mkdir -p wolf3d
cd wolf3d
wget http://image.dosgamesarchive.com/games/1wolf14.zip
unzip *.zip
dosbox INSTALL.EXE
echo "After setup cd into the new wolf3d directory"
@jlollis
jlollis / Merge-PDF.ps1
Created January 13, 2019 02:35 — forked from aaroncalderon/Merge-PDF.ps1
Merge PDFs with PowerShell
#Not my code, this is from Mike Pfeiffer - http://mikepfeiffer.net/2010/03/how-to-merge-pdf-files-using-powershell-and-pdfsharp/
#Requires PDFSharp assembly libraries http://sourceforge.net/projects/pdfsharp/
#You need to load the assembly before you can use the function
#
#Merge-PDF -path c:\pdf_docs -filename c:\saved_docs.pdf
Add-Type -Path C:\assemblies\PdfSharp.dll
Function Merge-PDF {