working on it ...

Filters

Explore Public Snippets

Sort by

Found 6,258 snippets matching: actual

    public by christopher  206484  20  3  0

    Draw things with the turtle api built into python. It can be slow due to fact its not an actual GUI system. However it is fun to toy with.

    Draw things with the turtle api built into python. It can be slow due to fact its not an actual GUI system. However it is fun to toy with.: drawUtils.py
    #import sys #Currently not needed
    import time
    from turtle import *
    
    #Draw a box
    def drawBox(x1, x2, y1, y2, penColor="Black", fillColor="Black"):
        turtle = Turtle()
        d = delay()
        delay(0)
        turtle.hideturtle()
        turtle.up()
        turtle.pencolor(penColor)
        turtle.fillcolor(fillColor)
        turtle.goto(x1, y1)
        turtle.down()
        turtle.begin_fill()
        turtle.goto(x1, y2)
        turtle.goto(x2, y2)
        turtle.goto(x2, y1)
        turtle.goto(x1, y1)
        turtle.end_fill()
        turtle.up()
        del turtle
        delay(d)
        del d
        
    def drawCircle(size,
                   x = None, y = None,
                   usePen = True,
                   useFill = True,
                   fillColor = "Black",
                   penColor = ["Black"],
                   penSize = 5,
                   pieces = 1):
        if (pieces < 1):
            pieces = 1
        if not(usePen) and not(useFill):
            raise Exception("No pen or fill makes this useless! Please specify at least one of them as True")
        turtle = Turtle()
    
        #Store previous delay
        d = delay()
    
        #Set to draw instantly.
        delay(0)
    
    
        turtle.up() #Pickup pen
        turtle.ht() #Hide the turtle
        if (x == None): #Set default value
            x = (0-(size/2))
        if (y == None): #Set default value
            y = (0-(size/2))
        
        turtle.goto(x, y) #Goto co ords
        icM = len(penColor) #Check size of array and limit it.
        if (icM < 1):
            raise Exception("penColor must have at least one entry in array!")
    
        b = 0 #Store the first color index
    
    
        incD =  (360/pieces)#Incrementation of degrees./
        if (useFill):
            turtle.begin_fill()
        if (usePen):
            turtle.down()
            turtle.pensize(penSize)
        for i in range(-1, pieces):
            ic = penColor[b]
            turtle.fillcolor(fillColor)
            turtle.pencolor(ic)
            turtle.circle(size, incD)
            b += 1
            if not(b < icM):
                b = 0
        turtle.end_fill()
        #Reset delay
        delay(d)
    
        del turtle
    
    
    
    
    def drawTriangle(h, w, x = None, y = None, useFill = True, usePen = True, penColor = "Black", fillColor = "Black", penSize = 1):
        if (x == None): #Set default values
            x = 0-(w/2)
        if (y == None): #Set default values
            y = 0-(h/2)
        else:
            y += (h/2)
        x1, x2 = x-(w/2), x+(w/2)
        y1, y2 = y-(h/2), y+(h/2)
        d = delay()
        delay(0)
        turtle = Turtle()
        turtle.ht()
        turtle.up()
        turtle.goto(x1, y1)
        if (useFill):
            turtle.begin_fill()
            turtle.fillcolor(fillColor)
        if (usePen):
            turtle.down()
            turtle.pencolor(penColor)
        print("x1=",x1,"x2=",x2,"y1=", y1,"y2=", y2,"y=", y,"x=", x) #Debug code
        turtle.goto(x2, y1)
        turtle.goto(x, y2)
        turtle.goto(x1, y1)
        turtle.up()
        turtle.end_fill()
        del turtle
        delay(d)
    
    def drawHouse(size, x = 0, y = 0):
        pass
    
    
    
    
    
    ########This is a test area for use Simply uncomment code
    setup()
    title("PLACE TITLE HERE")
    
    ##Use the api below here to create simple drawings on a window. Or do more complex stuff.
    ##This is not exactly a proper module so it can not be imported or atleast I do not think. I am still learning python.
    ##Enjoy!
    
    
    
    
    
    

    public by Geometry  74842  0  4  0

    Algorithm FastExpansionSum

    // Algorithm Fast-Expansion-Sum // NOTE: This algorithm is not actually used further, but good for checking the S. paper. // Instead the Zero Eliminating version is used. // h cannot be the same as e or f // Read this code together with fast_expansion_sum in predicates.c // There are some minor changes here, because we don't want to read
    // Algorithm Fast-Expansion-Sum
    // NOTE: This algorithm is not actually used further, but good for checking the S. paper.
    //       Instead the Zero Eliminating version is used.
    // h cannot be the same as e or f
    // Read this code together with fast_expansion_sum in predicates.c
    // There are some minor changes here, because we don't want to read outside the array bounds.
    public static int FastExpansionSum(int elen, double[] e, int flen, double[] f, double[] h)
    {
        double Q;
        double Qnew;
        int eindex, findex, hindex;
        double enow, fnow;
    
        // We traverse the lists e and f together. moving from small to large magnitude
        // enow and fnow keep track of the current value in each list, 
        // and eindex and findex the current index
        enow = e[0];
        fnow = f[0];
        eindex = findex = 0;
    
        // First step is to assign to Q the entry with smaller magnitude
        if ((fnow > enow) == (fnow > -enow)) // if |fnow| >= |enow|
        {
            Q = enow;
            eindex++;
    
            // NOTE: The original prdicates.c code here would read past the array bound here (but never use the value).
            // Q = enow;
            // enow = e[++eindex]; <<< PROBLEM HERE
    
            // Instead I just increment the index, and do an extra read later.
            // Pattern is then to read both enow and fnow for every step
            // This adds some extra array evaluations, especially for long arrays, but removes one at the end of each array.
        }
        else
        {
            Q = fnow;
            findex++;
        }
    
        // Start adding entries into h, carrying Q
        hindex = 0;
                
        // Check whether we still have entries in both lists
        if ((eindex < elen) && (findex < flen)) 
        {
            // Note we have an extra 'unrolled' step here, where we are allowed to use FastTwoSum
            // This is becuase we know the next expansion entry is smaller than Q (according to how Q was picked above)
            enow = e[eindex];
            fnow = f[findex];
            // Pick smaller magnitude
            // if |fnow| >= |enow|
            if ((fnow > enow) == (fnow > -enow))
            {
                // Add e and advance eindex
                FastTwoSum(enow, Q, out Qnew, out h[0]);
                eindex++;
            } 
            else 
            {
                // Add f and advance findex
                FastTwoSum(fnow, Q, out Qnew, out h[0]);
                findex++;
            }
            Q = Qnew;
            hindex = 1;
            // While we still have entries in both lists
            while ((eindex < elen) && (findex < flen)) 
            {
                // Can no longer use FastTwoSum - use TwoSum
                enow = e[eindex];
                fnow = f[findex];
                // Pick smaller magnitude
                // if |fnow| >= |enow|
                if ((fnow > enow) == (fnow > -enow))
                {
                    TwoSum(Q, enow, out Qnew, out h[hindex]);
                    eindex++;
                } 
                else 
                {
                    TwoSum(Q, fnow, out Qnew, out h[hindex]);
                    findex++;
                }
                Q = Qnew;
                hindex++;
            }
        }
        // Now we have exhausted one of the lists
        // For the rest, we just run along the list that has values left, 
        //    no more tests to try to pull from the correct list
        while (eindex < elen)
        {
            enow = e[eindex];
            TwoSum(Q, enow, out Qnew, out h[hindex]);
            eindex++;
            Q = Qnew;
            hindex++;
        }
        while (findex < flen)
        {
            fnow = f[findex];
            TwoSum(Q, fnow, out Qnew, out h[hindex]);
            findex++;
            Q = Qnew;
            hindex++;
        }
        h[hindex] = Q;
        return hindex + 1;
    }

    public by cghersi  3422  1  8  0

    C#: How to detect the actual size of an image

    This method can tell you the size of an image, given its URL
    static public bool DetectImageSize(string url, out int resX, out int resY)
    {
        resX = 0;
        resY = 0;
        try
        {
            WebClient client = new WebClient();
            Stream data = client.OpenRead(url);
            Image remoteImage = Image.FromStream(data);
            resX = (int)remoteImage.Width;
            resY = (int)remoteImage.Height;
            data.Close();
        }
        catch
        {
            return false;
        }
        return true;
    }
    

    public by Geometry  1533  0  4  0

    SetActualRequestType: Specifies the actual type of <see cref="System.Net.Http.ObjectContent{T}"/> passed to the <see cref="System.Net.Http.HttpRequestMessage"/> in an action. The help page will use this information to produce more accurate re...

    Specifies the actual type of passed to the in an action. The help page will use this information to produce more accurate request samples. The . The type. Name of the controller. Name of the action. The parameter names.
    using System;
    using System.Collections.Generic;
    using System.Collections.ObjectModel;
    using System.ComponentModel;
    using System.Diagnostics;
    using System.Diagnostics.CodeAnalysis;
    using System.Globalization;
    using System.Linq;
    using System.Net.Http;
    using System.Net.Http.Headers;
    using System.Web.Http;
    using System.Web.Http.Controllers;
    using System.Web.Http.Description;
    using PowerBIRestDemo.Areas.HelpPage.ModelDescriptions;
    using PowerBIRestDemo.Areas.HelpPage.Models;
    
    /// <summary>
    /// Specifies the actual type of <see cref="System.Net.Http.ObjectContent{T}"/> passed to the <see cref="System.Net.Http.HttpRequestMessage"/> in an action.
    /// The help page will use this information to produce more accurate request samples.
    /// </summary>
    /// <param name="config">The <see cref="HttpConfiguration"/>.</param>
    /// <param name="type">The type.</param>
    /// <param name="controllerName">Name of the controller.</param>
    /// <param name="actionName">Name of the action.</param>
    /// <param name="parameterNames">The parameter names.</param>
    public static void SetActualRequestType(this HttpConfiguration config, Type type, string controllerName, string actionName, params string[] parameterNames)
    {
        config.GetHelpPageSampleGenerator().ActualHttpMessageTypes.Add(new HelpPageSampleKey(SampleDirection.Request, controllerName, actionName, parameterNames), type);
    }

    public by Geometry  1337  0  4  0

    SetActualResponseType: Specifies the actual type of <see cref="System.Net.Http.ObjectContent{T}"/> returned as part of the <see cref="System.Net.Http.HttpRequestMessage"/> in an action. The help page will use this information to produce more ...

    Specifies the actual type of returned as part of the in an action. The help page will use this information to produce more accurate response samples. The . The type. Name of the controller. Name of the action.
    using System;
    using System.Collections.Generic;
    using System.Collections.ObjectModel;
    using System.ComponentModel;
    using System.Diagnostics;
    using System.Diagnostics.CodeAnalysis;
    using System.Globalization;
    using System.Linq;
    using System.Net.Http;
    using System.Net.Http.Headers;
    using System.Web.Http;
    using System.Web.Http.Controllers;
    using System.Web.Http.Description;
    using PowerBIRestDemo.Areas.HelpPage.ModelDescriptions;
    using PowerBIRestDemo.Areas.HelpPage.Models;
    
    /// <summary>
    /// Specifies the actual type of <see cref="System.Net.Http.ObjectContent{T}"/> returned as part of the <see cref="System.Net.Http.HttpRequestMessage"/> in an action.
    /// The help page will use this information to produce more accurate response samples.
    /// </summary>
    /// <param name="config">The <see cref="HttpConfiguration"/>.</param>
    /// <param name="type">The type.</param>
    /// <param name="controllerName">Name of the controller.</param>
    /// <param name="actionName">Name of the action.</param>
    public static void SetActualResponseType(this HttpConfiguration config, Type type, string controllerName, string actionName)
    {
        config.GetHelpPageSampleGenerator().ActualHttpMessageTypes.Add(new HelpPageSampleKey(SampleDirection.Response, controllerName, actionName, new[] { "*" }), type);
    }

    public by Geometry  1283  0  5  0

    SetActualResponseType: Specifies the actual type of <see cref="System.Net.Http.ObjectContent{T}"/> returned as part of the <see cref="System.Net.Http.HttpRequestMessage"/> in an action. The help page will use this information to produce more ...

    Specifies the actual type of returned as part of the in an action. The help page will use this information to produce more accurate response samples. The . The type. Name of the controller. Name of the action. The parameter names.
    using System;
    using System.Collections.Generic;
    using System.Collections.ObjectModel;
    using System.ComponentModel;
    using System.Diagnostics;
    using System.Diagnostics.CodeAnalysis;
    using System.Globalization;
    using System.Linq;
    using System.Net.Http;
    using System.Net.Http.Headers;
    using System.Web.Http;
    using System.Web.Http.Controllers;
    using System.Web.Http.Description;
    using PowerBIRestDemo.Areas.HelpPage.ModelDescriptions;
    using PowerBIRestDemo.Areas.HelpPage.Models;
    
    /// <summary>
    /// Specifies the actual type of <see cref="System.Net.Http.ObjectContent{T}"/> returned as part of the <see cref="System.Net.Http.HttpRequestMessage"/> in an action.
    /// The help page will use this information to produce more accurate response samples.
    /// </summary>
    /// <param name="config">The <see cref="HttpConfiguration"/>.</param>
    /// <param name="type">The type.</param>
    /// <param name="controllerName">Name of the controller.</param>
    /// <param name="actionName">Name of the action.</param>
    /// <param name="parameterNames">The parameter names.</param>
    public static void SetActualResponseType(this HttpConfiguration config, Type type, string controllerName, string actionName, params string[] parameterNames)
    {
        config.GetHelpPageSampleGenerator().ActualHttpMessageTypes.Add(new HelpPageSampleKey(SampleDirection.Response, controllerName, actionName, parameterNames), type);
    }

    public by Geometry  1185  0  5  0

    SetActualRequestType: Specifies the actual type of <see cref="System.Net.Http.ObjectContent{T}"/> passed to the <see cref="System.Net.Http.HttpRequestMessage"/> in an action. The help page will use this information to produce more accurate re...

    Specifies the actual type of passed to the in an action. The help page will use this information to produce more accurate request samples. The . The type. Name of the controller. Name of the action.
    using System;
    using System.Collections.Generic;
    using System.Collections.ObjectModel;
    using System.ComponentModel;
    using System.Diagnostics;
    using System.Diagnostics.CodeAnalysis;
    using System.Globalization;
    using System.Linq;
    using System.Net.Http;
    using System.Net.Http.Headers;
    using System.Web.Http;
    using System.Web.Http.Controllers;
    using System.Web.Http.Description;
    using PowerBIRestDemo.Areas.HelpPage.ModelDescriptions;
    using PowerBIRestDemo.Areas.HelpPage.Models;
    
    /// <summary>
    /// Specifies the actual type of <see cref="System.Net.Http.ObjectContent{T}"/> passed to the <see cref="System.Net.Http.HttpRequestMessage"/> in an action.
    /// The help page will use this information to produce more accurate request samples.
    /// </summary>
    /// <param name="config">The <see cref="HttpConfiguration"/>.</param>
    /// <param name="type">The type.</param>
    /// <param name="controllerName">Name of the controller.</param>
    /// <param name="actionName">Name of the action.</param>
    public static void SetActualRequestType(this HttpConfiguration config, Type type, string controllerName, string actionName)
    {
        config.GetHelpPageSampleGenerator().ActualHttpMessageTypes.Add(new HelpPageSampleKey(SampleDirection.Request, controllerName, actionName, new[] { "*" }), type);
    }

    public by cghersi  1942  0  6  0

    Finding actual number of physical cpu installed

    By Rahul Singh, 2013/01/14 The Sql Server always see Logical cpu it does not distinguish between Hyperthreaded logical cpu and physical processor using the below query we can find out actual number of physical cpu installed on the server The first column represent logical processor and second column represent actual physical processor insta
    SELECT cpu_count AS Logical_CPU_Count , cpu_count / hyperthread_ratio AS Physical_CPU_Count FROM sys.dm_os_sys_info ;

    public by AndreaBuffa  2265  0  5  2

    sh: avoid runtime error when a variable is supposed to contain a number but it is actually empty

    sh
    myNum='';
    [ ${myNum:-0} -eq 0 ] && echo ok
    # ok
    
    [ ${myNum:-1} -eq 1 ] && echo ok
    # ok
    
    [ ${myNum:-1} -gt 0 ] && echo ok
    # ok
    
    [ ${myNum:-0} -gt 1 ] || echo "0 is not greater than 1"
    # 0 is not greater than 1
    
    # This behaviour comes from the common way to extract a substring from a 
    # variable
    tmp='mississippi'; echo ${tmp:0:2}
    # mi
    
    echo ${tmp:1:1}
    # i
    
    # 
    echo ${tmp:2}
    # ssissippi

    public by lbottaro  7102  1  7  3

    Linux one liner bash code to detect file or directory from a given list

    This bash code shows how to detect if a given item in a list returned by a command is actually a file or a directory, without affecting the output format. In this case, xargs is used to pass the '{}' reference to a shell script executed for each line returned by the tree command.
    tree -if --noreport /home/ | xargs -I '{}' sh -c 'if [ -d {} ]; then echo "Dir {}"; else echo "File {}"; fi'  
    • Public Snippets
    • Channels Snippets