DZone 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

Snippets

  • submit to reddit

Recent Snippets

                    @RequestMapping(value = "/logout", method = RequestMethod.POST)
	public void logout(HttpServletRequest request,
			HttpServletResponse response) {
		/* Getting session and then invalidating it */
		HttpSession session = request.getSession(false);
		if (request.isRequestedSessionIdValid() && session != null) {
			session.invalidate();
		}
		handleLogOutResponse(response);
	}

/**
	 * This method would edit the cookie information and make JSESSIONID empty
	 * while responding to logout. This would further help in order to. This would help
	 * to avoid same cookie ID each time a person logs in
	 * @param response
	 */
	private void handleLogOutResponse(HttpServletResponse response) {
		Cookie[] cookies = request.getCookies();
		for (Cookie cookie : cookies) {
			cookie.setMaxAge(0);
			cookie.setValue(null);
			cookie.setPath("/");
			response.addCookie(cookie);
		}
	}                
                    -- 1st way
SELECT *
FROM TABLE
WHERE FIND_IN_SET(" '.$tag.'", CONCAT(" ", TABLE.tags))
LIMIT 1;
 
-- 2st way 
SELECT *
FROM TABLE
WHERE '.$tag.' IN(TABLE.tags)
LIMIT 1;

-- source: http://www.apphp.com/index.php?snippet=mysql-search-in-tags-set                
                    <!-- This part goes into your body tag -->
<body OnLoad="document.myform.user.focus();">
 
<!-- You you just use the name of the form and field name within your form -->
<form name="myform">
Name:  <input type="text" name="user" size="10">
Email:  <input type="text" name="email" size="10">
</form>
 
</body>                
                    function getLocationInfoByIp(){
    $client  = @$_SERVER['HTTP_CLIENT_IP'];
    $forward = @$_SERVER['HTTP_X_FORWARDED_FOR'];
    $remote  = @$_SERVER['REMOTE_ADDR'];
    $result  = array('country'=>'', 'city'=>'');
    if(filter_var($client, FILTER_VALIDATE_IP)){
        $ip = $client;
    }elseif(filter_var($forward, FILTER_VALIDATE_IP)){
        $ip = $forward;
    }else{
        $ip = $remote;
    }
    $ip_data = @json_decode(file_get_contents("http://www.geoplugin.net/json.gp?ip=".$ip));    
    if($ip_data && $ip_data->geoplugin_countryName != null){
        $result['country'] = $ip_data->geoplugin_countryCode;
        $result['city'] = $ip_data->geoplugin_city;
    }
    return $result;
}                
                    //[C#]

// Load the Outlook template (OFT) file in MailMessage's instance
MailMessage message = MailMessage.Load("invitation to meeting.oft", MessageFormat.Msg);

// Set the sender and recipients information
string senderDisplayName = "John";
string senderEmailAddress = "john@abc.com";
string recipientDisplayName = "William";
string recipientEmailAddress = "william@xzy.com";

message.Sender = new MailAddress(senderEmailAddress, senderDisplayName);
message.To.Add(new MailAddress(recipientEmailAddress, recipientDisplayName));
message.HtmlBody = message.HtmlBody.Replace("DisplayName", "<b>" + recipientDisplayName + "</b>");

// Set the name, location and time in email body
string meetingLocation = "<u>" + "Hall 1, Convention Center, New York, USA" + "</u>";
string meetingTime = "<u>" + "Monday, June 28, 2010" + "</u>";
message.HtmlBody = message.HtmlBody.Replace("MeetingPlace", meetingLocation);
message.HtmlBody = message.HtmlBody.Replace("MeetingTime", meetingTime);

// Send the email or save as MSG and open in Outlook for further editing
SmtpClient client = new SmtpClient("host", 25, "username", "password");
client.Send(message);

// Save the message in MSG format and open in Office Outlook
MapiMessage msg = MapiMessage.FromMailMessage(message);
msg.SetMessageFlags(MapiMessageFlags.MSGFLAG_UNSENT);
msg.Save("Invitation.msg");
Process.Start("Invitation.msg");
 
//[VB.NET]

' Load the Outlook template (OFT) file in MailMessage's instance
Dim message As MailMessage = MailMessage.Load("invitation to meeting.oft", MessageFormat.Msg)

