• The Treachery of Comments

    samlecuyer        
    0 Likes0 Commentsc_cpp

    #include <sys/types.h>
    #include <sys/stat.h>
    int main() {
      // Ceci n'est pas une pipe
      mkfifo("~/fifo", S_IWUSR|S_IROTH);
    }
    
  • Remove alt tags

    dnbrwstr        
    0 Likes0 Commentsjavascript

    $('img').each(function(){
      $(this).attr('alt', '')
    })
  • LL(1) parser

    Odaym        
    1 Likes0 Commentsruby

    #LL(1) parser as a solution for exercise 4.9 in "Compiler Construction: Principles and Practice"
    #String given is (a,(b,(2)),(c))$
    #deduce the grammar ;) 
    
    class Parser
      def initialize()
      	@parsing_stack = []
    		@parsing_stack.push('$')
    		@parsing_stack.push('lexp-seq')
    	end
    
    	def launch!
    		introduction
    		result = nil
    		until result == :done
    			print "> "
    			user_response = gets.chomp
    			result = parse(user_response)
    		end
    		@parsing_stack.inspect
    		conclusion
    	end
    
    	def parse (input)
    		output = ""
    		counter = 0
    		puts "This is how your stack looks like: \n#{@parsing_stack.inspect}"
    		input.each_char do |single_char|
    		case single_char
    			when '('
    				while @parsing_stack[-1] != single_char
    					if @parsing_stack[-1] == 'lexp-seq'
    						@parsing_stack.pop
    						@parsing_stack.push('lexp-seq1','lexp')
    						puts @parsing_stack.inspect
    					elsif @parsing_stack[-1] == 'lexp'
    						@parsing_stack.pop
    						@parsing_stack.push('list')
    						puts @parsing_stack.inspect
    					elsif @parsing_stack[-1] == 'list'
    						@parsing_stack.pop
    						@parsing_stack.push(')','lexp-seq','(')
    						puts @parsing_stack.inspect
    					end
    				end
    				if @parsing_stack[-1] == single_char
    					@parsing_stack.pop
    					puts @parsing_stack.inspect
    					output += single_char
    					counter += 1
    					puts "read #{counter} characters so far"
    				end
    			when 'a','b','c'
    				while @parsing_stack[-1] != 'identifier'
    					if @parsing_stack[-1] == 'atom'
    						@parsing_stack.pop
    						@parsing_stack.push('identifier')
    						puts @parsing_stack.inspect
    					elsif @parsing_stack[-1] == 'lexp'
    						@parsing_stack.pop
    						@parsing_stack.push('atom')
    						puts @parsing_stack.inspect
    					elsif @parsing_stack[-1] == 'lexp-seq'
    						@parsing_stack.pop
    						@parsing_stack.push('lexp-seq1', 'lexp')
    						puts @parsing_stack.inspect
    
    					end
    				end
    				if @parsing_stack[-1] == 'identifier'
    					@parsing_stack.pop
    					puts @parsing_stack.inspect
    					output += single_char
    					counter += 1
    					puts "read #{counter} characters so far"
    				end
    			when '0'..'9'
    				while @parsing_stack[-1] != 'number'
    					if @parsing_stack[-1] == 'lexp'
    						@parsing_stack.pop
    						@parsing_stack.push('atom')
    						puts @parsing_stack.inspect
    					elsif @parsing_stack[-1] == 'atom'
    						@parsing_stack.pop
    						@parsing_stack.push('number')
    						puts @parsing_stack.inspect
    					elsif @parsing_stack[-1] == 'lexp-seq'
    						@parsing_stack.pop
    						@parsing_stack.push('lexp-seq1', 'lexp')
    						puts @parsing_stack.inspect
    					end
    				end
    				if @parsing_stack[-1] == 'number'
    					@parsing_stack.pop
    					puts @parsing_stack.inspect
    					output += single_char
    					counter += 1
    					puts "read #{counter} characters so far"
    				end
    			when ')'
    				while @parsing_stack[-1] != single_char
    					if @parsing_stack[-1] == 'lexp-seq1'
    						@parsing_stack.pop
    						puts @parsing_stack.inspect
    					end
    				end
    				if @parsing_stack[-1] == ')'
    					@parsing_stack.pop
    					puts @parsing_stack.inspect
    					output += single_char
    					counter += 1
    					puts "read #{counter} characters so far"
    				end
    			when ','
    				while @parsing_stack[-1] != single_char
    					if @parsing_stack[-1] == 'lexp-seq1'
    						@parsing_stack.pop
    						@parsing_stack.push('lexp-seq')
    						@parsing_stack.push(',')
    						puts @parsing_stack.inspect
    					end
    				end
    				if @parsing_stack[-1] == ','
    					@parsing_stack.pop
    					puts @parsing_stack.inspect
    					output += single_char
    					counter += 1
    					puts "read #{counter} characters so far"
    				end
    			when '$'
    				while @parsing_stack[-1] != single_char
    					if @parsing_stack[-1] == 'lexp-seq1'
    						@parsing_stack.pop
    						puts @parsing_stack.inspect
    					end
    				end
    				if @parsing_stack[-1] == '$'
    					@parsing_stack.pop
    					output += single_char
    					counter += 1
    					puts "read #{counter} characters so far"
    					puts "#{output}"
    					return :done
    				end
    			when "\s"
    
    			else
    				puts "\nInput not recognized!"
    			end
    		end
    	end
    
    	def introduction
    		puts "\n<<< Welcome to the LL(1) Parser >>>\n"
    		puts "This is an interactive LL(1) Parser for you to play with.\n\n"
    	end
    
    	def conclusion
    		puts "\n<<< Goodbye and happy parsing! >>>"
    	end
    end
    
    parser = Parser.new()
    parser.launch!
  • cfeiock        
    0 Likes0 Commentspython

    #!/usr/bin/env python
    
    from googlevoice import Voice
    from googlevoice.util import input
    
    email = '<EMAIL>'
    pw = '<PASSWORD>'
    
    voice = Voice()
    voice.login(email, pw)
    
    phoneNumber = 'XXXXXXXXXX'
    text = 'test message'
    
    voice.send_sms(phoneNumber, text)
    
  • Rename Like A Boss

    n1m3        
    1 Likes0 Commentspython

    #!/usr/bin/env python3
    
    import re
    import os
    
    from bs4 import BeautifulSoup
    
    
    with open('titles', 'r') as f:
        html = f.read()
    soup = BeautifulSoup(html)
    
    titles = {}
    
    for episode in soup.find_all('tr', attrs={'class': "vevent"}):
        num = episode.find('td').text
        title = episode.find('td', attrs={'class': 'summary'}).text
        title = title.replace('"', '')
        titles[int(num)] = [num.zfill(2), title]
    
    reg = re.compile('.*S\d+E(\d+).*')
    for i in os.listdir(os.getcwd()):
        match = reg.match(i)
        if match is not None:
            episode = int(match.group(1))
            path = os.path.join(os.getcwd(), i)
            num, title = titles[episode]
            ext = os.path.splitext(path)[-1]
            filename = '{} - {}{}'.format(num, title, ext)
            new_path = os.path.join(os.getcwd(), filename)
            print(num, title)
            os.rename(path, new_path)
  • Infinite Loop Durations

    RunOfTheShipe        
    0 Likes0 Commentscsharp

    bool ever = true;
    DateTime start = DateTime.Now;
    
    // Recommend running this part on a separate thread. It may block the UI.
    for(; ever;)
    { }
    
    Console.WriteLine(DateTime.Now - start);
  • Snippet of chess

    dylanclark112        
    1 Likes0 Commentsruby

      # Piece superclass possible moves:
      def possible_moves(deltas, allowed_steps, board)
        possible_moves = []
        deltas.each do |delta|
          current_position = @position
          allowed_steps.times do
            move = [delta, current_position].transpose.map {|x| x.reduce(:+)}
            break unless board.move_on_board?(move)
            possible_moves << move if board.piece_at(move).nil?
            if !board.piece_at(move).nil?
              possible_moves << move if board.piece_at(move).color != self.color
              break
            end
            current_position = move
          end
        end
        possible_moves
      end
      
      ### For example our Rook Piece subclass inherits this function like so:  def possible_moves(board)
      def possible_moves(board)
        deltas = [[-1,0], [0,-1], [1,0], [0,1]]
        super(deltas, 8, board)
      end
  • Swag

    riota        
    0 Likes0 Commentshtml

    <HTML>
    <HEAD>
    <TITLE> PRACTICA N*1 DE INFORMATICA </TITLE>
    </HEAD>
    <BODY>
    <CENTER><H3>MINISTERIO DE EDUCACION
    <P> DIRECCION REGIONAL DE EDUCACION
    <p><I><H3> SOYUZ BILINGUAL SCHOOL </H3></CENTER></I>
    <HR>
    <HR>
    <CENTER> INFORMATICA </CENTER></HR>
    <P> CIENCIAS
    <P> GRUPO XII* A
    <P> JORNADA VESPERINA
    <P> ESTUDIANTE:
    <P><U><I> JORGE ORTIZ </U></I>
    <P> PROFESOR:
    <P><U><I> JUAN JOSE BARRIA</U></I>
    <P>2013
    </BODY>
    </HTML>
  • racket interpeter

    xapon        
    0 Likes0 Commentstext

    ;mlet - (struct mlet (var e body) #:transparent)
            [(mlet? e)
             (letrec ([v (eval-under-env (mlet-e e) env)]
                   [new-env (cons (cons (mlet-var e) v) env)])
               (eval-under-env (mlet-body e) new-env))]
            
            ;fun -(struct fun  (nameopt formal body) #:transparent)
            [(fun? e)
             (if (and (string? (fun-nameopt e)) (string? (fun-formal e)))
                 (letrec ([new-env (cons (cons (fun-nameopt  e) e) env)])
                   (closure new-env e))
                 (if (and (false? (fun-nameopt e)) (string? (fun-formal e)))
                     (closure env e)
                     (error "bad parameters passed to function")))]
            
            ;closure - (struct closure (env fun) #:transparent) 
            [(closure? e) e]
  • .vimrc

    teferi        
    2 Likes0 Commentspython

    function! PythonPath()
    python << EOF
    import os.path
    import sys
    curdir = os.path.abspath(os.path.curdir)
    while curdir != '/':
        if os.path.exists(os.path.join(curdir, 'apps')):
            sys.path.insert(0, os.path.join(curdir, 'apps'))
        curdir = os.path.abspath(curdir + '/..')
    EOF
    endfunction
    call PythonPath()