Preventing Apache memory leaks with ulimit
#!/bin/sh HTTPD=/usr/local/apache2/bin/httpd CONF=/bmi/httpd-php/conf/httpd.conf exec 2>&1 echo starting... ulimit -v 100000 exec $HTTPD -f $CONF -D NO_DETACH
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!)
#!/bin/sh HTTPD=/usr/local/apache2/bin/httpd CONF=/bmi/httpd-php/conf/httpd.conf exec 2>&1 echo starting... ulimit -v 100000 exec $HTTPD -f $CONF -D NO_DETACH
# start the server, enter your *nix password when prompted sudo mysqld_safe & # get the version string, enter the mysql_root password when prompted mysql -u root -p -e status | grep 'Server version' # sez "Server version: 5.0.18-standard"
<?php function cmp_date($a,$b) { if ($a['start_date'] > $b['start_date']) return 1; if ($a['start_date'] < $b['start_date']) return -1; return 0; } if (module_exists('civicrm')) { civicrm_initialize(TRUE); require_once 'api/v2/Event.php'; $params = array (); $myEvents = civicrm_event_search( $params ); if ($myEvents) { $count = 0; $last = ''; usort($myEvents,'cmp_date'); foreach ($myEvents as $event) { $now = date('Y-m-d H:i:s'); if ($now > $event['start_date']) continue; $startdate = date('D M j Y',strtotime($event['start_date'])); $enddate = date('D M j Y',strtotime($event['end_date'])); $eventid = $event['id']; list($title_place, $title_desc) = split(":",$event['title'],2); if ($last != $startdate) { $display = '<br /><b>'.$startdate.'</b><br />'; } $display .= l($title_place.' '.$title_desc, 'civicrm/event/info', array(), 'reset=1&id='.$event['id']).'<br />'; echo $display; $count++; $last = $startdate; if ($count > 8) break; // this limits the number of events to 8 - put in whatever number suits you } if ($count > 0) { } else { echo 'No events found.'; } } else { echo 'No events found.'; } } ?>
isMac = (navigator.appVersion.indexOf(”Mac”)!=-1) ? true : false; NS4 = (document.layers) ? true : false; IEmac = ((document.all)&&(isMac)) ? true : false; IE4plus = (document.all) ? true : false; IE4 = ((document.all)&&(navigator.appVersion.indexOf(”MSIE 4.”)!=-1)) ? true : false; IE5 = ((document.all)&&(navigator.appVersion.indexOf(”MSIE 5.”)!=-1)) ? true : false; IE6 = ((document.all)&&(navigator.appVersion.indexOf(”MSIE 6.”)!=-1)) ? true : false; IE7 = ((document.all)&&(navigator.appVersion.indexOf(”MSIE 7.”)!=-1)) ? true : false; ver4 = (NS4 || IE4plus) ? true : false; NS6 = (!document.layers) && (navigator.userAgent.indexOf(’Netscape’)!=-1)?true:false; /* * We can also use */ # if (typeof document.body.style.maxHeight != "undefined") { # // IE 7, mozilla, safari, opera 9 # } else { # // IE6, older browsers # } //or if (window.XMLHttpRequest) { // IE 7, mozilla, safari, opera 9 } else { // IE6, older browsers }
BEGIN DECLARE @MailDelivery int, @EmailDelivery int, @FaxDelivery int, @ParamVal int, @ZeroVal int set @MailDelivery = 1 --(0001) set @EmailDelivery = 2 --(0010) set @FaxDelivery = 4 --(0100) set @ParamVal = 1 set @ZeroVal = 0 if @ParamVal = 0 set @ZeroVal = null set @ParamVal = isnull(@ParamVal, 0) SELECT Id, --BusinessEventDate, DeliveryFlags, (isnull(DeliveryFlags,0) & @ParamVal) as BitMask FROM Mailsets WHERE (BusinessEventDate > '8/28/2007') --Check the appropriate bit. AND ( (isnull(DeliveryFlags,0) & @ParamVal) = @ParamVal + isnull(@ZeroVal, isnull(DeliveryFlags,0)) ) END GO
require 'RMagick' class Profile < ActiveRecord::Base belongs_to :user #image = the image passed from params[:image] #file_type = the confirmed filetype from the controller #current_user = various information about the current user def self.upload(image, file_type, current_user) #set default cols and rows for our two images that will be created from the uploaded user image img_size = {:main =>{:cols => 250,:rows => 375}, :thumb =>{:cols =>80, :rows =>120} } #set base directory for the users image imgDir = "#{RAILS_ROOT}/public/images/user_images" #set the base name for our userimage userImg = " #{current_user.login}-#{current_user.id}" #loop through the image dir and delete any old user images Dir.foreach(imgDir){|file| if file.to_s.include?(userImg) File.unlink("#{imgDir}/#{file}") end } #read the image from the string imgs = Magick::Image.from_blob(image.read) #change the geometry of the image to suit our predefined size main_image = imgs.first.change_geometry!("#{img_size[:main][:cols]}x#{img_size[:main][:rows]}") { |cols, rows, img| #if the cols or rows are smaller then our predefined sizes we build a white background and center the image in it if cols < img_size[:main][:cols] || rows < img_size[:main][:rows] #resize our image img.resize!(cols, rows) #build the white background bg = Magick::Image.new(img_size[:main][:cols],img_size[:main][:rows]){self.background_color = "white"} #center the image on our new white background bg.composite(img, Magick::CenterGravity, Magick::OverCompositeOp) else #in the unlikely event that the new geometry cols and rows match our predefined size we will not set a white bg img.resize!(cols, rows) end } main_image.write "#{imgDir}/#{userImg}.#{file_type}" thumb = imgs.first.change_geometry!("#{img_size[:thumb][:cols]}x#{img_size[:thumb][:rows]}") { |cols, rows, img| if cols < img_size[:thumb][:cols] || rows < img_size[:thumb][:rows] img.resize!(cols, rows) bg = Magick::Image.new(img_size[:thumb][:cols],img_size[:thumb][:rows]){self.background_color = "white"} bg.composite(img, Magick::CenterGravity, Magick::OverCompositeOp) else img.resize!(cols, rows) end } thumb.write "#{imgDir}/#{userImg}-thumb.#{file_type}" if FileTest.exist?("#{imgDir}/#{userImg}.#{file_type}") return "The file was written and its name is #{userImg}.#{file_type}" else return false end end end
function stop(e) { if (!e) e = window.event; (e.stopPropagation) ? e.stopPropagation() : e.cancelBubble = true; (e.preventDefault) ? e.preventDefault() : e.returnValue = false; return false; }
myId = function(me){ return me.id ? '#' + me.id : '' } myTag = function(me){ return me.tagName ? me.tagName.toLowerCase() : '' } myClass = function(me){ return me.className ? '.' + me.className.split(' ').join('.') : '' } breadcrumbs = function(me){ var path = [myTag(me) + myId(me) + myClass(me)]; $(me).parents().each(function() { path[path.length] = myTag(this) + myId(this) + myClass(this); }); return path.join(' < '); } $('body').click( function(){ alert( breadcrumbs(this) ); });
var images = new Array(); function preloadImages(){ for (i=0; i < preloadImages.arguments.length; i++){ images[i] = new Image(); images[i].src = preloadImages.arguments[i]; } } preloadImages("logo.jpg", "main_bg.jpg", "body_bg.jpg", "header_bg.jpg");
MovieClip.prototype.autoframeNavigate = function(delay, bContinue, numberOfFrames) { navigate = function(clipName) { desiredFrameNumber = clipName._currentframe + numberOfFrames; bContinue == "stop" ? clipName.gotoAndStop(desiredFrameNumber):clipName.gotoAndPlay(desiredFrameNumber); clearInterval( clipName.autoframeNavigateID ); } this.autoframeNavigateID = setInterval(navigate, delay, this); }