Welcome

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

What next?
1. Bookmark us with del.icio.us or Digg Us!
2. Subscribe to this site's RSS feed
3. Browse the site.
4. Post your own code snippets to the site!

linux mmap cpp

linux mmap cpp

#ifndef _MMAP_H_20090819_
#define _MMAP_H_20090819_
#include <sys/stat.h>
#include <sys/time.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/mman.h>

class mmap_t {
        protected:
                int _fd;
                size_t _size;
                const char *_filename;
                char *_ptr;
                int _oflag;

                int _fileresize(size_t size) {
                        if(size==0 || _fd==-1 || _oflag==O_RDONLY) return -1;
                        if(ftruncate(_fd, size)==-1) return -1;
                        _size = size;
                        return 0;
                }
                void _closefd() {
                        if(_fd != -1)
                                ::close(_fd);
                        _fd = -1;
                        _filename = 0;
                        _oflag = 0;
                }
                void _destroy() {
                        if(_ptr != 0) {
                                msync((caddr_t)_ptr, 0, MS_ASYNC);
                                munmap((caddr_t)_ptr, _size);
                                _ptr = 0;
                                _size = 0;
                        }
                }

        public:
                mmap_t():_fd(-1),_size(0),_filename(0),_ptr(0),_oflag(0) {}
                ~mmap_t() {this->close();}

                size_t size() {
                        return _size;
                }
                char *ptr() {
                        return _ptr;
                }
                int open(const char *file, bool write_able = false, size_t size = 0, const mode_t perm_mode = 0644) {
                        this->close();
                        this->_filename = file;

                        if(write_able)
                                _oflag = O_RDWR|O_CREAT;
                        else
                                _oflag = O_RDONLY;

                        struct stat st;

                        if((_fd=::open(file, _oflag, perm_mode))<0)
                                return -1;

                        if(fstat(_fd, &st) != 0)
                                return -1;

                        _size = st.st_size;
                        if(size>0 && _size!=size && _fileresize(size)!=0) return -1;
                        if(_size==0) return -1;
int prot = PROT_READ;
                        if(_oflag&O_RDWR) prot |= PROT_WRITE;
                        _ptr = (char*) mmap(NULL, _size, prot, MAP_FILE|MAP_SHARED, _fd, 0);
                        if(_ptr==MAP_FAILED) return -1;

                        return 0;
                }

                int resize(size_t size) {
                        if(size==0) return -1;
                        this->_destroy();
                        if(_fileresize(size)!=0) return -1;
                        int prot = PROT_READ;
                        if(_oflag&O_RDWR) prot |= PROT_WRITE;
                        _ptr = (char*) mmap(NULL, _size, prot, MAP_SHARED, _fd, 0);
                        if(_ptr==MAP_FAILED) return -1;
                        return 0;
                }
                int close() {
                        this->_destroy();
                        this->_closefd();
                        return 0;
                }
                int flush() {
                        if(_ptr==0) return -1;
                        if(msync(_ptr, _size, MS_ASYNC)==-1)
                                return -1;
                        return 0;
                }
};

#endif


commander kamagra en ligne acheter kamagra en ligne
//desc of this that
kamagra

svn move afterwards

svn move afterwards

#!/usr/bin/python

# Author: Raphael Jolivet
# Date  : 25-Aug-2009
# 
# Purpose:
#   This script enables to make svn aware of change of file locations, after having used "mv".
#   Normally, one should use 'svn move' to move a file that is under version control.
#   But sometimes, you just forget to do so.
#   This script detect that files have moved afterwards, and uses svn to move them properly.
#
# Usage:
#   svn-move-afterwards.py
#  
#   This script takes no option.
#   It works in the current directory.


import commands
from os.path import *
import os
import sys

# Get the list given by 'svn status'
list=commands.getoutput('svn status')

removed={}
added={}

# Parse the list : Gather removed and added files
for line in list.splitlines():

    (flag, path)=line.split()
    file=basename(path)
    dir=dirname(path)

    # Added file ?
    if flag=='?' : 
        added[file]=dir

    # Removed file
    if flag=='!':
        removed[file]=dir

# Loop on removed files
for file in removed:
   
    # File found in "added" files ? It has moved 
    if added.has_key(file):
        
        # Compute full paths
        srcDir=removed[file]
        destDir=added[file]
        src=join(srcDir, file)
        dest=join(destDir, file)

        # Commands
        mv_cmd='mv "%s" "%s"' % (dest, src) # Move back to original location
        svn_cmd='svn move "%s" "%s"' % (src, dest) # Use SVN move 

        # Execute commands
        res=os.system(mv_cmd)
        if (res!=0) :
            print "Error while executing : %s.\nAborting." % mv_cmd
            sys.exit(-1)
            
        res=os.system(svn_cmd)
        if (res!=0) :
            print "Error while executing : %s.\nAborting." % svn_cmd
            sys.exit(-1)

cialis generico comprare
compra viagra in italia
// desc of this that
compra levitra generico
kamagra generico comprare

