working on it ...

Filters

Explore Public Snippets

Sort by

Found 7,331 snippets matching: clean

    public by strykerraven  188255  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 cghersi  5412  14  9  0

    C#: How to remove a given tag (and all its content) from an HTML page

    This method removes the content of all the occurrences of the given tag in the given page
    static public string RemoveHtmlTag(string pageString, string tagName)
    {
        string output = pageString;
        int exprIni = 0;
        int firstChar = 0;
        int lastChar = 0;
    
        // find html element
        exprIni = output.IndexOf("<" + tagName, 0, output.Length,
                                        StringComparison.InvariantCultureIgnoreCase);
        while (exprIni > 0)
        {
            // extract the html
            firstChar = exprIni;
    
            // find <tag ... />
            lastChar = output.IndexOf("/>", (firstChar + 1)) + 1;
            int nextCloseTag = output.IndexOf('>', (firstChar + 1));
    
            // closed with </tag> marker..
            if ((lastChar <= 0) || (nextCloseTag < lastChar))
            {
                // find </tag>
                lastChar = output.IndexOf("</" + tagName, (firstChar + 1), (output.Length - firstChar - 1),
                                                                StringComparison.InvariantCultureIgnoreCase);
                lastChar = output.IndexOf('>', (lastChar + 1));
            }
    
            if ((firstChar < 0) || (lastChar <= 0) || (firstChar == lastChar))
                return output.Substring(0, firstChar);
            else
            {
                output = String.Format("{0} {1}",
                            output.Substring(0, firstChar).Trim(),
                            output.Substring((lastChar + 1), (output.Length - lastChar - 1)).Trim());
            }
            exprIni = output.IndexOf("<" + tagName, 0, output.Length,
                                        StringComparison.InvariantCultureIgnoreCase);
        }
    
        return output;
    }
     

    public by cghersi  3839  0  6  3

    How to clean all the data from the tables of a MS SQL Server database

    This procedure allows to clean all the data from all the tables of the given DB. Use @rese_ident = 1 if you want to restart the identity columns from the default value.
    CREATE PROCEDURE [dbo].[CleanDB]
    	@db_name sysname = 'MyDBName',
    	@reset_ident tinyint = 0
    as
    begin
    	set nocount on
    
    	if @db_name is null
    		set @db_name = db_name()
    
    	if @reset_ident is null
    		set @reset_ident = 0
    
    	if not exists(select * from sys.databases where name = @db_name and database_id > 4)
    	begin
    		raiserror('Database does not exist or it can not be cleared', 16, 1)
    		return
    	end
    
    	declare @recovery_mode sysname
    
    	select @recovery_mode = cast(DatabasePropertyEx(@db_name,'Recovery') as sysname)
    
    	if @recovery_mode <> 'Simple'
    	begin
    		declare @ncmd nvarchar(max)
    
    		print '-- Changing database recovery mode to SIMPLE'
    
    		set @ncmd = 'alter database [' + @db_name + '] set recovery simple'
    
    		print @ncmd
    
    		exec sp_executesql @ncmd
    	end
    
    	-------------------------------------------------------------------------------------------
    	-- prepare table with tables list
    
    	create table #temp_tables
    	(
    		rec_id int identity(1, 1) primary key not null,
    		schema_name sysname not null,
    		table_name sysname not null
    	)
    
    	declare @n_cmd nvarchar(max)
    
    	set @n_cmd = 'insert into #temp_tables (schema_name, table_name) select ss.name as schema_name, st.name as table_name from [' + @db_name + '].sys.tables as st inner join [' + @db_name + '].sys.schemas as ss on ss.schema_id = st.schema_id where ss.name <> ''sys'' '
    
    	exec sp_executesql @n_cmd
    
    	-------------------------------------------------------------------------------------------
    	-- disable constraints
    
    	declare @table_name sysname
    	declare @schema_name sysname
    	declare @counter_max int
    	declare @counter int
    
    	select @counter_max = max(rec_id) from #temp_tables
    
    	if @counter_max is null
    		set @counter_max = 0
    
    	declare @object_name nvarchar(max)
    
    	set @counter = @counter_max
    	while @counter > 0
    	begin
    		set @table_name = null
    		set @schema_name = null
    
    		select @table_name = table_name, @schema_name = schema_name from #temp_tables where rec_id = @counter
    
    		if @table_name is null or @schema_name is null
    			break
    
    		set @object_name = N'[' + @db_name + N'].[' + @schema_name + N'].[' + @table_name + N']'
    
    		set @n_cmd = N'alter table ' + @object_name + N' nocheck constraint all'
    
    		print @n_cmd
    
    		begin try
    			exec sp_executesql @n_cmd
    		end try
    		begin catch
    			print '-------------------------------------------------------------------------'
    			print 'ERROR - Could not disable constraints for table ' + @object_name
    			print error_message()
    			print '-------------------------------------------------------------------------'
    		end catch
    
    		set @counter = @counter - 1
    	end
    
    	----------------------------------------------------------------------------------------------
    	-- delete records from tables
    
    	set @counter = @counter_max
    	while @counter > 0
    	begin
    		set @table_name = null
    		set @schema_name = null
    
    		select @table_name = table_name, @schema_name = schema_name from #temp_tables where rec_id = @counter
    
    		if @table_name is null or @schema_name is null
    			break
    
    		set @object_name = N'[' + @db_name + N'].[' + @schema_name + N'].[' + @table_name + N']'
    
    		set @n_cmd = 'delete ' + @object_name
    
    		print @n_cmd
    
    		begin try
    			exec sp_executesql @n_cmd
    
    			if @reset_ident = 1
    			begin
    				set @n_cmd = 'if exists(select * from [' + @db_name + '].sys.columns where object_id = object_id(''' + 
    					@object_name + ''') and is_identity = 1) dbcc checkident(''' + @object_name + ''', reseed)'
    
    				print @n_cmd
    
    				exec sp_executesql @n_cmd
    			end
    		end try
    		begin catch
    			print '-------------------------------------------------------------------------'
    			print 'ERROR - Could not clean table ' + @object_name
    			print error_message()
    			print '-------------------------------------------------------------------------'
    		end catch
    
    		set @counter = @counter - 1
    	end
    
    	-----------------------------------------------------------------------------------------------
    	-- enable constraints
    
    	set @counter = @counter_max
    	while @counter > 0
    	begin
    		set @table_name = null
    		set @schema_name = null
    
    		select @table_name = table_name, @schema_name = schema_name from #temp_tables where rec_id = @counter
    
    		if @table_name is null or @schema_name is null
    			break
    
    		set @n_cmd = 'alter table [' + @db_name + '].[' + @schema_name + '].[' + @table_name + '] with check check constraint all'
    
    		print @n_cmd
    
    		begin try
    			exec sp_executesql @n_cmd
    		end try
    		begin catch
    			print '-------------------------------------------------------------------------'
    			print 'ERROR - Could not enable constraints for table ' + @object_name
    			print error_message()
    			print '-------------------------------------------------------------------------'
    		end catch
    
    		set @counter = @counter - 1
    	end
    
    	drop table #temp_tables
    
    	---------------------------------------------------------------------------------------------------
    	-- restore database recovery mode
    
    	if @recovery_mode <> 'Simple'
    	begin
    		declare @ncmd2 nvarchar(max)
    
    		print '-- Restoring database recovery mode'
    
    		set @ncmd2 = 'alter database [' + @db_name + '] set recovery ' + @recovery_mode
    
    		print @ncmd2
    
    		exec sp_executesql @ncmd2
    	end
    
    end

    public by cghersi  2340  0  5  0

    Batch command to clean folders

    This command should be issued from a DOS prompt from the root folder where the folders to purge belong. The command deletes the folders named "CVS" recursively from the root folder to the end of the tree.
    for /d /r . %d in (CVS) do @if exist "%d" rd /s /q "%d"

    public by shebin512  3047  1  5  0

    Bash Script to clean magento 1.x Cache

    Magento 1.x cache clean Bash script. 1. Save the code in "/path/of/the/file/.sh" 2. Give executable permission for the file "chmod a+x /path/of/the/file/.sh" 3. Run the script from your magento document root like $ /path/of/the/file/.sh
    #!/bin/bash 
    # author Shebin Sheikh
    
    # function to remove the magento cache.
    function mageCacheClear {
    
    	local current_dir=$(pwd);
    	#echo $current_dir
    	#exit
    
    	if [[ -f "$current_dir/app/Mage.php" ]]; then
    		#echo "Inside Mage Doc root"
    		rm -vrf var/{cache,full_page_cache}/ media/{js,css}/
    	else
    		echo -e "Not inside A magento 1.X's document root!"
    		exit $?
    	fi
    
    }
    
    mageCacheClear # call the function

    public by Omranic  2986  0  3  0

    Clean Install – OS X 10.11 El Capitan

    Clean Install – OS X 10.11 El Capitan: gistfile1.md
    ### OS X Preferences
    ---
    
    most of these require logout/restart to take effect
    
    ```bash
    # Enable character repeat on keydown
    defaults write -g ApplePressAndHoldEnabled -bool false
    
    # Set a shorter Delay until key repeat
    defaults write NSGlobalDomain InitialKeyRepeat -int 12
    
    # Set a blazingly fast keyboard repeat rate
    defaults write NSGlobalDomain KeyRepeat -int 0
    
    # Disable window animations ("new window" scale effect)
    defaults write NSGlobalDomain NSAutomaticWindowAnimationsEnabled -bool false
    
    # Turn on dashboard-as-space
    defaults write com.apple.dashboard enabled-state 2
    
    # Use plain text mode for new TextEdit documents
    defaults write com.apple.TextEdit RichText -int 0
    
    # Make top-right hotspot start screensaver
    defaults write com.apple.dock wvous-tr-corner -int 5 && \
    defaults write com.apple.dock wvous-tr-modifier -int 0
    
    # Set default Finder location to home folder (~/)
    defaults write com.apple.finder NewWindowTarget -string "PfLo" && \
    defaults write com.apple.finder NewWindowTargetPath -string "file://${HOME}"
    
    # Expand save panel by default
    defaults write NSGlobalDomain NSNavPanelExpandedStateForSaveMode -bool true
    
    # Disable ext change warning
    defaults write com.apple.finder FXEnableExtensionChangeWarning -bool false
    
    # Check for software updates daily, not just once per week
    defaults write com.apple.SoftwareUpdate ScheduleFrequency -int 1
    
    # Use current directory as default search scope in Finder
    defaults write com.apple.finder FXDefaultSearchScope -string "SCcf"
    
    # Show Path bar in Finder
    defaults write com.apple.finder ShowPathbar -bool true
    
    # Show Status bar in Finder
    defaults write com.apple.finder ShowStatusBar -bool true
    
    # Show icons for hard drives, servers, and removable media on the desktop
    defaults write com.apple.finder ShowExternalHardDrivesOnDesktop -bool true && \
    defaults write com.apple.finder ShowHardDrivesOnDesktop -bool true && \
    defaults write com.apple.finder ShowMountedServersOnDesktop -bool true && \
    defaults write com.apple.finder ShowRemovableMediaOnDesktop -bool true
    
    # Avoid creating .DS_Store files on network volumes
    defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool true
    
    # Disable disk image verification
    defaults write com.apple.frameworks.diskimages skip-verify -bool true && \
    defaults write com.apple.frameworks.diskimages skip-verify-locked -bool true && \
    defaults write com.apple.frameworks.diskimages skip-verify-remote -bool true
    
    # Trackpad: map bottom right corner to right-click
    defaults write com.apple.driver.AppleBluetoothMultitouch.trackpad TrackpadCornerSecondaryClick -int 2 && \
    defaults write com.apple.driver.AppleBluetoothMultitouch.trackpad TrackpadRightClick -bool true && \
    defaults -currentHost write NSGlobalDomain com.apple.trackpad.trackpadCornerClickBehavior -int 1 && \
    defaults -currentHost write NSGlobalDomain com.apple.trackpad.enableSecondaryClick -bool true
    
    # Enable the Develop menu and the Web Inspector in Safari
    defaults write com.apple.Safari IncludeInternalDebugMenu -bool true && \
    defaults write com.apple.Safari IncludeDevelopMenu -bool true && \
    defaults write com.apple.Safari WebKitDeveloperExtrasEnabledPreferenceKey -bool true && \
    defaults write com.apple.Safari com.apple.Safari.ContentPageGroupIdentifier.WebKit2DeveloperExtrasEnabled -bool true && \
    defaults write NSGlobalDomain WebKitDeveloperExtras -bool true
    
    # Show the ~/Library folder
    chflags nohidden ~/Library
    
    # Show absolute path in finder's title bar. 
    defaults write com.apple.finder _FXShowPosixPathInTitle -bool YES
    
    # Enable text copying from Quick Look
    defaults write com.apple.finder QLEnableTextSelection -bool YES
    
    # Auto-play videos when opened with QuickTime Player
    defaults write com.apple.QuickTimePlayerX MGPlayMovieOnOpen 1
    
    # Enable AirDrop over Ethernet and on unsupported Macs
    defaults write com.apple.NetworkBrowser BrowseAllInterfaces -bool true
    
    # Disable WebkitNightly.app's homepage
    defaults write org.webkit.nightly.WebKit StartPageDisabled -bool true
    
    ```
    
    
    
    ###Shell
    
    ---
    
    ####Switch to z-shell
    
    ```bash
    curl -L https://github.com/robbyrussell/oh-my-zsh/raw/master/tools/install.sh | sh
    ```
    
    
    ####Homebrew
    
    ```bash
    # install package manager
    ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
    
    # install homebrew packages
    brew install \
    tree \
    node \
    ssh-copy-id \
    wget \
    jpegoptim \
    pngcrush \
    colordiff \
    imagemagick \
    graphicsmagick \
    ack \
    caskroom/cask/brew-cask
    ```
    ####Homebrew Web Server Packages
    ```bash
    brew install \
    dnsmasq \
    nginx \
    mariadb \
    redis \
    memcached \
    libmemcached \
    ```
    
    ####Homebrew Cask Apps & Fonts
    
    ```bash
    # add support for fonts
    brew tap caskroom/fonts
    
    #add dev/beta versions
    brew tap caskroom/versions
    
    #install mac apps & fonts
    brew cask install \
    font-source-code-pro \
    adobe-creative-cloud \
    blueharvest \
    cleanmymac \
    cocktail \
    ghostlab \
    coda \
    sublime-text-dev \
    virtualbox \
    coderunner \
    google-chrome \
    firefox \
    codekit \
    iterm2-beta \
    sequel-pro \
    querious \
    imageoptim \
    imagealpha \
    xquartz \
    simpholders-2-alpha \
    handbrake \
    vagrant \
    ksdiff \
    spotify
    ```
    
    
    ####Update .zshrc
    
    ```bash
    wget https://gist.githubusercontent.com/saetia/2764210/raw/ab099b587689640eb32cbc1afdb6a19b62be7fb0/.zshrc -O \
    ~/.zshrc
    
    #syntax highlighting
    git clone git://github.com/zsh-users/zsh-syntax-highlighting.git \
    ~/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting
    ```
    
    ####Set hostname
    
    ```bash
    sudo scutil --set HostName Work
    ```
    
    ###Agree To Xcode
    ```bash
    sudo xcrun cc
    ```
    
    ###Git
    
    ---
    
    ####Setup Github
    
    ```bash
    ssh-keygen -t rsa -C "saetia@gmail.com"
    
    #copy ssh key to clipboard for adding to github.com
    pbcopy < ~/.ssh/id_rsa.pub
    
    #test connection
    ssh -T git@github.com
    
    #set git config values
    git config --global user.name "Joel Glovacki" && \
    git config --global user.email "saetia@gmail.com" && \
    git config --global github.user saetia && \
    git config --global core.editor "subl -w" && \
    git config --global color.ui true && \
    git config --global push.default simple
    
    #token
    git config --global github.token your_token_here
    ```
    
    ###Coda
    
    ---
    
    ####Install markdown support
    
    ```bash
    git clone https://github.com/bobthecow/Markdown.mode.git \
    ~/Library/Application\ Support/Coda\ 2/modes/Markdown.mode
    ```
    
    ###Sublime Text
    
    ---
    
    ####Install Soda Theme
    
    ```bash
    git clone git://github.com/buymeasoda/soda-theme.git \
    ~/Library/Application\ Support/Sublime\ Text\ 3/Packages/Theme\ -\ Soda
    ```
    
    ####Install Tomorrow Night Eighties Themes
    
    ```bash
    #Sublime Text
    git clone git://github.com/chriskempson/textmate-tomorrow-theme.git \
    ~/Library/Application\ Support/Sublime\ Text\ 3/Packages/Color\ Scheme\ -\ Tomorrow
    
    #iTerm2
    wget https://raw.githubusercontent.com/mbadolato/iTerm2-Color-Schemes/master/schemes/Tomorrow%20Night%20Eighties.itermcolors \
    -O ~/Downloads/Tomorrow\ Night\ Eighties.itermcolors && open ~/Downloads/Tomorrow\ Night\ Eighties.itermcolors
    
    #Xcode
    mkdir -p ~/Library/Developer/Xcode/UserData/FontAndColorThemes && \
    wget https://raw.githubusercontent.com/chriskempson/tomorrow-theme/master/Xcode%204/Tomorrow%20Night%20Eighties.dvtcolortheme -O \
    ~/Library/Developer/Xcode/UserData/FontAndColorThemes/Tomorrow\ Night\ Eighties.dvtcolortheme
    ```
    
    ####Settings
    
    ```json
    {
    	"close_windows_when_empty": true,
    	"color_scheme": "Packages/Color Scheme - Tomorrow/Tomorrow-Night-Eighties.tmTheme",
    	"draw_indent_guides": false,
    	"font_face": "Source Code Pro",
    	"font_size": 22.0,
    	"highlight_modified_tabs": true,
    	"ignored_packages":
    	[
    		"Vintage"
    	],
    	"show_full_path": true,
    	"show_tab_close_buttons": false,
    	"spell_check": false,
    	"tab_size": 2,
    	"theme": "Soda Light.sublime-theme",
    	"word_separators": "./\\()\"'-:,.;<>~!@#%^&*|+=[]{}`~?"
    }
    
    ```
    
    ####Key Bindings
    
    
    ```json
    [
    	{ "keys": ["super+b"], "command": "expand_selection", "args": {"to": "brackets"} },
    	{ "keys": ["super+f"], "command": "show_panel", "args": {"panel": "replace"} },
    	{ "keys": ["super+alt+f"], "command": "show_panel", "args": {"panel": "find"} }
    ]
    ```
    
    
    ####Snippets
    
    ```bash
    git clone git@github.com:co-b/sublime-snippets.git \
    ~/Library/Application\ Support/Sublime\ Text\ 3/Packages/CoB
    ```
    
    ### iOS
    ---
    
    ```bash
    sudo gem install cocoapods
    pod setup
    ```
    
    ### Ruby
    ---
    
    #### Ruby version manager
    
    ```bash
    curl -L https://get.rvm.io | bash -s stable --rails
    ```
    
    #### Gems
    ```bash
    gem install pygmentize growl guard guard-phpunit bropages
    ```
    
    
    
    ### Node
    ---
    
    #### Packages
    
    ```bash
    npm install -g coffee-script bower
    ```
    
    
    
    
    ### Vagrant
    ---
    
    ```bash
    vagrant plugin install vagrant-hostsupdater
    ```
    
    
    ### PHP
    ---
    
    ```bash
    #install php-fpm
    brew tap homebrew/dupes && \
    brew tap homebrew/versions && \
    brew tap homebrew/dupes && \
    brew install php70 \
    --with-fpm \
    --without-apache \
    --with-mysql
    
    #setup daemon
    ln -sfv /usr/local/opt/php70/*.plist ~/Library/LaunchAgents && \
    launchctl load ~/Library/LaunchAgents/homebrew.mxcl.php70.plist
    ```
    
    ####PHP-Redis
    ```bash
    #brew install php70-redis
    brew install --HEAD homebrew/php/php70-redis
    ```
    
    ####MariaDB
    
    ```bash
    
    #setup daemon
    ln -sfv /usr/local/opt/mariadb/*.plist ~/Library/LaunchAgents && \
    launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mariadb.plist
    
    #initial setup
    mysql_install_db
    
    #secure mariadb
    mysql_secure_installation
    ```
    
    ####NGINX
    
    ```bash
    sudo cp -v /usr/local/opt/nginx/*.plist /Library/LaunchDaemons/ && 
    sudo chown root:wheel /Library/LaunchDaemons/homebrew.mxcl.nginx.plist &&
    sudo launchctl load /Library/LaunchDaemons/homebrew.mxcl.nginx.plist
    ```
    
    ### Local Web Server
    ---
    
    #### Add DNS Domains, Enable dnsmasq daemon
    
    This will route requests to any url ending in **.build** back to your own computer. The goal is to use urls like http://example.com.build for development while you work on http://example.com
    
    ```bash
    mkdir -pv $(brew --prefix)/etc/ && \
    echo 'address=/.build/127.0.0.1' > $(brew --prefix)/etc/dnsmasq.conf && \
    sudo cp -v $(brew --prefix dnsmasq)/homebrew.mxcl.dnsmasq.plist /Library/LaunchDaemons && \
    sudo launchctl load -w /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist && \
    sudo mkdir -v /etc/resolver && \
    sudo zsh -c 'echo "nameserver 127.0.0.1" > /etc/resolver/build'
    
    #flush cache
    sudo discoveryutil mdnsflushcache && scutil --dns
    ```
    
    ####Enable virtual hosts
    
    This will allow you to serve folders under ~/Sites/ as websites. 
    
    * ~/Sites
      * example.com
        * htdocs
          * index.html
      
    to access this site, visit http://example.com.build
    
    
    ####Match production server paths
    ```bash
    sudo mkdir -p /var/ && sudo ln -s ~/Sites /var/www
    ```
    
    
    
    ![aww yeah](http://i.imgur.com/AmFax.gif)
    
    

    public by lbottaro  8201  26  6  -2

    How to clear a list in python

    This code shows how to clear and remove all items in a list. Note that also any reference to such list will be updated to an empty list.
    # Create a list
    myList = list()
    # Fill the list
    myList.append("a")
    myList.append("ab")
    myList.append("abc")
    # Clear the list
    del myList[0:len(myList)]

    public by libby  2604  0  5  1

    pull with rebase

    Avoid a git merge and interleaving your commits with the commit in the upstream repo. Rebase will stash your local commits, apply the upstream commits, then reapply your local commit keeping the history nice clean.
    Git
    git pull --rebase

    public by TheMetaphysicalCrook  2427  1  5  0

    .dotfiles

    ![](https://assets-cdn.github.com/images/spinners/octocat-spinner-32.gif) [xquartz.sh](/kevinelliott/.dotfiles/blob/master/xquartz.sh) [I guess output is not really necessary here](/kevinelliott/.dotfiles/commit/cfecaff9f0a4af157e29712923ebd788768b7fdb) Jul 14, 2012 ### README.md # .dotfiles Dotfiles for your unix-like system. I've created thi
    From <https://github.com/kevinelliott/.dotfiles>:
    
    Skip to content
    
    [ ](https://github.com/)
    
    [Sign up](/join) [Sign in](/login?return_to=%2Fkevinelliott%2F.dotfiles)
    
    This repository
    
      * [Explore](/explore)
      * [Features](/features)
      * [Enterprise](https://enterprise.github.com/)
      * [Pricing](/pricing)
    
      * [ Watch ](/login?return_to=%2Fkevinelliott%2F.dotfiles) [ 2 ](/kevinelliott/.dotfiles/watchers)
      * [ Star ](/login?return_to=%2Fkevinelliott%2F.dotfiles) [ 13 ](/kevinelliott/.dotfiles/stargazers)
      * [ Fork ](/login?return_to=%2Fkevinelliott%2F.dotfiles) [ 8 ](/kevinelliott/.dotfiles/network)
    
    #  [kevinelliott](/kevinelliott)/**[.dotfiles](/kevinelliott/.dotfiles)** ![](https://assets-cdn.github.com/images/spinners/octocat-spinner-32.gif)
    
      * [ Code ![](https://assets-cdn.github.com/images/spinners/octocat-spinner-32.gif) ](/kevinelliott/.dotfiles)
      * [ Issues ![](https://assets-cdn.github.com/images/spinners/octocat-spinner-32.gif) ](/kevinelliott/.dotfiles/issues)
      * [ Pull requests ![](https://assets-cdn.github.com/images/spinners/octocat-spinner-32.gif) ](/kevinelliott/.dotfiles/pulls)
    
      * [ Pulse ![](https://assets-cdn.github.com/images/spinners/octocat-spinner-32.gif) ](/kevinelliott/.dotfiles/pulse)
      * [ Graphs ![](https://assets-cdn.github.com/images/spinners/octocat-spinner-32.gif) ](/kevinelliott/.dotfiles/graphs)
    
    ### HTTPS clone URL
    
    ### Subversion checkout URL
    
    You can clone with 
    
    HTTPS or 
    
    Subversion. [ ](https://help.github.com/articles/which-remote-url-should-i-use)
    
    [ Download ZIP ](/kevinelliott/.dotfiles/archive/master.zip)
    
    My Unix-like dot files for my shells 
    
      * [ 52  commits ](/kevinelliott/.dotfiles/commits/master)
      * [ 1  branch ](/kevinelliott/.dotfiles/branches)
      * [ 0  releases ](/kevinelliott/.dotfiles/releases)
      * [ Fetching contributors ](/kevinelliott/.dotfiles/graphs/contributors)
    
      1. [ Shell 100.0% ](/kevinelliott/.dotfiles/search?l=bash)
    
    Shell
    
    [ ](/kevinelliott/.dotfiles/find/master) [ ](/kevinelliott/.dotfiles/compare)
    
    _Branch:_ master
    
    Switch branches/tags
    
      * Branches
      * Tags
    
    [ master  ](/kevinelliott/.dotfiles/tree/master)
    
    Nothing to show
    
    Nothing to show
    
    [.dotfiles](/kevinelliott/.dotfiles)/
    
    Latest commit [ 1691986 ](/kevinelliott/.dotfiles/commit/1691986eb0b25e58f304952b52686fcfb518f710) May 20, 2015 ![@kevinelliott](https://avatars1.githubusercontent.com/u/123112?v=3&s=40) [kevinelliott](/kevinelliott) [Stuff and things.](/kevinelliott/.dotfiles/commit/1691986eb0b25e58f304952b52686fcfb518f710)
    
    [Permalink](/kevinelliott/.dotfiles/tree/1691986eb0b25e58f304952b52686fcfb518f710)
    
    Failed to load latest commit information.
    
    ![](https://assets-cdn.github.com/images/spinners/octocat-spinner-32.gif)
    [bin](/kevinelliott/.dotfiles/tree/master/bin)
    [Modify which service runs for redis.](/kevinelliott/.dotfiles/commit/7b21aaa3deedb103c4f84e8e0e830e79bac9ce9d)
    Nov 20, 2013
    
    ![](https://assets-cdn.github.com/images/spinners/octocat-spinner-32.gif)
    [etc](/kevinelliott/.dotfiles/tree/master/etc)
    [Move to more modern bundle no-document, as well as some other little …](/kevinelliott/.dotfiles/commit/27a1845bc0182c46bfcb6776a033f6c3d68f1994)
    Dec 18, 2014
    
    ![](https://assets-cdn.github.com/images/spinners/octocat-spinner-32.gif)
    [.gitmodules](/kevinelliott/.dotfiles/blob/master/.gitmodules)
    [added seinfeld for showing my last public github commit](/kevinelliott/.dotfiles/commit/f19f7005936211299ac7d5086e2bb2037dc61cfb)
    Nov 17, 2011
    
    ![](https://assets-cdn.github.com/images/spinners/octocat-spinner-32.gif)
    [README.md](/kevinelliott/.dotfiles/blob/master/README.md)
    [updated readme](/kevinelliott/.dotfiles/commit/fe075f11280d33a9fb599bba34e6b86fd517aa79)
    Nov 17, 2011
    
    ![](https://assets-cdn.github.com/images/spinners/octocat-spinner-32.gif)
    [aliases.sh](/kevinelliott/.dotfiles/blob/master/aliases.sh)
    [Stuff and things.](/kevinelliott/.dotfiles/commit/1691986eb0b25e58f304952b52686fcfb518f710)
    May 20, 2015
    
    ![](https://assets-cdn.github.com/images/spinners/octocat-spinner-32.gif)
    [autojump.sh](/kevinelliott/.dotfiles/blob/master/autojump.sh)
    [Added autojump.](/kevinelliott/.dotfiles/commit/098717c8994bdb22b6fa03fbbfab8fc384565117)
    Jan 24, 2013
    
    ![](https://assets-cdn.github.com/images/spinners/octocat-spinner-32.gif)
    [base.sh](/kevinelliott/.dotfiles/blob/master/base.sh)
    [Stuff and things.](/kevinelliott/.dotfiles/commit/1691986eb0b25e58f304952b52686fcfb518f710)
    May 20, 2015
    
    ![](https://assets-cdn.github.com/images/spinners/octocat-spinner-32.gif)
    [bash_colors.sh](/kevinelliott/.dotfiles/blob/master/bash_colors.sh)
    [* Add node.js environment configuration](/kevinelliott/.dotfiles/commit/f366a165834ed0362ee9de57dda82d5ccf699c78)
    Jul 13, 2012
    
    ![](https://assets-cdn.github.com/images/spinners/octocat-spinner-32.gif)
    [bash_completion.sh](/kevinelliott/.dotfiles/blob/master/bash_completion.sh)
    [Add support for git 2.1.x's bash completion and prompt support.](/kevinelliott/.dotfiles/commit/9589d4f36e6c8fb44e3089a2ff23baa8c975bc22)
    Oct 20, 2014
    
    ![](https://assets-cdn.github.com/images/spinners/octocat-spinner-32.gif)
    [bash_path.sh](/kevinelliott/.dotfiles/blob/master/bash_path.sh)
    [Added /usr/local/sbin to the PATH for Homebrew.](/kevinelliott/.dotfiles/commit/0295513d7ff8f375094aea225f4bc35dcf4549c4)
    Aug 8, 2012
    
    ![](https://assets-cdn.github.com/images/spinners/octocat-spinner-32.gif)
    [bash_prompt.sh](/kevinelliott/.dotfiles/blob/master/bash_prompt.sh)
    [Work to move to chruby instead of rvm. Unfortunately chruby auto chan…](/kevinelliott/.dotfiles/commit/d01505606cdc97c9f540cbf10aeff6f6584dc3db)
    Jul 21, 2013
    
    ![](https://assets-cdn.github.com/images/spinners/octocat-spinner-32.gif)
    [control.sh](/kevinelliott/.dotfiles/blob/master/control.sh)
    [Add control script and initialization in order to be able to start/st…](/kevinelliott/.dotfiles/commit/06453d3247d85dd97b50a39dcfa8501a16b6b985)
    Jul 18, 2012
    
    ![](https://assets-cdn.github.com/images/spinners/octocat-spinner-32.gif)
    [docker.sh](/kevinelliott/.dotfiles/blob/master/docker.sh)
    [Add docker script.](/kevinelliott/.dotfiles/commit/48464bbc395a298ec9bce647f0e39a43a92d46a3)
    Jul 30, 2014
    
    ![](https://assets-cdn.github.com/images/spinners/octocat-spinner-32.gif)
    [editor.sh](/kevinelliott/.dotfiles/blob/master/editor.sh)
    [Add control script and initialization in order to be able to start/st…](/kevinelliott/.dotfiles/commit/06453d3247d85dd97b50a39dcfa8501a16b6b985)
    Jul 18, 2012
    
    ![](https://assets-cdn.github.com/images/spinners/octocat-spinner-32.gif)
    [git.sh](/kevinelliott/.dotfiles/blob/master/git.sh)
    [Work to move to chruby instead of rvm. Unfortunately chruby auto chan…](/kevinelliott/.dotfiles/commit/d01505606cdc97c9f540cbf10aeff6f6584dc3db)
    Jul 22, 2013
    
    ![](https://assets-cdn.github.com/images/spinners/octocat-spinner-32.gif)
    [go.sh](/kevinelliott/.dotfiles/blob/master/go.sh)
    [Stuff and things.](/kevinelliott/.dotfiles/commit/1691986eb0b25e58f304952b52686fcfb518f710)
    May 20, 2015
    
    ![](https://assets-cdn.github.com/images/spinners/octocat-spinner-32.gif)
    [heroku.sh](/kevinelliott/.dotfiles/blob/master/heroku.sh)
    [* Add node.js environment configuration](/kevinelliott/.dotfiles/commit/f366a165834ed0362ee9de57dda82d5ccf699c78)
    Jul 13, 2012
    
    ![](https://assets-cdn.github.com/images/spinners/octocat-spinner-32.gif)
    [install.sh](/kevinelliott/.dotfiles/blob/master/install.sh)
    [Add .gemrc file.](/kevinelliott/.dotfiles/commit/e72b9dbc4063516c08a7b4b542c53fac53da3481)
    Oct 28, 2014
    
    ![](https://assets-cdn.github.com/images/spinners/octocat-spinner-32.gif)
    [node.sh](/kevinelliott/.dotfiles/blob/master/node.sh)
    [* Add node.js environment configuration](/kevinelliott/.dotfiles/commit/f366a165834ed0362ee9de57dda82d5ccf699c78)
    Jul 13, 2012
    
    ![](https://assets-cdn.github.com/images/spinners/octocat-spinner-32.gif)
    [rails.sh](/kevinelliott/.dotfiles/blob/master/rails.sh)
    [Stuff and things.](/kevinelliott/.dotfiles/commit/1691986eb0b25e58f304952b52686fcfb518f710)
    May 20, 2015
    
    ![](https://assets-cdn.github.com/images/spinners/octocat-spinner-32.gif)
    [ruby.sh](/kevinelliott/.dotfiles/blob/master/ruby.sh)
    [Comment out unnecessary RVM ruby version override. This now occurs pr…](/kevinelliott/.dotfiles/commit/6034c28f6c04d12129187c4e008af2c792cfd6cc)
    Oct 28, 2014
    
    ![](https://assets-cdn.github.com/images/spinners/octocat-spinner-32.gif)
    [xquartz.sh](/kevinelliott/.dotfiles/blob/master/xquartz.sh)
    [I guess output is not really necessary here](/kevinelliott/.dotfiles/commit/cfecaff9f0a4af157e29712923ebd788768b7fdb)
    Jul 14, 2012
    
    ###  README.md 
    
    # .dotfiles
    
    Dotfiles for your unix-like system. I've created this little repository to setup my OSX development machine. You're free to clone this for your own use, or pull out items. Definitely fork this and make your own repository, and submit pull requests if you've made something cleaner or more useful. I love seeing what other people do to optimize their shells, and I'm constantly looking for general productivity improvements.
    
    # Install
    
    To install, you will be cloning this repository into ~/.dotfiles.
        
        cd ~
        git clone git@github.com:kevinelliott/.dotfiles.git
        
    
    Then you will activate the .dotfiles by including the following line to ~/.bash_profile
        
        source ~/.dotfiles/base.sh
        
    
    # Credits
    
    Thanks to @drnic for his own .dotfiles repository for inspiration and the idea for how to set this up. Look at his repositories if you'd like to see some other examples for how to do this.
    
    # Copyright
    
    Copyright © 2011 Kevin Elliott
    
    Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
    
    The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
    
    THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    
      * [Status](https://status.github.com/)
      * [API](https://developer.github.com)
      * [Training](https://training.github.com)
      * [Shop](https://shop.github.com)
      * [Blog](https://github.com/blog)
      * [About](https://github.com/about)
      * [Pricing](https://github.com/pricing)
    [ ](https://github.com)
    
      * (C) 2015 GitHub, Inc.
      * [Terms](https://github.com/site/terms)
      * [Privacy](https://github.com/site/privacy)
      * [Security](https://github.com/security)
      * [Contact](https://github.com/contact)
      * [Help](https://help.github.com)
    
    Something went wrong with that request. Please try again. 
    
    You signed in with another tab or window. [Reload]() to refresh your session. You signed out in another tab or window. [Reload]() to refresh your session.
    

    public by juntalis  1601  9  5  0

    Common-use functions for batch

    A collection of utility functions for use in Windows batch scripts. Functions near the bottom may or may not cleanly work in all situations. Still need to work the kinks out of them.
    @echo off
    
    :dirname
    rem Given a filepath, resolve the absolute filepath of its parents folder.
    rem \param [out] %1 - The variable name to output the results to.
    rem \param [in]  %2 - The filepath that we'll be operating on.
    call set "%~1=%%~dp2"
    call set "%~1=%%%~1:~0,-1%%"
    goto :EOF
    
    :filename
    rem Given a filepath, extract the filename. (name and file extension)
    rem \param [out] %1 - The variable name to output the results to.
    rem \param [in]  %2 - The filepath that we'll be operating on.
    call set "%~1=%~nx2"
    goto :EOF
    
    :basename
    rem Given a filepath, extract the basename. (name without file extension)
    rem \param [out] %1 - The variable name to output the results to.
    rem \param [in]  %2 - The filepath that we'll be operating on.
    call set "%~1=%~n2"
    goto :EOF
    
    :abspath
    rem Resolve the absolute filepath to a file or folder.
    rem \param [out] %1 - The variable name to output the results to.
    rem \param [in]  %2 - The filepath that we'll be operating on.
    call set "%~1=%~f2"
    goto :EOF
    
    :which
    rem Get the path of the program in arg 2 and set the variable who's
    rem name was specified in the first argument.
    rem \param [out] %1 - The variable name to output the executable path to.
    rem \param [in]  %2 - The executable name to search for.
    call set "%~1=%~f$PATH:2"
    goto :EOF
    
    :trimslashes
    rem Trims all trailing '/' and '\')from a variable.
    rem \param [inout] %1 - The name of the variable we'll be operating on.
    call set "__C=%%%~1:~-1%%"
    if not "%__C%x"=="\x" if not "%__C%x"=="/x" (set "__C=" & goto :EOF)
    call set "%~1=%%%~1:~0,-1%%"
    goto trimslashes
    
    :strlen
    rem Determine the length of the string specified in the second argument.
    rem \param [out] %1 - The variable name to output the results to.
    rem \param [in]  %2 - The subject text that we will be measuring.
    setlocal
    set _STRLEN_BUFFER_=%~2
    set /A _STRLEN_LENGTH_=0
    :strlen_loop
    if "%_STRLEN_BUFFER_%x"=="x" goto strlen_continue
    set _STRLEN_CHAR_=%_STRLEN_BUFFER_:~0,1%
    set /A _STRLEN_LENGTH_ += 1
    set _STRLEN_BUFFER_=%_STRLEN_BUFFER_:~1%
    goto strlen_loop
    :strlen_continue
    endlocal & call set %~1=%_STRLEN_LENGTH_%
    goto :EOF
    
    :rreplace
    rem Replaces recursively.
    rem \param [out] %1 - The variable name to output the results to.
    rem \param [in]  %2 - The subject text to search and replace through.
    rem \param [in]  %3 - The substring to search for in %2.
    rem \param [in]  %4 - The replacement text to substitute when %3 is found.
    call set "%~1=%~2"
    verify>nul
    :rreplace_work
    (call echo %%%~1%%|find "%~3")>nul 2>nul
    if errorlevel 1 goto rreplace_done
    verify>nul
    call set "%~1=%%%~1:%~3=%~4%%"
    goto rreplace_work
    :rreplace_done
    verify>nul
    goto :EOF
    
    :tolower
    rem Subroutine to convert a variable VALUE to all lower case.
    rem The argument for this subroutine is the variable NAME.
    for %%C in ("A=a" "B=b" "C=c" "D=d" "E=e" "F=f" "G=g" "H=h" "I=i" "J=j" "K=k" "L=l" "M=m" "N=n" "O=o" "P=p" "Q=q" "R=r" "S=s" "T=t" "U=u" "V=v" "W=w" "X=x" "Y=y" "Z=z") do @call set "%~1=%%%~1:%%~C%%"
    goto :EOF
    
    :isdefined
    rem Checks if a variable has a defined value.
    if "%~1x"=="x" exit /B 1
    if not defined %~1 exit /B 1
    goto :EOF
    
    :splitenv
    rem Given an expandable environment variable such as PATH or PATHEXT,
    rem split the variable into its individual lowercase components such that the
    rem value of:
    rem   .COM;.BAT;.EXE
    rem would expand into:
    rem   ".COM" ".BAT" ".EXE"
    rem The resulting value should be suitable for using with the FOR command.
    call set %~1=%%%~2:;=" "%%
    call set %~1="%%%~1%%"
    call :tolower "%~1"
    goto :EOF
    
    :whichex
    rem Similar to the original which above, but with additional functionality
    rem to use the PATHEXT variable when the executable is specified without a
    rem file extension. (ex: Specifying cmd.exe as cmd)
    rem \param [out] %1 - The variable name to output the executable path to.
    rem \param [in]  %2 - The executable name to search for.
    setlocal
    set _WHICHEX_TARGET_=%~2
    call :which _WHICHEX_RESULT_ "%_WHICHEX_TARGET_%"
    if exist "%_WHICHEX_RESULT_%" goto whichex_success
    if not "%~x2x"=="x" goto whichex_failure
    goto whichex_pathext
    :whichex_testpath
    rem Given a file basename and extension, see if we can find a matching
    rem executable on the system PATH.
    if errorlevel 1 exit /B %ERRORLEVEL%
    call :which _WHICHEX_RESULT_ "%~1%~2"
    if exist "%_WHICHEX_RESULT_%" exit /B 1
    goto :EOF
    :whichex_pathext
    rem No file extension was found on our executable name. First we'll try
    rem a search with no extension, (as it was specified) and if that fails,
    rem we'll try the search again with each file extension in PATHEXT until
    rem we find a match. (or run out of extensions)
    call :splitenv _WHICHEX_PATHEXT_ PATHEXT
    for %%E in (%_WHICHEX_PATHEXT_%) do @call :whichex_testpath "%~nx2" "%%~E"
    rem When an executable is found, the errorcode is set to 1 to indicate success.
    if errorlevel 1 goto whichex_success
    rem If it's still zero at this point, that means we failed to find our executable.
    goto whichex_failure
    :whichex_success
    rem We maanged to resolve the executable path, which is now stored in a
    rem localized variable named _WHICHEX_RESULT_. Copy that value over to
    rem our outgoing parameter and cleanup.
    verify>nul
    call set _WHICHEX_COPYCMD_=set "%~1=%_WHICHEX_RESULT_%"
    endlocal & call %_WHICHEX_COPYCMD_%
    goto :EOF
    :whichex_failure
    rem We failed to find the executable path based on the info given. Clean
    rem up and report the error.
    set _WHICHEX_RESULT_=
    endlocal
    call set %~1=%_WHICHEX_RESULT_%
    exit /B 1
    
    
                            
    • Public Snippets
    • Channels Snippets