Skip to content

Instantly share code, notes, and snippets.

@solomon081
solomon081 / shape.rb
Created March 27, 2012 02:48
Shape Class
class Shape
def initialize(sides, perimiter, name)
@name = name
@sides = sides
@perimiter = perimiter
puts "Shape Name: #@name"
puts "Sides: #@sides"
puts "Perimiter: #@perimiter"
puts "Avg. Side Length: " + (@perimiter.to_i/@sides.to_i).to_s
if @sides.to_i < 3 or @perimiter.to_i <= 0
@solomon081
solomon081 / fdom.py
Created March 27, 2012 03:34
Five Days On Mars
#——————————————————#
#/////////\\\\\\\\\#
#/|-Solomon Wise-|\#
#/|-Do Not Steal-|\#
#\\\\\\\\\/////////#
#——————————————————#
# Imports modules
from random import randint, choice
from os import system
import platform
@solomon081
solomon081 / profile.rb
Created March 28, 2012 19:50
Ruby Profile
require 'ostruct'
profile = OpenStruct.new
BEGIN {puts "This program generates a profile for you."}
END {puts "Name: #{profile.name}"
puts "Description: #{profile.desc}"
puts "Gender: #{profile.gender}"
puts "Age: #{profile.age}"
puts "I Live in: #{profile.live}"
puts "I was born in: #{profile.born}"
@solomon081
solomon081 / dtlog.py
Created March 29, 2012 22:11
DateTime Error Log
def logtime(message, logfile):
"""Writes a message to a log file, as well as the time"""
log = open(logfile, 'a')
log.write("Error at:")
log.write(str(datetime.datetime.now()))
log.write(message)
def relog(message, logfile):
"""Overwrites the log file and writes a message to the log file, as well as the time"""
log = open(logfile, 'w')
log.write(str(datetime.datetime.now()))
@solomon081
solomon081 / profilestruct.rb
Created March 30, 2012 02:06
Ruby Profile (Struct)
class Profile
# Profile in the struct format
def initialize(name, desc, age, gender, status)
:attr_reader
puts "Name: #{name}"
puts "Description: #{desc}"
puts "Age: #{age}"
puts "Gender: #{gender}"
puts "Status: #{status}"
end
@solomon081
solomon081 / cloexample.py
Created March 30, 2012 02:17
Closure Example
#!/usr/bin/env python
def multby(factor):
def mult(value):
return value * factor
return mult
times2 = multby(2)
times2(5)
@solomon081
solomon081 / show.rb
Created March 31, 2012 18:08
Show RegExp
def show(a, re)
if a =~ re
puts "#{$`}>>#{$&}<<#{$'}"
else
puts "No Match Found"
end
end
@solomon081
solomon081 / fdom.py
Created April 1, 2012 11:17
Five Days on Mars
#——————————————————#
#/////////\\\\\\\\\#
#/|-Solomon Wise-|\#
#/|-Do Not Steal-|\#
#\\\\\\\\\/////////#
#——————————————————#
# Imports modules
from random import randint, choice
from os import system
listofitems = set()
@solomon081
solomon081 / customll.py
Created April 2, 2012 02:47
Custom Line Length
import textwrap
text = input("Enter in your text: ")
line = input("Enter in your line length: ")
try:
line = int(line)
except:
print("Invalid line value")
exit()
print(textwrap.fill(text, width=line))
stext = input("Enter your text: ")
dedented = textwrap.dedent(stext)
print(dedented)