Never been to DZone Snippets before?

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

« Newer Snippets
Older Snippets »
Showing 11-20 of 25 total

Get the name of the script that is running

   1  
   2  script-name: does [system/options/script]

rails related svn configurator

   1  
   2  #!/bin/sh
   3  svn remove log/*
   4  svn commit -m"removing log files" 
   5  svn propset svn:ignore "*.log" log/
   6  svn update log/
   7  svn commit -m 'Ignoring all files in /log/ ending in .log'
   8  svn move config/database.yml config/database.example
   9  svn commit -m 'Moving database.yml to database.example to provide a template for anyone who checks out the code'
  10  svn propset svn:ignore "database.yml" config/
  11  svn update config/
  12  svn commit -m 'Ignoring database.yml'
  13  svn remove tmp/*
  14  svn propset svn:ignore "*" tmp/
  15  svn update tmp/
  16  svn commit -m "ignore tmp/ content from now" 
  17  svn propset svn:ignore ".htaccess" config/
  18  svn update config/
  19  svn commit -m 'Ignoring .htaccess'
  20  svn propset svn:ignore "dispatch.fcgi" config/
  21  svn update config/
  22  svn commit -m 'Ignoring dispatch.fcgi'

Start rails dev env

Here's the script I use to start up my Rails editing environment. It assumes you are in the RAILS_ROOT folder, and you have textmate and mongrel.

   1  
   2  #!/bin/sh
   3  killall ruby
   4  mongrel_rails start -d
   5  sleep 1
   6  open http://localhost:3000/
   7  sleep 1
   8  mate .

Linux - command ls without color

// Elimina tutti i caratteri speciali che portano il colore

   1  
   2  ls --color=never

CSS Drop Shadows

This handy technique allows us to build flexible CSS drop shadows that we can apply to any arbitraryblock elements. The beauty of this method is that most exisitng techniques use images to create the shadow effect. This script is lightweight and uses pure CSS! ENJOY!
www.webscriptexpert.com

<HTML PAGE HERE>
   1  
   2  
   3  
   4  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
   5  <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
   6  <head>
   7  <title>CSS Drop Shadow DEMO</title>
   8  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
   9  <link media="screen" type="text/css" rel="stylesheet" href="dropshadow.css" />
  10  
  11  <style>
  12  body {
  13  margin: 0px;
  14  padding: 20px;
  15  font-family: verdana;
  16  font-size: 12px;
  17  min-width: 770px;
  18  }
  19  </style>
  20  
  21  </head>
  22  
  23  <body>
  24  
  25  <div id="shadow-container">
  26  <div class="shadow1">
  27  
  28  <div class="shadow2">
  29  <div class="shadow3">
  30  <div class="container">
  31  <p>This is a sample of how we implement the CSS style to create flexible CSS drop shadows that can be applied to block elements.</p>
  32  <p>The beauty of this script is that is doesnt use any images to create the final effect, just pure CSS!</p>
  33  </div>
  34  </div>
  35  </div>
  36  </div>
  37  </div>
  38  
  39  <br />
  40  <br />
  41  
  42  <table cellspacing=0 cellpadding=0 border=0 width="100%"><tr valign="top">
  43  <td width="22%" height="218">
  44  <div id="shadow-container">
  45  <div class="shadow1">
  46  <div class="shadow2">
  47  <div class="shadow3">
  48  <div class="container">
  49  The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog. </div>
  50  
  51  </div>
  52  </div>
  53  </div>
  54  </div>
  55  </td>
  56  <td width="21%"></td>
  57  <td width="57%">
  58  <div id="shadow-container">
  59  <div class="shadow1">
  60  <div class="shadow2">
  61  
  62  <div class="shadow3">
  63  <div class="container">The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog. </div>
  64  </div>
  65  </div>
  66  </div>
  67  </div>
  68  </td>
  69  </tr></table>
  70  
  71  </body>
  72  </html>
  73  



<.CSS FILE HERE>
   1  
   2  
   3  /* CSS container shadow */
   4  #shadow-container {
   5  position: relative;
   6  left: 3px;
   7  top: 3px;
   8  margin-right: 3px;
   9  margin-bottom: 3px;
  10  }
  11  
  12  #shadow-container .shadow2,
  13  #shadow-container .shadow3,
  14  #shadow-container .container {
  15  position: relative;
  16  left: -1px;
  17  top: -1px;
  18  }
  19  
  20  #shadow-container .shadow1 {
  21  background: #F1F0F1;
  22  }
  23  
  24  #shadow-container .shadow2 {
  25  background: #DBDADB;
  26  }
  27  
  28  #shadow-container .shadow3 {
  29  background: #B8B6B8;
  30  }
  31  
  32  #shadow-container .container {
  33  background: #ffffff;
  34  border: 1px solid #848284;
  35  padding: 10px;
  36  }
  37  /* CSS container shadow */
  38  