' Set the sender and recipients information
Dim senderDisplayName As String = "John"
Dim senderEmailAddress As String = "john@abc.com"
Dim recipientDisplayName As String = "William"
Dim recipientEmailAddress As String = "william@xzy.com"

message.Sender = New MailAddress(senderEmailAddress, senderDisplayName)
message.To.Add(New MailAddress(recipientEmailAddress, recipientDisplayName))
message.HtmlBody = message.HtmlBody.Replace("DisplayName", "<b>" & recipientDisplayName & "</b>")

' Set the name, location and time in email body
Dim meetingLocation As String = "<u>" & "Hall 1, Convention Center, New York, USA" & "</u>"
Dim meetingTime As String = "<u>" & "Monday, June 28, 2010" & "</u>"
message.HtmlBody = message.HtmlBody.Replace("MeetingPlace", meetingLocation)
message.HtmlBody = message.HtmlBody.Replace("MeetingTime", meetingTime)

' Send the email or save as MSG and open in Outlook for further editing
Dim client As SmtpClient = New SmtpClient("host", 25, "username", "password")
client.Send(message)

' Save the message in MSG format and open in Office Outlook
Dim msg As MapiMessage = MapiMessage.FromMailMessage(message)
msg.SetMessageFlags(MapiMessageFlags.MSGFLAG_UNSENT)
msg.Save("Invitation.msg")
Process.Start("Invitation.msg")
 
                
                    

<?php

function replace_relative_urls($html) {

$replace='$1http://mywebsite.com/$2$3';
$pattern="#(<\s*?a\s*?[^>]*href\s*?=[\"'])(?!http)([^\"'>]+)([\"'>]+)#";
$html=preg_replace($pattern,$replace, $html);
return $html;

}                
                    function function1(){  // Function #1
 alert('Hello');
}

function function2(){  // Function #1
 alert('World');
}

