Skip to content

Instantly share code, notes, and snippets.

View IndianGuru's full-sized avatar

IndianGuru IndianGuru

View GitHub Profile
@IndianGuru
IndianGuru / struct2.go
Created September 4, 2015 04:31
Another struct example
msn := My_Struct_Name{1, "talim"}
msn.X = 4
@IndianGuru
IndianGuru / struct3.go
Created September 4, 2015 04:47
Another struct example
type Student struct {
Name string
}
@IndianGuru
IndianGuru / struct3.go
Created September 4, 2015 04:47
Another struct example
type Student struct {
Name string
}
@IndianGuru
IndianGuru / defineend.txt
Created September 4, 2015 04:51
Define and End in Go
`{{define "T1"}}ONE{{end}}
{{define "T2"}}TWO{{end}}
{{define "T3"}}{{template "T1"}} {{template "T2"}}{{end}}
{{template "T3"}}`
@IndianGuru
IndianGuru / stud_struct.go
Created September 4, 2015 04:56
stud_struct.go
package main
import (
"log"
"os"
"text/template"
)
type Student struct {
//exported field since it begins
@IndianGuru
IndianGuru / new_person.go
Created September 4, 2015 05:19
new_person.go
package main
import (
"log"
"os"
"text/template"
)
type Person struct {
Name string
class String
alias_method :is_a, :==
alias_method :is_an, :==
end
class Maze
NAVIGABLE = ' '
WALL = '#'
POINT_A = 'A'
@IndianGuru
IndianGuru / maze.rb
Created January 14, 2010 05:06 — forked from anonymous/maze.rb
class Maze
attr_reader :maze_array
def initialize(maze)
@maze_array = maze.split("\n") #create array of lines of the string
@maze_array.map! { |line| line.chars.to_a } #converts array to 2-d array of characters in maze
raise ArgumentError, "All lines must be of the same length", caller if !@maze_array.all? {|line| line.length == @maze_array[0].length}
@height = @maze_array.length #store the height of the maze in an instance variable
@width = @maze_array[0].length #store the length of the maze in an instance variable (assumes each line is the same length - should really test for this if being thorough)
@maze_array.each_with_index do |line, index1| #search array to find start and end of maze
line.each_with_index do |char, index2|
class Maze
Cardinals = Proc.new{|(x,y)| [[x-1,y],[x,y+1],[x+1,y],[x,y-1]].select{|c| c.min >= 0}}
MazeSeperator, MazeStart, MazeWall, MazeEnd, MazeOOB = "\n", 'A', '#', 'B', nil
Infinity = 1.0/0
X, Y = 0, 1
def initialize(maze)
raise ArgumentError, 'No end point' unless maze.include? MazeEnd
raise ArgumentError, 'No start point' unless maze.include? MazeStart
@IndianGuru
IndianGuru / maze.rb
Created January 18, 2010 12:33 — forked from patio11/maze.rb
#This solves the maze using regular expressions, because I am too
#lazy to worry about arrays, darn it. It is inefficient as heck and designed
#purely to demonstrate perversion of sound CS principals.
#
# Code by Patrick McKenzie, 2010. I release this work unto the public domain.
class Maze
def initialize(maze_string)
@width = maze_string.split("\n")[0].length #width of maze in characters
@guts = maze_string.gsub("\n", "") #maze as a flat string -- no newlines