Making SQLITE/SQLITE3 executable scripts.

Use "here document" statements to build complex script files with embedded SQL statements via the sqlite/sqlite3 utility.

   1  
   2  #! /usr/bin/env bash
   3  
   4  # execute some bash scripting commands here
   5  
   6  sqlite3 mydatabase <<SQL_ENTRY_TAG_1
   7  SELECT * 
   8    FROM mytable 
   9    WHERE somecondition='somevalue';
  10  SQL_ENTRY_TAG_1
  11  
  12  # execute other bash scripting commands here
  13  
  14  sqlite3 mydatabase <<SQL_ENTRY_TAG_2
  15  SELECT *
  16    FROM myothertable
  17    WHERE someothercondition='someothervalue';
  18  SQL_ENTRY_TAG_2


Note that being in a bash script means that you can expand $-variables inside the SQL code directly. This is, however, not advised unless you can be sure that only trusted, competent people will run your code. Otherwise you'll be facing SQL injection attacks.

Making MySQL executable scripts.

Use "here document" statements to build complex script files with embedded SQL statements via the mysql utility.

   1  
   2  #! /usr/bin/env bash
   3  
   4  # execute some bash scripting commands here
   5  
   6  mysql mydatabase <<SQL_ENTRY_TAG_1
   7  SELECT * 
   8    FROM mytable 
   9    WHERE somecondition='somevalue';
  10  SQL_ENTRY_TAG_1
  11  
  12  # execute other bash scripting commands here
  13  
  14  mysql mydatabase <<SQL_ENTRY_TAG_2
  15  SELECT *
  16    FROM myothertable
  17    WHERE someothercondition='someothervalue';
  18  SQL_ENTRY_TAG_2


Note that being in a bash script means that you can expand $-variables inside the SQL code directly. This is, however, not advised unless you can be sure that only trusted, competent people will run your code. Otherwise you'll be facing SQL injection attacks.

Get HTML/XML output of your MySQL queries.

The mysql command line utility can be used to build databases, manipulate them, etc. It can also be used as an ad-hoc query tool with HTML-snippet output. Consider this code:

   1  
   2  mysql -e "SELECT * FROM mytable WHERE somecondition='somevalue'"


The resulting output will be a mess of +, - and | characters used to frame boxes around the values. Now consider instead:

   1  
   2  mysql -H -e "SELECT * FROM mytable WHERE somecondition='somevalue'"


The output of this is <TABLE/><TR/><TD/> code that can be cut-and-pasted into your HTML editor of choice. Complex queries not easily put into a single -e string can be done thus:

   1  
   2  mysql -H < myqueries.sql


Note that no HTML is generated for any query that does not have a result set (like INSERT or UPDATE).

Change the -H to a -X to get XML output (without a DTD/XSL description, unfortunately).

Bash - Creare una galleria di mini immagini

// Prende le immagini di una cartella e ne crea delle copie
// della dimensione di 320x240

   1  
   2  #!/bin/sh
   3  
   4  for i in `ls *.jpg`;
   5  do
   6  	convert -geometry 320x240 $i galleria-$i
   7  done

Javascript - Rollover con preview immagine

// loader.js
   1  
   2  var t_id = setInterval(animate,20);
   3  var pos=0;
   4  var dir=2;
   5  var len=0;
   6  
   7  function animate()
   8  {
   9  var elem = document.getElementById('progress');
  10  if(elem != null) {
  11  if (pos==0) len += dir;
  12  if (len>32 || pos>79) pos += dir;
  13  if (pos>79) len -= dir;
  14  if (pos>79 && len==0) pos=0;
  15  elem.style.left = pos;
  16  elem.style.width = len;
  17  }
  18  }
  19  
  20  function remove_loading() {
  21  this.clearInterval(t_id);
  22  var targelem = document.getElementById('loader_container');
  23  targelem.style.display='none';
  24  targelem.style.visibility='hidden';
  25  var t_id = setInterval(animate,60);
  26  }


