you are here: codestackercodes [RSS]

update wordpress url

use this sql when migrating a website

UPDATE wp_options SET option_value = replace(option_value, 'http://oldsite', 'http://newsite') WHERE option_name = 'home' OR option_name = 'siteurl';

UPDATE wp_posts SET guid = replace(guid, 'http://oldsite','http://newsite');

UPDATE wp_posts SET post_content = replace(post_content, 'http://oldsite', 'http://newsite');

simple http monitor based on keyword

http://leonardofaria.net/2015/07/10/uptime-monitoring-tools/

gem 'mechanize', '2.7.2'
require 'mechanize'
require 'pony'

def sendmail(to, subject, body)
	Pony.mail({
	  :to => to,
	  :via => :smtp,
	  :subject => subject,
	  :body => body,
	  :charset => 'UTF-8',
	  :via_options => {
		:address => 'smtp.sendgrid.net',
			:port => '587',
			:domain => 'heroku.com',
			:user_name => ENV['SENDGRID_USERNAME'],
			:password => ENV['SENDGRID_PASSWORD'],
			:authentication => :plain,
			:enable_starttls_auto => true
	  }
	})
end

mechanize = Mechanize.new{|a| a.ssl_version, a.verify_mode = 'SSLv3', OpenSSL::SSL::VERIFY_NONE}
page = mechanize.get('https://www.yourwebsite.com/mytesturl')

content = ""

if page.body.include?('refused')
	content = 'Error: Connection Refused'
end

if content
	puts content
	sendmail("email@domain.com", "Monitor", content)
end

shell script for audio recording

details in this post: http://leonardofaria.net/2016/01/26/shell-script-for-audio-recording/

#!/bin/bash


# paths

TIMELIMIT="timelimit"
LIVESTREAMER="livestreamer"
FFMPEG="ffmpeg"

# parameters

IN=$1
OUT=$2
TIME=$3
if [[ -z $TIME ]]; then TIME="3600"; fi

if [ $# -lt 1 ]; then
	echo -n "Usage: $0 url output [time]"
	exit 0
fi

if [[ -z `which $TIMELIMIT` ]]; then
	echo "timelimit not found" 1>&2
	exit 1;
fi

if [[ -z `which $LIVESTREAMER` ]]; then
	echo "livestreamer not found" 1>&2
	exit 1;
fi

if [[ -z `which $FFMPEG` ]]; then
	echo "ffmpeg not found" 1>&2
	exit 1;
fi

echo "START STREAMING"
$TIMELIMIT -t $TIME $LIVESTREAMER $IN best -o $OUT.ts

echo "CONVERTING FILE TO MP3"
ffmpeg -y -i $OUT.ts -c:a libmp3lame -b:a 64k -joint_stereo 0 $OUT

rm $OUT.ts
echo "DONE"

replace git author using shell script

#!/bin/sh

git filter-branch -f --env-filter '

an="$GIT_AUTHOR_NAME"
am="$GIT_AUTHOR_EMAIL"
cn="$GIT_COMMITTER_NAME"
cm="$GIT_COMMITTER_EMAIL"

if [ "$GIT_COMMITTER_EMAIL" = "old@email.com" ]
then
  cn="New author name"
  cm="new@email.com"
fi

export GIT_AUTHOR_NAME="$an"
export GIT_AUTHOR_EMAIL="$am"
export GIT_COMMITTER_NAME="$cn"
export GIT_COMMITTER_EMAIL="$cm"
'

echo "Run after"
echo "git push origin +master:master"

getting battery information in the mac terminal

pmset -g batt

fixing wordpress permissions

find . -name '*.php' | xargs chmod 644
find . -type d | xargs chmod 755

How to Make a Bootable OS X Yosemite

https://support.apple.com/en-sg/HT201372

sudo /Applications/Install\ OS\ X\ Yosemite.app/Contents/Resources/createinstallmedia --volume /Volumes/MyVolume --applicationpath /Applications/Install\ OS\ X\ Yosemite.app

How to Make a Bootable OS X El Capitan

sudo /Applications/Install\ OS\ X\ El\ Capitan.app/Contents/Resources/createinstallmedia --volume /Volumes/ElCapInstaller --applicationpath /Applications/Install\ OS\ X\ El\ Capitan.app --nointeraction

git log for humans

git log --graph --format=format:'%C(yellow)%h%C(reset) %C(red)- %an%C(reset) - %C(white)%s%C(reset) %C(bold yellow)%d%C(reset) %C(green)(%ar)%C(reset)' --abbrev-commit --date=short

android - add battery percentage in status bar

Android 5

adb shell content insert --uri content://settings/system --bind name:s:status_bar_show_battery_percent --bind value:i:1
adb reboot

how to hide php version

Edit your php.ini file

expose_php = off

how to hide nginx version

The server_tokens variable can be used either in the http, server or location sections.
In your nginx.conf file:

server_tokens off;

get invalid email

SELECT * FROM contact WHERE email NOT REGEXP '^[a-zA-Z0-9][a-zA-Z0-9._-]*[a-zA-Z0-9]@[a-zA-Z0-9][a-zA-Z0-9._-]*[a-zA-Z0-9]\.[a-zA-Z]{2,4}$'

Change Chrome interface

   defaults write com.google.Chrome AppleLanguages '(en-US)' 

   defaults write com.google.Chrome AppleLanguages '(pt-BR)' 

disable spotlight in mountain lion

sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.metadata.mds.plist

select invalid emails

if validation breaks...

SELECT * FROM users WHERE email NOT REGEXP '^[A-Z0-9\._%-]+@[A-Z0-9\.-]+\.[A-Z]{2,4}$'

solve: Got a packet bigger than 'max_allowed_packet' bytes

solve import problem: Got a packet bigger than 'maxallowedpacket' bytes

set global max_allowed_packet=1000000000; 
set global net_buffer_length=1000000; 

count unique ips in apache access log

awk '{!a[$1]++}END{for(i in a) if ( a[i] >10 ) print a[i],i }'

good practice to css typografic

Via http://goo.gl/O4yzj

h1, h2, h3, h4, h5, h6 { line-height: 1.1; }
body { font: 16px/1.5 "Lucida Grande", Verdana, sans-serif }

get database's size

select table_schema "Database Name", round(sum(data_length + index_length) / 1024 / 1024, 1) "Database Size (MB)" 
from information_schema.TABLES group by table_schema;
Displaying Code 1 - 20 of 299 in total