working on it ...

Filters

Explore Public Snippets

Sort by

Found 1,408 snippets matching: replacement

    public by cghersi  7261  16  9  1

    C#: Replace an exact word in a sentence

    Same as String.Replace but with case-insensitive matches and search for the exact word. E.g. searching in "Java and Javascript with Java." the word 'Java', and replacing it with 'Python' results in "Python and Javascript with Python."
    public static string ReplaceExactWord(this string stringToSearch, string find, string replace)
    {
        string pattern = @"\b" + find + @"\b";
        return Regex.Replace(stringToSearch, pattern, replace, RegexOptions.IgnoreCase);
    }
    

    public by cghersi  2571  0  6  0

    How to replace a character in string in C#

    This is the fastest way to replace a character in a string
    string temp = "My new string";
    temp = temp.replace("new", "old");
    Console.WriteLine(temp);

    public by ekarakas  2619  0  5  0

    A print_r replacement function that can handle nested arrays and strings

    Usage: printr($array);
    PHP
    /*
        A print_r replacement function that can handle nested arrays and strings
        Usage: printr($array);
        */
        function printr($array){
        echo '<blockquote>';
        if (!is_array($array)) return;
        foreach($array as $key => $value){
        echo htmlspecialchars("$key: ");
        if (is_array($value)){ printr($value);}else{echo htmlspecialchars($value).'<br />';}
        }
        echo '</blockquote>';
        }

    public by Alessio Felicioni  9023  1  4  1

    scheduled task command, windows host (warning: not just a CTRL+C & CTRL+V crontab replacement). Scheduled for every Monday at 20:15

    scheduled task command, windows host (warning: not just a CTRL+C & CTRL+V crontab replacement). Scheduled for every Monday at 20:15: windows-scheduled-task.cmd
    schtasks /create /tn "Namespace\Scheduled Task" /tr "php -f C:\xampp\htdocs\index.php" /sc weekly /d MON /st 20:15
    
    

    public by tcyrus  1262  0  4  0

    Favorite Mac Icon Replacements

    Favorite Mac Icon Replacements: icons.md
    # Favorite Mac Icon Replacements
    
    ## Atom
    * [Native UI - @ferdinandvogler](https://atom.io/themes/native-ui)
    * [Atom Zion Style Icon - Alessandro Mingione](https://dribbble.com/shots/1809023-Atom-Zion-Style-Icon)
    * [Atom Replacement Icon - Edward Loveall](https://github.com/edwardloveall/atom-replacement-icon)
    * [Atom Icon - Trevor Kay](http://trevorkay.me/downloads/atom.zip)
    * [Atom Icon - Meritt Thomas](https://dribbble.com/shots/2228635-Atom-Icon)
    * [Atom Icon for Mac - Jonathan Simcoe](https://dribbble.com/shots/2567409-Atom-Icon-for-Mac)
    
    ## Helium
    * [Helium Browser Icon - David Keegan](https://dribbble.com/shots/2313396-Helium-Browser-Icon)
    
    ## 
    
    

    public by cghersi  3340  1  7  0

    Get Top 14 KPIs performances of SQL Server

    Gets top 14 Key Performance Indicators (KPI). This is a replacement for various perfmons statistics.
    DROP PROCEDURE dbo.spGetKpi_Top14
    GO
    CREATE PROCEDURE dbo.spGetKpi_Top14
        (
       @iDelay AS INT = 10
        )
    AS
    
    /***********************************************************************************************************
     Purpose:      Gets top 14 Key Performance Indicators (KPI).   This is a replacement for various perfmons statistics.  
                   DMV's are used which are a lower resource use than perfmon.
                   The statistics are collected over a specified interval and returned as a recordset.  This may show up 
                   as a long running process on some monitoring systems due to the WAITFOR verb being used.
    
                    Information on sys.dm_os_performance_counters can be found here: 
                    http://technet.microsoft.com/en-us/library/ms187743.aspx
                    http://technet.microsoft.com/en-us/library/ms189628.aspx
                    http://technet.microsoft.com/en-us/library/ms189628.aspx
     
     Created Date: 06/29/2012
     Written by:   Monte Kottman
    
     Modification:
    
     Proc Name:    spGetKPI_Top14
    
     Inputs:       iDelay                     Number of seconds to delay while collecting statistics.
    
     Outputs:      [Event Date]               Starting Date / Time of the reporting period.
                   [SQL Proc Utiliz %]        Percentage of the CPU that SQL is utilizing.
                   [CPU Idle %]               Percentage of the CPU that is doing nothing.
                   [Other Proc Utiliz %]      Percentage of the CPU used by other processes.
                   [User Connections]         The number of users currently connected to the SQL Server. 
                   [Logins Per Sec]           The number of logins per second.
                   [Logouts Per Sec]          The number of logouts per second.
                   [% Page Splits Per Batch]  Number of page splits per second that occur as the result of overflowing index pages. 
                   [Buffer Cache Hit Ratio]   Percentage of pages found in the buffer cache without having to read from disk. 
                   [Page Life Expectancy]     How long data pages are staying in the buffer. 
                   [Latch Waits Per Sec]      Number of latch requests that could not be granted immediately. 
                   [Total Latch Wait Time]    Total latch wait time (in milliseconds) for latch requests in the last second
                   [Lock Waits Per Sec]       How many users waited to acquire a lock over the past second.  
                   [Number of Deadlocks/sec]  The number of lock requests that resulted in a deadlock. 
                   [Batch Requests Per sec]   Number of batch requests that SQL Server receives per second. 
    
     Dependencies: NONE
    
     Tested on:    SQL Server 2005, 2008, 2012
    
     Usage:        Standalone
    
     Example:      EXEC spGetKPI_Top14 10
    
    ***********************************************************************************************************/
    SET NOCOUNT ON
                                                              /***********************
                                                              ** Declare supporting data structures
                                                             ***********************/
    DECLARE
       @sDelayDuration   AS CHAR(8),
       @nBuffCachHit     AS Numeric(10,2),
       @iPageLife        AS INT,
       @biDeadLock       AS BIGINT,
       @iUserCon         AS INT,
       @dtStart          AS DATETIME,
       @sStartDate       AS VARCHAR(20),
       @fSeconds         AS FLOAT,
       @iBatchStart      AS INT,
       @iBatchEnd        AS INT,
       @iLogInStart      AS INT,
       @iLogInEnd        AS INT,
       @iLogOutStart     AS INT,
       @iLogOutEnd       AS INT,
       @iPageSplitStr    AS INT,
       @iPageSplitEnd    AS INT,
       @iLatchStart      AS INT,
       @iLatchEnd        AS INT,
       @iLatchTmStart    AS INT,
       @iLatchTmEnd      AS INT,
       @iLockWaitStart   AS INT,
       @iLockWaitEnd     AS INT
                                                              /***********************
                                                              ** Assign Variables.
                                                             ***********************/
    SET @dtStart = GETDATE()
    
    SET @sDelayDuration ='00:00:' + CAST(@iDelay AS VARCHAR)
    
    SET @iBatchStart = (SELECT cntr_value FROM sys.dm_os_performance_counters WHERE counter_name ='Batch Requests/sec')
    SET @iLogInStart = (SELECT cntr_value FROM sys.dm_os_performance_counters WHERE counter_name ='Logins/sec')
    SET @iLogOutStart = (SELECT cntr_value FROM sys.dm_os_performance_counters WHERE counter_name ='Logouts/sec')
    SET @iPageSplitStr =  (SELECT cntr_value FROM sys.dm_os_performance_counters WHERE counter_name ='page splits/sec')
    SET @iUserCon = (SELECT cntr_value FROM sys.dm_os_performance_counters WHERE counter_name ='User Connections');
    SET @iLatchStart = (SELECT cntr_value FROM sys.dm_os_performance_counters WHERE counter_name ='Latch Waits/sec');
    SET @iLatchTmStart = (SELECT cntr_value FROM sys.dm_os_performance_counters WHERE counter_name ='Total Latch Wait Time (ms)');
    SET @iLockWaitStart = (SELECT cntr_value FROM sys.dm_os_performance_counters WHERE counter_name ='Lock Waits/sec' And Instance_Name = '_Total');
    
    
    SET @nBuffCachHit = 
       (SELECT cast(cntr_value as float) FROM sys.dm_os_performance_counters WHERE counter_name = 'Buffer cache hit ratio') 
       /
       (SELECT cast(cntr_value AS FLOAT) FROM sys.dm_os_performance_counters WHERE counter_name = 'Buffer cache hit ratio base') *100
    
    SET @biDeadLock = (SELECT cntr_value FROM sys.dm_os_performance_counters WHERE counter_name = 'Number of Deadlocks/sec' AND instance_name = 'Database')
    SET @iPageLife = (SELECT cntr_value FROM sys.dm_os_performance_counters WHERE object_name LIKE '%Buffer Manager%' AND counter_name = 'Page life expectancy')
    SET @sStartDate = @dtStart;
    
    WAITFOR DELAY @sDelayDuration
    
    SET @fSeconds = DATEDIFF(ss, @dtStart, GETDATE())
    SET @iBatchEnd = (SELECT cntr_value FROM sys.dm_os_performance_counters WHERE counter_name ='Batch Requests/sec')
    SET @iLogInEnd = (SELECT cntr_value FROM sys.dm_os_performance_counters WHERE counter_name ='Logins/sec')
    SET @iLogOutEnd = (SELECT cntr_value FROM sys.dm_os_performance_counters WHERE counter_name ='Logouts/sec')
    SET @iPageSplitEnd = (SELECT cntr_value FROM sys.dm_os_performance_counters WHERE counter_name ='page splits/sec')
    SET @iLatchEnd = (SELECT cntr_value FROM sys.dm_os_performance_counters WHERE counter_name ='Latch Waits/sec')
    SET @iLatchTmEnd = (SELECT cntr_value FROM sys.dm_os_performance_counters WHERE counter_name ='Total Latch Wait Time (ms)');
    SET @iLockWaitEnd = (SELECT cntr_value FROM sys.dm_os_performance_counters WHERE counter_name ='Lock Waits/sec' And Instance_Name = '_Total');
                                                              /***********************
                                                              ** Display Results.
                                                             ***********************/
    SELECT TOP 1
       @dtStart                                                                                        AS [Event DateTime],
       SQLProcessUtilization                                                                           AS [SQL Proc Utiliz %],
       SystemIdle                                                                                      AS [CPU Idle %],
       100 - SystemIdle - SQLProcessUtilization                                                        AS [Other Proc Utiliz %],
       @iUserCon                                                                                       AS [User Connections],
       CAST((@iLogInEnd - @iLogInStart)/ @fSeconds AS Numeric(10,2))                                   AS [Logins Per Sec],
       CAST((@iLogOutEnd - @iLogOutStart)/ @fSeconds AS Numeric(10,2))                                 AS [Logouts Per Sec],
       CASE WHEN (@ibatchEnd - @iBatchStart) = 0 THEN 
          CAST(0.00 AS Numeric(10,2))
       ELSE
             CAST((CAST((@iPageSplitEnd -@iPageSplitStr) AS FLOAT)/
                   CAST((@ibatchEnd - @iBatchStart) AS FLOAT) * 100) AS Numeric(10,2))  
       END                                                                                             AS [% Page Splits Per Batch],
       CAST(@nBuffCachHit AS VARCHAR)                                                                  AS [Buffer Cache Hit Ratio %],     
       @iPageLife                                                                                      AS [Page Life Expectancy],   
       CAST((@iLatchEnd - @iLatchStart)/ @fSeconds AS Numeric(10,2))                                   AS [Latch Waits Per Sec],
       CAST((@iLatchTmEnd - @iLatchTmStart)/ @fSeconds AS Numeric(10,2))                               AS [Total Latch Wait Time (ms)],
       CAST((@iLockWaitEnd - @iLockWaitStart)/ @fSeconds AS Numeric(10,2))                             AS [Lock Waits Per Sec],
       CAST(@biDeadLock AS NUMERIC(10,2))                                                              AS [Number of Deadlocks/sec],
       CAST((@ibatchEnd - @iBatchStart)/ @fSeconds AS Numeric(10,2))                                   AS [Batch Requests Per sec]
    FROM
       (
       SELECT
          record.value('(./Record/@id)[1]', 'int')                                                     AS record_id,
          record.value('(./Record/SchedulerMonitorEvent/SystemHealth/SystemIdle)[1]', 'int')           AS SystemIdle,
          record.value('(./Record/SchedulerMonitorEvent/SystemHealth/ProcessUtilization)[1]', 'int')   AS SQLProcessUtilization,
          timestamp
       FROM
          (
          SELECT
             timestamp, CONVERT(xml, record) AS record
          FROM
             sys.dm_os_ring_buffers
          WHERE
             ring_buffer_type = N'RING_BUFFER_SCHEDULER_MONITOR' AND
             record LIKE '%<SystemHealth>%'
          ) AS x
       ) AS y
    ORDER BY
       record_id desc
    GO

    public by wassim  3566  1  5  0

    how to replace line in file java example

    replacement line java file
    package com.example;    
    import java.io.BufferedWriter;
        import java.io.File;
        import java.io.FileNotFoundException;
        import java.io.FileWriter;
        import java.util.Scanner;
        public class FileIOTest {
        static StringBuffer stringBufferOfData = new StringBuffer();
        static String filename = null;
        static Scanner sc = new Scanner(System.in);//initiliaze scanner to get user input
        
        
        public static void main(String[] args) {
        boolean fileRead = readFile();//call the method to read the file with the files name
        if (fileRead) {//if the read file was successfull
        replacement();//call method to get text to replace, replacement text and output replaced String buffer
        writeToFile();
        }
        System.exit(0);//exit once app is done
        }
        
        
        
        private static boolean readFile() {
        System.out.println("Please enter your files name and path i.e C:\\test.txt: ");//prompt for file name
        filename = sc.nextLine();//read in the file name
        Scanner fileToRead = null;
        try {
        fileToRead = new Scanner(new File(filename)); //point the scanner method to a file
        //check if there is a next line and it is not null and then read it in
        for (String line; fileToRead.hasNextLine() && (line = fileToRead.nextLine()) != null; ) {
        System.out.println(line);//print each line as its read
        stringBufferOfData.append(line).append("\r\n");//this small line here is to appened all text read in from the file to a string buffer which will be used to edit the contents of the file
        }
        fileToRead.close();//this is used to release the scanner from file
        return true;
        } catch (FileNotFoundException ex) {//if the file cannot be found an exception will be thrown
        System.out.println("The file " + filename + " could not be found! " + ex.getMessage());
        return false;
        } finally {//if an error occurs now we close the file to exit gracefully
        fileToRead.close();
        return true;
        }
        /* The below is another way in which to read the file, however i think the shorter method would be the scanner class
        The reason for this is the below commented method uses 5 extra imports:
        import java.io.BufferedReader;
        import java.io.DataInputStream;
        import java.io.FileInputStream;
        import java.io.IOException;
        import java.io.InputStreamReader;
        *//*
        try {
        BufferedReader reader = new BufferedReader(new InputStreamReader(new DataInputStream(new FileInputStream(filename))));
        for (String line; (line = reader.readLine()) != null;) {
        System.out.println(line);
        sb.append(line).append("\r\n");//this small line here is to appened all text read in from the file to a string buffer which will be used to edit the contents of the file
        }
        } catch (IOException ex) {
        System.out.println("The file " + filename + " could not be found or opened! "+ex.getMessage());
        System.exit(0);
        }
        */
        }
        private static void writeToFile() {
        try {
        BufferedWriter bufwriter = new BufferedWriter(new FileWriter(filename));
        bufwriter.write(stringBufferOfData.toString());//writes the edited string buffer to the new file
        bufwriter.close();//closes the file
        } catch (Exception e) {//if an exception occurs
        System.out.println("Error occured while attempting to write to file: " + e.getMessage());
        }
        }
        private static void replacement() {
        System.out.println("Please enter the contents of a line you would like to edit: ");//prompt for a line in file to edit
        String lineToEdit = sc.nextLine();//read the line to edit
        System.out.println("Please enter the the replacement text: ");//prompt for a line in file to replace
        String replacementText = sc.nextLine();//read the line to replace
        //System.out.println(sb);//used for debugging to check that my stringbuffer has correct contents and spacing
        int startIndex = stringBufferOfData.indexOf(lineToEdit);//now we get the starting point of the text we want to edit
        int endIndex = startIndex + lineToEdit.length();//now we add the staring index of the text with text length to get the end index
        stringBufferOfData.replace(startIndex, endIndex, replacementText);//this is where the actual replacement of the text happens
        System.out.println("Here is the new edited text:\n" + stringBufferOfData); //used to debug and check the string was replaced
        }
        }
    
    

    external by TomOne  320  0  3  0

    Diff Dropbox replacement variables

    Diff Dropbox replacement variables: dropbox-replacement-variables.diff
    diff -nurw dropbox/dropbox.nuspec dropbox-push-directly/dropbox.nuspec
    --- dropbox/dropbox.nuspec	Wed Aug  6 20:43:17 2014
    +++ dropbox-push-directly/dropbox.nuspec	Mon Aug 11 15:52:44 2014
    @@ -1,9 +1,9 @@
     <?xml version="1.0" encoding="utf-8"?>
     <package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
       <metadata>
         <id>dropbox</id>
         <title>Dropbox</title>
    -    <version>{{PackageVersion}}</version>
    +    <version>2.10.27.20140811</version>
         <authors>Dropbox</authors>
         <owners>Rob Reynolds</owners>
         <summary>Dropbox is a free service that lets you bring all your photos, docs, and videos anywhere.</summary>
    diff -nurw dropbox/tools/chocolateyInstall.ps1 dropbox-push-directly/tools/chocolateyInstall.ps1
    --- dropbox/tools/chocolateyInstall.ps1	Wed Aug  6 20:43:17 2014
    +++ dropbox-push-directly/tools/chocolateyInstall.ps1	Mon Aug 11 15:53:44 2014
    @@ -1,9 +1,9 @@
     $packageName = 'dropbox'
    -$version = '{{PackageVersion}}'
    +$version = '2.10.27'
     $uninstallRegistryPath = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall\Dropbox'
     $filePath = "$env:TEMP\chocolatey\$packageName"
     $fileFullPath = "$filePath\${packageName}Install.exe"
    -$url = 'https://dl-web.dropbox.com/u/17/Dropbox {{PackageVersion}}.exe'
    +$url = 'https://dl-web.dropbox.com/u/17/Dropbox 2.10.27.exe'
     
     $fileType = 'exe'
     $silentArgs = '/S'
    
    
    

    external by James Swineson  240  0  3  0

    A good /etc/mysql/my.cnf replacement which solves mysql/percona fail to start problem. Worked for me.

    A good /etc/mysql/my.cnf replacement which solves mysql/percona fail to start problem. Worked for me. : my.cnf
    # https://www.digitalocean.com/community/questions/mysql-server-keeps-stopping-unexpectedly
    # http://pastie.org/8665237
    # Generated by Percona Configuration Wizard (http://tools.percona.com/) version REL5-20120208
    
    [mysql]
    
    # CLIENT #
    port                           = 3306
    socket                         = /var/run/mysqld/mysqld.sock
    
    [mysqld]
    
    # GENERAL #
    user                           = mysql
    default-storage-engine         = InnoDB
    socket                         = /var/run/mysqld/mysqld.sock
    pid-file                       = /var/run/mysqld/mysqld.pid
    performance_schema             = off
    
    # MyISAM #
    key-buffer-size                = 32M
    myisam-recover                 = FORCE,BACKUP
    
    # SAFETY #
    max-allowed-packet             = 16M
    max-connect-errors             = 1000000
    
    # DATA STORAGE #
    datadir                        = /var/lib/mysql/
    
    # BINARY LOGGING #
    log-bin                        = /var/lib/mysql/mysql-bin
    expire-logs-days               = 14
    sync-binlog                    = 1
    
    # CACHES AND LIMITS #
    tmp-table-size                 = 32M
    max-heap-table-size            = 32M
    query-cache-type               = 0
    query-cache-size               = 0
    max-connections                = 500
    thread-cache-size              = 50
    open-files-limit               = 65535
    table-definition-cache         = 1024
    table-open-cache               = 2048
    
    # INNODB #
    innodb-flush-method            = O_DIRECT
    innodb-log-files-in-group      = 2
    innodb-log-file-size           = 64M
    innodb-flush-log-at-trx-commit = 1
    innodb-file-per-table          = 1
    innodb-buffer-pool-size        = 128M
    
    # LOGGING #
    log-error                      = /var/lib/mysql/mysql-error.log
    log-queries-not-using-indexes  = 1
    slow-query-log                 = 1
    slow-query-log-file            = /var/lib/mysql/mysql-slow.log
    
    

    external by Github  11  0  0  0

    Will I get paid for overtime? http://aiapets.com/what-is-a-good-replacement-for-nexium.pdf sleep what is a good replacement for nexium visiting early Olympic 1,500 meters champion Asli Cakir Alptekin is one of dozens of Turkish athletes to fail recent...

    Will I get paid for overtime? http://aiapets.com/what-is-a-good-replacement-for-nexium.pdf sleep what is a good replacement for nexium visiting early Olympic 1,500 meters champion Asli Cakir Alptekin is one of dozens of Turkish athletes to fail recent tests while host nation Russia has more than 40 currently serving bans - as well as several more
    Will I get paid for overtime? http://aiapets.com/what-is-a-good-replacement-for-nexium.pdf sleep what is a good replacement for nexium visiting early  Olympic 1,500 meters champion Asli Cakir Alptekin is one of dozens of Turkish athletes to fail recent tests while host nation Russia has more than 40 currently serving bans - as well as several more back in action having served their time for positives.
     
    
    
    • Public Snippets
    • Channels Snippets