working on it ...

Filters

Explore Public Snippets

Sort by

Found 2,574 snippets matching: execute

    public by emsity  262979  2  6  0

    PHP script to call Python robot arm command

    HTML call PHP to execute python command
    <?php
    exec( " sudo python /home/pi/arm/baseanti.py &"  );
    
    /* Redirect browser */
    $gohere = "http://192.168.169.15/index3G.html";
    header("Location: $gohere");
    /* Make sure that code below does not get executed when we redirect. */
    exit;
    ?>
    

    public by dave83  223909  8  7  0

    How to run methods in class marked with specific Java annotation

    The snippet shows how to invoke only methods of a class marked with specific annotation. The list of methods class (MyTest) is returned using reflection. Annotations are returned via getAnnotation() method. The method is executed via invoke() method.
    import java.lang.reflect.Method;
    
    public class MyTest {
    
        @MyAnnotation
        public void method1() {
          System.out.println("method1");
        }
    
        public void method2() {
          System.out.println("method2");
        }
        
        @MyAnnotation
        public void method3() {
          System.out.println("method3");
        }
        
        public static void main(String[] args) {
    
            MyTest runner = new MyTest();
            Method[] methods = runner.getClass().getMethods();
    
            for (Method method : methods) {
                MyAnnotation annos = method.getAnnotation(MyAnnotation.class);
                if (annos != null) {
                    try {
                        method.invoke(runner);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    } 
                            

    public by egodoyc  148289  2  6  0

    PHP Adodb Execute

    Invoque de execution method of ADODB
    $rs=$db->Execute($sql);
    

    public by strykerraven  188253  7  5  1

    WordPress safely defining and executing functions

    Handy safe way to include functions in your WordPress Themes functions.php file. This is even more useful if you are using a child theme and don't want to conflict with functions already defined by the parent theme. Even better; These functions can be executed within the same if(function_exists()) block that defines them creating a neater to manage
    <?php
    
    // Lets get rid of the versioning on static .js and .css files.
    // It looks tacky anyway for static files.
    
    	/**
    	 * Strips Version query strings
    	 * @param type $src
    	 * @return type
    	 */
    	if(!function_exists('remove_css_js_versions')){ // if the function doesnt exist then...
    		function remove_css_js_versions($src){ // define the function
    			return remove_query_arg('ver', $src); // call built-in wordpress function to remove query named "ver" from whatever is passed as $src
    		}
    		add_filter('script_loader_src', 'remove_css_js_versions'); // Pass a hook as $src for js to function listed above named "remove_css_js_versions"
    		add_filter('style_loader_src', 'remove_css_js_versions'); // Pass a hook as $src for css to function listed above named "remove_css_js_versions"
    	} // All scripts and styles will be filtered to have ?ver=1.2.3 stripped from urls. Function defined and executed in same if() statement.
    
      /**
      * Need to debug? Instead of just using print_r($array) you just do preprint_r($array)
      * the array will be output neatly instead of wrapped and messy.
      */
    	if(!function_exists('preprint_r')){
    		function preprint_r($val){
    			echo '<pre>' . PHP_EOL;
    			print_r($val) . PHP_EOL;
    			echo '</pre>' . PHP_EOL;
    		}
    	}
    	
    	/** Remove the WP Icon (Menu) from profile and admin pages. */
    		if(!function_exists('remove_wp_logo')){
      		function remove_wp_logo($wp_admin_bar){
      			$wp_admin_bar->remove_node('wp-logo');
      		}
      		add_action('admin_bar_menu', 'remove_wp_logo', 33);
      	}
      	
    /**
    	 * Wordpress Login Page fixes. By default WordPress shows its logo on your login pages and links to its own site.
    	 * A visitor logging into your site don't need this potential roadblock so lets show WordPress that we mean business!
    	 */
    	# Fix Login Page WordPress URL
    	if(!function_exists('fix_wp_login_img_url')){
    		function fix_wp_login_img_url($url){
    			return get_bloginfo('url');
    		}
    		add_filter('login_headerurl', 'fix_wp_login_img_url');
    	}
    
    	# Fix Login Page WordPress Title (Text displayed on hover defaults to Powered By WordPress)
    	if(!function_exists('fix_wp_login_img_title')){
    		function fix_wp_login_img_title($title){
    			return get_bloginfo('description');
    		}
    		add_filter('login_headertitle', 'fix_wp_login_img_title');
    	}
    
    	/**
    		Change Login Page WordPress Logo, You will need to update path and point to a valid image.
    		WordPress adds this with a CSS background image for your anchor link. It first applys a PNG and then a SVG override if your browser is modern and supports svg
    		In your themes custom stylesheet you can change default Wordpress image by supplying a new background image:
    
    		.login h1 a {
    			background-image: none,url(images/your_image.png);
    		}
    
    		Hint: WordPress uses an 64x64 image but you can adapt size to your need. You might want to use SVG like WordPress did because it will scale best at any resolution.
    
    	 */
    
    	/**
    	 * Simple Actions that use wp_head hook to cleanup WP header Junk/Bloat
    	 * that is included with WordPress by default.
    	 */
    	remove_action('wp_head', 'wp_generator');
    	remove_action('wp_head', 'rsd_link');
    	remove_action('wp_head', 'wlwmanifest_link');
    	remove_action('wp_head', 'wp_shortlink_wp_head');            
    	
    	
    	?>

    public by micurs  2768  2  9  7

    Execute javascript code at the end of a CSS transition

    Using JQuery you can easily bind a function to any event. CSS transitions on a given element trigger different event depending on the browser. You can capture all or write a small function that select the one working on the current browser. Here is how (using typescript and underscore):
    function getBrowserTransitionEvent( el : JQuery ) : string {
      var transitions = [ 
        { name: 'transition', value: 'transitionend' },
        { name: 'OTransition', value: 'oTransitionEnd' },
        { name: 'MozTransition', value: 'transitionend' },
        { name: 'WebkitTransition', value: 'webkitTransitionEnd' } ];
      var HTMLElement e = el.get();
      var t = _.find< { name: string; value: string }>( transitions , 
          (t) => e.style[t.name] !== undefined);
      return t !== undefined ? t.value : '';
    }
    
    
    // Here is how to use this:
    $('#myElement').bind( getBrowserTransitionEvent($('#myElement')),
      function() {
        alert('CSS transision is complete');
      });

    public by lbottaro  3890  5  6  0

    Msbuild batch result check script

    This script (bat) allows to check the result of MSBuild command execution. The script implements functions and method for bat programming.
    ECHO Off
    @%WINDIR%\Microsoft.NET\Framework\v3.5\MSBuild.exe "c:\a\copy.proj"
    set BUILD_STATUS=%ERRORLEVEL% 
    IF NOT %BUILD_STATUS%==0 GOTO ERROR
    GOTO DONE
    
    :ERROR
    ECHO %ERRORLEVEL%
    ECHO --------------------------------------------------
    ECHO ERROR HAS OCCURED
    ECHO --------------------------------------------------
    pause
    GOTO END
    
    :DONE
    ECHO %ERRORLEVEL%
    ECHO "AllOK"
    pause
    :END

    public by lbottaro  1841  15  6  2

    Execute a linux command at regular intervals

    Use Linux watch to execute a running command at certain time. Note the usage of double quotes to include a complex command, eg ls -la AND grep result Options: -n 5: exec every 5s
    watch -n 5 "ls -la | grep something"                                           

    public by lbottaro  3519  1  5  0

    Python execute shell cmd

    This python script runs a shell in linux and executes the cmd or script in a new thread. Python polls the thread till it has some output and save it to file, as well as standard error redirection to file. Then close both file descriptors.
    logFile = open(outputDir + '/build_log.txt',"w")
    errFile = open(outputDir + '/build_err.txt',"w")
    
    compileProcess = Popen(<CMD_or_SCRIPT>, shell=True, executable='/bin/tcsh', stdout=PIPE, stderr=errFile)
    
    while (True):
    	output = compileProcess.stdout.readline()
            if output == "":
            	break
            logFile.write(output)
    
    logFile.close()
    errFile.close()

    public by cghersi  4283  0  6  1

    How to execute an SQL statement in VBA

    This simple method allows to execute the given SQL query, returning true if there was no error, or false otherwise. The SQL statement is not supposed to return resultsets, like an INSERT, UPDATE or DELETE
    Public Function ExecCmd(ByVal sql As String) As Boolean
    On Error GoTo ErrorCmd
    
      Dim conn As ADODB.Connection
      Dim cmd As ADODB.Command
          
      'Init db objects
      'Connection is the current DB one
      Set conn = CurrentProject.Connection
      Set cmd = New ADODB.Command
        
      With cmd
          .ActiveConnection = conn
          .CommandText = sql
          .CommandType = adCmdText
          .Execute
      End With
    
      ExecCmd = True
        
    Exit_go: Exit Function
    ErrorCmd:
      MsgBox Err.Description
      ExecCmd = False
    End Function

    public by lbottaro  2277  8  6  0

    Executing a command from string variable in bin bash

    This linux bash script allows to store a bash command in string variable and then to execute it. The output is then saved into a variable, using eval statement.
    cmd="find . -name *.zip"
    echo Command to execute: "$cmd"
    res=`eval $cmd`
    echo RESULT = "$res"
    
    • Public Snippets
    • Channels Snippets