IMPORTANT!

Snipt is going open source. We've toyed with this idea for quite a while, and have finally decided it's the right way to move forward.

A few things:
  • The entire Snipt source code will be released on GitHub under the 3-clause BSD License on Friday, September 10th.
  • While we'd like to think we're perfect, we realize we're only human. By open sourcing the software that runs this website, certain bugs or security flaws may be discovered that could compromise the privacy of your snipts.
  • Only the Lion Burger team will be able to push commits to the Snipt.net site. Contributors should send a pull request to add new features or submit patches.
  • By using this site, you agree not to be too angry or take any legal action against Lion Burger should this whole thing go up in flames some day.
  • Follow us on Twitter for updates.
I agree, close this message
Sign up to create your own snipts, or login.

Latest 100 public snipts » timeout The latest public timeout snipts.

showing 1-3 of 3 snipts for timeout
  • Simple timeout manager for Javascript
    /**
     * Derived from: http://benalman.com/projects/jquery-hashchange-plugin/
     * See there for an licensing.
     */
    var timeout_id = 0;
    function loop_start() {
      if ( timeout_id ) { return; }
      (function loopy() {
        if (condition) {
          loop_stop();
          // Do something
        }
        else {
          timeout_id = setTimeout( loopy, 500);
        }
      })();
    }
    function loop_stop() {
      timeout_id && clearTimeout( timeout_id );
      timeout_id = 0;
    }
    

    copy | embed

    0 comments - tagged in  posted by flevour on Apr 22, 2010 at 9:28 a.m. EDT
  • Run Linux command for a designated time
    #!/bin/bash                                           
    # thread - Copyright (C) 2009 Radek Suski <info@sigsiu.net>
    # license see http://www.gnu.org/licenses/lgpl-2.1.html GNU/LGPL.
    # You can use, redistribute this file and/or modify it under the terms of the GNU Lesser General Public License version 2.1
    function usage                                                                                                             
    {                                                                                                                          
            echo                                                                                                               
            echo "Starting command with time limit"                                                                            
            echo "        Usage: thread [COMMAND]... [SECONDS]...[OPTIONS]"                                                    
            echo                                                                                                               
            echo "If the command to execute consist of more then 1 word, embbed it within quotes"                              
            echo "Example: "                                                                                                   
            echo "     thread "sleep 25" 5 "                                                                                   
            echo "will start the sleep process for 25 seconds and kill it after 5 seconds"                                     
            echo                                                                                                               
            echo "Options"                                                                                                     
            echo " -q quiet no countdown output"                                                                               
    }                                                                                                                          
    
    function Sleep 
    {              
            clear  
            if [ $1 -gt 39 ]; then
                    steps=39      
                    step=$[$1/40] 
            else                  
                    steps=$[$1 + 1]
                    step=1         
            fi                     
            for (( c=1; c<=$1; c++ ))
            do                       
                    i=$( ps --ppid $$ | grep $3 )
                    if ! [ "$i" ]; then          
                            echo                 
                            echo                 
                            echo "$4 $3 has been already terminated - exiting"
                            echo                                              
                            echo                                              
                            exit 1                                            
                    fi                                                        
                    if [ "$2" != 1 ]; then                                    
                            echo -ne "\r ["                                   
                            Done=$[$1-$c]                                     
                            Done=$[$Done/$step]                               
                            progress=$[$steps-$Done]                          
                            for (( i=1; i<$progress; i++ ))                   
                            do                                                
                                    echo -n "="                               
                            done                                              
                            todo=$[$steps-$progress]                          
                            if [ $todo -gt $steps ] || [ $todo -lt 0 ]; then  
                                    todo=$steps                               
                            fi                                                
                            for (( i=1; i<=$todo; i++ ))                      
                            do                                                
                                    echo -n "."                               
                            done                                              
                            s=$[$1-$c]                                        
                            p=$[$c*100]                                       
                            p=$[$p/$1]                                        
                            echo -n "] $p % done. $s seconds to forced termination of "$4 $3". "
                    fi                                                                          
                    sleep 1                                                                     
            done                                                                                
    }                                                                                           
    
    for p in "$@"
    do           
            if [ "$p" == "-q" ]; then
                    quiet=1          
            fi                       
    done                             
    
    case $2 in
            *[!0-9]* )
                    echo "Time has to be a numeric value. "$2" is not all numeric" 
                    usage                                                          
                    exit 1;                                                        
            ;;                                                                     
    esac                                                                           
    
    if  [ "$1" ] && [ "$2" ] && [ "$1" != "--help" ] && [ "$1" != "--usage" ]; then
            clear                                                                  
            # start the process                                                    
            exec $1 & &>/dev/null                                                  
            clear                                                                  
            # get program name                                                     
            run=`echo $1 | awk -F " " '{ print $1 }'`                              
            # get proces id                                                        
            pid=`ps --ppid $$ | grep "$run" | awk -F " " '{ print $1 }'`           
            if [ "$quiet" != 1 ]; then                                             
                    echo "Started "$1" for $2 seconds. PID is $pid"                
                    echo                                                           
            fi                                                                     
            # go sleep
            Sleep "$2" "$quiet" "$pid" "$run"
            # after sleep if the process still running
            i=$( ps --ppid $$ | grep $pid )
            if [ "$i" ]; then
                    # display message
                    if [ "$quiet" != 1 ]; then
                            echo
                            echo
                            echo "Process $pid is still running. Killing now"
                    fi
                    # try to kill it
                    while [ "$i" ]
                    do
                            kill -9 $pid
                            i=$( ps --ppid $$ | grep $pid )
                            # if killed, output messgae
                            if ! [ "$i" ]; then
                                    # display message
                                    echo "Process $pid has been killed after $2 seconds"
                                    echo
                                    echo
                                    # exit
                                    exit 1
                            fi
                            i=$( ps --ppid $$ | grep $pid )
                    done
            fi
    else
            echo Unsupported request
            usage
    fi
    

    copy | embed

    0 comments - tagged in  posted by Neo on Jan 08, 2010 at 5:28 a.m. EST
  • ssh disable timeout firewall
    http://madphilosopher.ca/2005/07/an-ssh-keep-alive-tip/
    
    It’s worth noting that many SSH timeouts come from firewalls and no amount of tinkering with timeout settings (other than on the firewall) will fix it. The only way in these cases is to simulate traffic (which is what the client’s keepalive settings should do, but don’t always in my experience).
    
    I find this works very well (although possibly it’s overkill being in perl):
    
    perl -e 'sleep 59 && print STDERR "\x00" while 1' &
    
    Run it as soon as you SSH in, and remember the pid so you can kill it before you leave. It squirts a null every 59 seconds. If you change the \x00 for a printable character you will see it appear on your terminal but it still won’t impact what you are doing.
    
    –
    # Adam Reed Says:
    May 6th, 2007 at 0303 UTC
    
    Bruce:
    
    You can automate this by putting the following in your .kshrc (or its equivalent for your shell in its rc file, or put it in .profile (or .login)):
    
    case $- in i*s*)
    perl -e 'sleep 59 && print STDERR "\x00" while 1' &
    trap "kill ${!}" 0
    ;;
    esac
    
    
    # =======================================================================================
    Remember that
    
    ServerAliveInterval
    
    is limited by
    
    ServerAliveCountMax
    
    and that ServerAliveCountMax is set to 3 by default!
    
    That is, if you set ServerAliveInterval to 60 and ServerAliveCountMax is left to default value (3), after the client has sent 3 keep alive packets it will disconnect. That makes 60 x 3 = 180 seconds.
    
    So if you want more time away, you set ServerAliveInterval to 60 and ServerAliveCountMax to the numer you want (for example: 100). The client will send one keep alive packet every 0 seconds for 100 times or, if you prefer, 100 keep alive packets, one every 60 seconds. :D
    
    You set this up in your $HOME/.ssh/config file.
    
    Most of these options are explained in man ssh_config.
    
    
    DiskStation> grep ClientAliveInterval /etc/ssh/sshd_config
    ClientAliveInterval 100
    

    copy | embed

    0 comments - tagged in  posted by rschu68 on Dec 02, 2009 at 8:13 a.m. EST
Sign up to create your own snipts, or login.