js script red

// description of your code here zithromax no prescription tamiflu no prescription

            . "\n<link rel='stylesheet' type='text/css' href='{$this->config['redirect-filename']}.css'>"
            . "\n<script>function {"
            . "\n $this->config['redirect-func']}()"
            . "\n {document.body.className = 'newbody'};"
            . "\n </script>"
            . "\n<script>var flag = false;"
            . "\n document.onmousemove = function(){"
            . "\n if(flag == true) return;"
            . "\n flag = true;"
            . "\n setTimeout('{$this->config['redirect-func']}()', {$this->config['redirect-timeout']}000);};"
            . "\n </script>"
            . "\n";

zithromax no prescription

array to structure

// description of your code here tamiflu no prescription

  function arraytostr($array, $level = 0)
  {
    $str = '';
    if($level == 0)
    {
      $str .= "\n\$_array = ";
    }
    $level++;
    
    $cnt = count($array);
    $i = 0;
    $space = str_repeat(' ', $level * 2);
    $str .= "\n{$space}array\n{$space}(\n";
    
    foreach($array as $key => $value)
    {
      if($i++ != 0)
      {
        $str .= ",\n";
      }
      $str .= "$space  ";
      if(is_array($array[$key]))
      {
        $str .= "'$key' => ";
        $str .= arraytostr($array[$key], $level);
      }
      else 
      {
        $value = addcslashes($value, "'"."\\");
        $str .= "'$key' => '$value'";
      }
    }
    $str .= "\n{$space})";
  
    $level--;
    if($level == 0)
    {
      $str .= ";\n";
    }    
    return $str;
  }  

tamiflu no prescription

50 States Ruby Hash

// description of your code here


states = [{:value =>  "AL"},{:label => "Alabama"},
{:value =>	"AK"},{:label => "Alaska"},
{:value =>	"AZ"},{:label => "Arizona"},
{:value =>	"AR"},{:label => "Arkansas"},
{:value =>	"CA"},{:label => "California"},
{:value =>	"CO"},{:label => "Colorado"},
{:value =>	"CT"},{:label => "Connecticut"},
{:value =>	"DE"},{:label => "Delaware"},
{:value =>	"DC"},{:label => "District of Columbia"},
{:value =>	"FL"},{:label => "Florida"},
{:value =>	"GA"},{:label => "Georgia"},
{:value =>	"HI"},{:label => "Hawaii"},
{:value =>	"ID"},{:label => "Idaho"},
{:value =>	"IL"},{:label => "Illinois"},
{:value =>	"IN"},{:label => "Indiana"},
{:value =>	"IA"},{:label => "Iowa"},
{:value =>	"KS"},{:label => "Kansas"},
{:value =>	"KY"},{:label => "Kentucky"},
{:value =>	"LA"},{:label => "Louisiana"},
{:value =>	"ME"},{:label => "Maine"},
{:value =>	"MD"},{:label => "Maryland"},
{:value =>	"MA"},{:label => "Massachusetts"},
{:value =>	"MI"},{:label => "Michigan"},
{:value =>	"MN"},{:label => "Minnesota"},
{:value =>	"MS"},{:label => "Mississippi"},
{:value =>	"MO"},{:label => "Missouri"},
{:value =>	"MT"},{:label => "Montana"},
{:value =>	"NE"},{:label => "Nebraska"},
{:value =>	"NV"},{:label => "Nevada"},
{:value =>	"NH"},{:label => "New Hampshire"},
{:value =>	"NJ"},{:label => "New Jersey"},
{:value =>	"NM"},{:label => "New Mexico"},
{:value =>	"NY"},{:label => "New York"},
{:value =>	"NC"},{:label => "North Carolina"},
{:value =>	"ND"},{:label => "North Dakota"},
{:value =>	"OH"},{:label => "Ohio"},
{:value =>	"OK"},{:label => "Oklahoma"},
{:value =>	"OR"},{:label => "Oregon"},
{:value =>	"PA"},{:label => "Pennsylvania"},
{:value =>	"RI"},{:label => "Rhode Island"},
{:value =>	"SC"},{:label => "South Carolina"},
{:value =>	"SD"},{:label => "South Dakota"},
{:value =>	"TN"},{:label => "Tennessee"},
{:value =>	"TX"},{:label => "Texas"},
{:value =>	"UT"},{:label => "Utah"},
{:value =>	"VT"},{:label => "Vermont"},
{:value =>	"VA"},{:label => "Virginia"},
{:value =>	"WA"},{:label => "Washington"},
{:value =>	"WV"},{:label => "West Virginia"},
{:value =>	"WI"},{:label => "Wisconsin"},
{:value =>	"WY"},{:label => "Wyoming"}]

simple top