// preview_templates.js
   1  
   2  var offsetfrommouse=[15,25]; //image x,y offsets from cursor position in pixels. Enter 0,0 for no offset
   3  var displayduration=0; //duration in seconds image should remain visible. 0 for always.
   4  
   5  var defaultimageheight = 40;	// maximum image size.
   6  var defaultimagewidth = 40;	// maximum image size.
   7  
   8  var timer;
   9  
  10  function gettrailobj(){
  11  if (document.getElementById)
  12  return document.getElementById("preview_div").style
  13  }
  14  
  15  function gettrailobjnostyle(){
  16  if (document.getElementById)
  17  return document.getElementById("preview_div")
  18  }
  19  
  20  
  21  function truebody(){
  22  return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
  23  }
  24  
  25  
  26  function hidetrail(){	
  27  	gettrailobj().display= "none";
  28  	document.onmousemove=""
  29  	gettrailobj().left="-500px"
  30  	clearTimeout(timer);
  31  }
  32  
  33  function showtrail(imagename,title,width,height){
  34  	i = imagename
  35  	t = title
  36  	w = width
  37  	h = height
  38  	timer = setTimeout("show('"+i+"',t,w,h);",200);
  39  }
  40  function show(imagename,title,width,height){
  41   
  42      var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth - offsetfrommouse[0]
  43  	var docheight=document.all? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(window.innerHeight)
  44  
  45  	if( (navigator.userAgent.indexOf("Konqueror")==-1  || navigator.userAgent.indexOf("Firefox")!=-1 || (navigator.userAgent.indexOf("Opera")==-1 && navigator.appVersion.indexOf("MSIE")!=-1)) && (docwidth>650 && docheight>500)) {
  46  		( width == 0 ) ? width = defaultimagewidth: '';
  47  		( height == 0 ) ? height = defaultimageheight: '';
  48  			
  49  		width+=30
  50  		height+=55
  51  		defaultimageheight = height
  52  		defaultimagewidth = width
  53  	
  54  		document.onmousemove=followmouse; 
  55  
  56  		
  57  		newHTML = '<div class="border_preview" style="width:'+  width +'px;height:'+ height +'px"><div id="loader_container"><div id="loader"><div align="center">Loading template preview...</div><div id="loader_bg"><div id="progress"> </div></div></div></div>';
  58  		newHTML = newHTML + '<h2 class="title_h2">' + ' '+title + '</h2>'
  59  		
  60      	newHTML = newHTML + '<div class="preview_temp_load"><img onload="javascript:remove_loading();" src="' + imagename + '" border="0"></div>';
  61  		newHTML = newHTML + '</div>'; 
  62  		
  63  		if(navigator.userAgent.indexOf("MSIE")!=-1 && navigator.userAgent.indexOf("Opera")==-1 ){
  64  			newHTML = newHTML+'<iframe src="about:blank" scrolling="no" frameborder="0" width="'+width+'" height="'+height+'"></iframe>';
  65  		}		
  66  
  67  		gettrailobjnostyle().innerHTML = newHTML;
  68  		gettrailobj().display="block";
  69  	}
  70  }
  71  
  72  function followmouse(e){
  73  
  74  	var xcoord=offsetfrommouse[0]
  75  	var ycoord=offsetfrommouse[1]
  76  
  77  	var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth-15
  78  	var docheight=document.all? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(window.innerHeight)
  79  
  80  	if (typeof e != "undefined"){
  81  		if (docwidth - e.pageX < defaultimagewidth + 2*offsetfrommouse[0]){
  82  			xcoord = e.pageX - xcoord - defaultimagewidth; // Move to the left side of the cursor
  83  		} else {
  84  			xcoord += e.pageX;
  85  		}
  86  		if (docheight - e.pageY < defaultimageheight + 2*offsetfrommouse[1]){
  87  			ycoord += e.pageY - Math.max(0,(2*offsetfrommouse[1] + defaultimageheight + e.pageY - docheight - truebody().scrollTop));
  88  		} else {
  89  			ycoord += e.pageY;
  90  		}
  91  
  92  	} else if (typeof window.event != "undefined"){
  93  		if (docwidth - event.clientX < defaultimagewidth + 2*offsetfrommouse[0]){
  94  			xcoord = event.clientX + truebody().scrollLeft - xcoord - defaultimagewidth; // Move to the left side of the cursor
  95  		} else {
  96  			xcoord += truebody().scrollLeft+event.clientX
  97  		}
  98  		if (docheight - event.clientY < (defaultimageheight + 2*offsetfrommouse[1])){
  99  			ycoord += event.clientY + truebody().scrollTop - Math.max(0,(2*offsetfrommouse[1] + defaultimageheight + event.clientY - docheight));
 100  		} else {
 101  			ycoord += truebody().scrollTop + event.clientY;
 102  		}
 103  	}
 104  	gettrailobj().left=xcoord+"px"
 105  	gettrailobj().top=ycoord+"px"
 106  
 107  }


   1  
   2  <html>
   3  	<head>
   4  		<script src="preview_templates.js" language="JavaScript" type="text/javascript"></script>
   5  		<script src="loader.js" language="JavaScript" type="text/javascript"></script>
   6  	</head>
   7  
   8  	<body>
   9  		<img src="uno.jpg" border=0  border=1 style="border-color: 777777" onmouseover="showtrail('due.jpg ','Template 12306',430,449);"   onmouseout="hidetrail();">
  10  		<div style="display: none; position: absolute;z-index:110; " id="preview_div"></div>
  11  	</body>
  12  </html>
« Newer Snippets
Older Snippets »
Showing 11-20 of 25 total