var queue= [];                     // <- This is a Vector in this case a queue representation.
 queue.push(function1);      // <- storage a function #1 in a queue vector.
 queue.push(function2);      // <- storage a function #2 in a queue vector.
   while (cola.length > 0) {   // <- iterate a queue vector and execute the functions.
      (queue.shift())();            // <- Excecute the process. 
    }                
                    Spire.BarCode for .NET is a FREE and professional barcode component specially designed for .NET developers (C#, VB.NET, ASP.NET) to generate, read 1D & 2D barcodes. Developers and programmers can use Spire.BarCode to add Enterprise-Level barcode formats to their .net applications (ASP.NET, WinForms and Web Service) quickly and easily.

Spire.BarCode for .NET provides a very easy way to integrate barcode processing. With just one line of code to create, read 1D & 2D barcode, Spire.BarCode supports variable common image formats, such as Bitmap, JPG, PNG, EMF, TIFF, GIF and WMF.

Spire.BarCode for .NET is 100% FREE BarCode component, no risk to integrate in your .NET application.                
                        <div id="graph"></div>

    <script type="text/javascript" charset="utf-8">
    window.onload = function () {

        /**
         * set graph data
         */
        var data = ({series1data : new Array('6097','5970','3230','7236','3236','4723','546','6236','3236','5246','4928','1296'),
                     series2data : new Array('500','1200','1800','1235','4231','5738','8236','4230','2432','1236','4237','7234'),
                     series3data : new Array('1200','7000','1560','6230','2230','3720','4230','1652','4378','1462','2654','5321')
                    });

        /**
         * draw the graph
         */
        var graph = new JpGraph(
                'line',
                'graph',
                data,
                {
                  width                 : 800,
                  height                : 500,
                  backgroundColor       : '#f9f5da',
                  series1               : "title: Standard Widgets; color:#ea7532; scale:left",
                  series2               : "title: Special Widgets; color:#00a550; scale:left",
                  series3               : "title: Custom Widgets; color:#367adf; scale:left",
                  target1               : "value: 3750.00; color: #948; text:Break even; linewidth: 3; scale:left; fontSize:12; fontFamily: Helvetica, Arial, sans-serif;fontWeight: normal;",
                  target2               : "value: 7700.00; color: #161; text:Sales target; linewidth: 3; scale:left; fontSize:12; fontFamily: Helvetica, Arial, sans-serif;fontWeight: normal;",
                  xLabels               : 'January|February|March|April|May|June|July|August|September|October|November|December',
                  xfontColor            : "#444",
                  xopacity              : 1.0,
                  xfontSize             : 12,
                  xfontWeight           : "normal",
                  xfontStyle            : "normal",
                  xfontFamily           : "Helvetica, Arial, Verdana, sans-serif",
                  xtextAnchor           : "end",
                  xrotation             : 315,
                  displayValues         : false,
                  title                 : "Sales by Month",
                  titleFontSize         : "24px",
                  titleFontWeight       : "normal",
                  titleFontStyle        : "normal",
                  titleFontFamily       : "Helvetica, Arial, Verdana, sans-serif",
                  titleFontColor        : "#444",
                  xTitle                : "Months",
                  xTitleFontSize        : 16,
                  xTitleFontWeight      : "normal",
                  xTitleFontStyle       : "normal",
                  xTitleFontFamily      : "Helvetica, Arial, Verdana, sans-serif",
                  xTitleFontColor       : "#444",
                  yTitle                : "Gross Value",
                  yTitleFontSize        : 16,
                  yTitleFontWeight      : "normal",
                  yTitleFontStyle       : "normal",
                  yTitleFontFamily      : "Helvetica, Arial, Verdana, sans-serif",
                  yTitleFontColor       : "#444",
                  threeD                : true,
                  depth                 : 10,
                  animationTime         : 750,
                  gridBackgroundColor   : "#dbd39a",
                  gridBanding           : true,
                  gridOpacity           : 1.0,
                  gridBackgroundImage   : "",
                  gridLineWidth         : 0.3,
                  gridLineStyle         : ". ",
                  gridAxisWidth         : 2,
                  gridAxisStyle         : "- ",
                  gridNRows             : 6,
                  gridColSpacing        : 65,
                  gridRowSpacing        : 50,
                  gridxPos              : 75,
                  gridyPos              : 400,
                  xLabelPre             : "",
                  xLabelPost            : "",
                  yLabelColor           : "#777",
                  yLabelPre             : "$",
                  yLabelPost            : "",
                  x2LabelPre            : "",
                  x2LabelPost           : "",
                  y2LabelPre            : "",
                  y2LabelPost           : " units",
                  ndecplaces            : 0,
                  ndecplaces2           : 3,
                  xrotation             : 315,
                  legendXpos            : 250,
                  legendYpos            : 45,
                  legendPadding         : 6,
                  legendRoundRadius     : 6,
                  legendOpacity         : 0.7,
                  legendBackground      : false,
                  legendBackgoundColor  : '#ffffff',
                  legendBorderColor     : '#888',
                  legendBorderWidth     : 0,
                  legendStyle           : 'horizontal',
                  legendTitle           : 'Products',
                  legendTitleFontSize   : 14,
                  legendTitleFontWeight : 'normal',
                  legendTitleFontStyle  : 'normal',
                  legendTitleFontFamily : 'Helvetica, Arial, Verdana, sans-serif',
                  legendTitleFontColor  : '#000',
                  legendFontSize        : 12,
                  legendFontWeight      : 'normal',
                  legendFontStyle       : 'normal',
                  legendFontFamily      : 'Helvetica, Arial, Verdana, sans-serif',
                  legendFontColor       : '#444'
                });
    }
    </script>                
                    scene.setOnKeyPressed(new EventHandler<KeyEvent>() {
 public void handle(final KeyEvent keyEvent) {
   if (keyEvent.getCode() == KeyCode.F5) {
    System.out.println("F5 pressed");
    //Stop letting it do anything else
    keyEvent.consume();
   }
 }
});


final KeyCombination keyComb1 = new KeyCodeCombination(KeyCode.R,
                                    KeyCombination.CONTROL_DOWN);
scene.addEventHandler(KeyEvent.KEY_RELEASED, new EventHandler<KeyEvent>() {
                @Override
                public void handle(KeyEvent event) {
                    if (keyComb1.match(event)) {
                        System.out.println("Ctrl+R pressed");
 
                    }
                }
            });