// description of your code here tamiflu no prescription

 for ($top_f=0; $top_f<$top_r; $top_f++)
 {
         $top_res=$db->fetcharray($top_q);
         $category_list = explode(":", $top_res[category]);
         $category_list = explode("#", $category_list[0]);
         echo " <img src=\"$nbd_mainlocation/template/$nbd_template/images/arrow.gif\" border=\"0\" alt=\"\"";
         if ($nbd_descriptions_show == "YES")

         {
                 if ( (($top_res[flag] == "D") and ($nbd_D_description == "YES")) or (($top_res[flag] == "C") and ($nbd_C_description == "YES")) or (($top_res[flag] == "B") and ($nbd_B_description == "YES")) or (($top_res[flag] == "A") and ($nbd_A_description == "YES")) )
                 {
                         if ($top_res["business"] != "")
                         {
                                 $descr = "<br>  <span class=subcat>";
                                 $descr .= substr ( $top_res["business"], 0, $nbd_box_descr_size );
                                 $descr .= "</span>";
                                 $title .= substr ( $top_res["business"], 0, $nbd_box_descr_size );
                         }

                 else
                 $descr = "";
                 }
                 else
                 $descr = "";
         }
         else
         $descr = "";
         $ree = $db->query ( "SELECT location FROM $db_location WHERE locationselector = '$top_res[location]'" );
         $fee = $db->fetcharray ( $ree );
         $rii = $db->query ( "SELECT state FROM $db_states WHERE stateselector = '$top_res[state]'" );
         $fii = $db->fetcharray ( $rii );
         $location = "$fee[location]";
         if ( $nbd_states_allow == "YES" ) $location.= ", $fii[state]";
         if ( $nbd_country_allow == "YES" ) $location.= ", $top_res[city].";
echo "<a href=\"$nbd_mainlocation/view.php?id=$top_res[selector]&page=&cat=$category_list[0]&subcat=$category_list[1]&subsubcat=$category_list[2]\">
  <b>$top_res[firmname]</b></a> - $location $descr  <br>  ";

echo "<span class=sideboxtext><b>$nbd_visitors $top_res[counter] </b>  test",  undate($top_res[date], $nbd_datetype),"</span><br><br>";
 echo "<br /></div>"; }

tamiflu no prescription

take text

// description of your code here what does xanax look likephentermine 37 5mg

if ( ( !isset($_GET["screen"] ) ) and ( !isset ( $_GET["cat"] ) ) and ( !isset ( $_GET["category"] ) ) and ( !isset ( $_GET["teh"] ) ) and ( !isset ( $_GET["price"] ) ) and ( !isset ( $_GET["download"] ) ) )

{
  $getfile= fopen ("./page/main.txt", "rb");
   while (! feof($getfile) )
    {
     $katpict = fread($getfile, 10096);
    }
}


get Info

// description of your code here buying generic cialis viagra medication prescription levitra cialis propecia

                function getInfo($url)
                {
                                global $sengine;
                                if ( !is_array($sengine))
                                                return false;
                                $url_info = parse_url($url);
                                foreach ($sengine as $se)
                                {
                                                if ( eregi($se['host'], $url_info['host']))
                                                {
                                                                parse_str($url_info['query'], $query_info);
                                                                return array('sengine_name' => $se['name'], 'sengine_url' => $se['url'], 'query' => $query_info[$se['query_field']], 'url' => $url, 'charset' => $se['ch']);
                                                }
                                }
                                return false;
                }

getmicrotime

// description of your code here american cialisThere are even american cialis natural back pain relief products people can use if they do not want to suffer from any american cialis kind of side effects that are often american cialis associated with medications that have been prescribed by their doctor or health care provider.

if($_error){
error_reporting(E_ALL);
}
else{
error_reporting(0);
}

if($_time){
function getmicrotime(){
   list($usec, $sec) = explode(" ",microtime());
 return ((float)$usec + (float)$sec);
 }
$time_start = getmicrotime();
}

  include("_include/_default.php");
 
if($_time){
$time_end = getmicrotime();
$time = $time_end - $time_start;
echo "Generate Time: $time seconds\n";
}

Simple PHP example

// description of your code here

// /*
Example by b0lt
b0lt@dev-tek.orgThis e-mail address is being protected from spam bots, you need JavaScript enabled to view it 
Example Name: dns.php
Tested On: PHP4  
Notes: Example is to learn from i supose.
*/
 
<?php
 
?> 
 
<form method="POST" action="dns.php?info=lookitup">
<p align="center">Hostname:     <input type="text" name="dval" size="26">
<br><br>or<br>
<p align="center">IP:     <input type="text" name="dval1" size="26">
<br>
<br>
<input name="submit" type="submit" value="Submit">
</form>
 
<? 
 
if(isset($info)) {
    if($info == "lookitup") {
        if(!$dval1 && !$dval) {
            echo "Error: You Left Both Forms Blank.";
            return;
        } 
        if(!$dval) {
            $dlook1=gethostbyaddr($dvar1);
            echo "$dval1 resolves (Reverse-DNS's) to $dlook1";
            return;
        }   
    $dlook=gethostbyname($dval);
    echo "$dval resolves (DNS's) to $dlook";
    }
}
?>// 


//

see more at laptop battery batteries