Category: Tech Blog

Easy file manipulations in locked folders

Sometimes you want to delete/ insert/ edit files that are in some locked location – like – outside your Home folder, in the system somewhere in Ubuntu. You could use the terminal to gain admin privileges and access the files, or copy/ move folders, but there is an easier way. You can do it through the GUI by typing this into the terminal:

  • gksudo nautilus

Then a new finder window will open in which you will be running in SUDO – Admin. Nautilus is the file manager used in Ubuntu Unity. If you use Kubuntu it would be “kdesudo dolphin” for example. This is an add-on which adds an “Open as administrator” dialogue to right click.

Extract here when double click

Mac computers save a bit of time with extracting for simple people that just want to always extract to current folder – just double click, and it loads.. no menus, no semi-extracted file browsers. Simple.

In ubuntu: do this:

  • right click on a ZIP file (etc.)
  • select: “open with other application”
  • click “use custom command”
  • paste in ”/usr/bin/file-roller -h”
  • check “remember this application”

And that’s it  ~ ZIP files will always extract on double click.

(you need to repeat this process for different types of archives)

Share your mouse between two computers – Ubunt, Mac – SynergyShare

I saw some posts and tutorials about using Synergy to connect Ubuntu/Mac – but after following a few, I couldn’t get it to work, then trial and error, more tutorials, and I got it, so I’ll share – Ubuntu having the mouse/ keyboard, and sharing them with Mac – (client)

This makes it as if it’s dual-screen – but with different operating systems.

  • Ubuntu – search software center for “synergy” – install QuickSynergy
  • Mac – SynergyKM – I used version 1.3.1
  • I don’t know if this file has anything to do with getting it to work, but:
    download this file, edit it replacing “pushka” with your main computer name that has the keyboard and mouse to share, and “sda” with the extra computer.
  • Install these on the separate machines
  • Then move the file to /etc (in Filesystem, Root.) But you need to have Admin privileges.
    Open up Terminal, type in:
    “sudo mv “
    Then drag into the terminal the file you just downloaded (it will write in the link to it)
    Then press space
    Then type “/etc” (or again, drag in the folder into the terminal.)
  • On ubuntu open up the preferences -> share, and type in the computer name in the box where you want the computer mouse to switch to the mac.
    EG: I have my MacBook next to my desktop on the left, so I type “sda” (the name of my Mac Computer into the left box)
  • On Mac – Prefrences -> use, type in the computer name and .local (like, “pushka.local”)
  • Then run the two apps on both computers, and it should be done ~ ~

If you find it’s the same on other opperating systems, leave a comment below ~
If you don’t need that file – comment, and I’ll remove those steps ~

Resize windows by holding Alt, and draging right click

In Ubuntu the edge of windows for resizing is quite sensitive and thin.

But there is an easier way to resize windows ~ 
just like you can move windows around by holding Alt and draging the window with your left mouse button – you can do the same with your right mouse button to resize the window.

Install Compiz – then do this:

Alt+F2 (run program) -> type ‘gconf-editor’ ->  click to directories: apps -> metacity -> general -> ‘resize_with_right_button’ tick the checkbox

And that’s it ~

Delete everything in a folder in the terminal~

I had this problem that I had an undeletable file – when I pressed “delete” or “rename”, it would say “file does not exist”
I got rid of one in the terminal, but the other had a “!” in the filename and so terminal thought it was some other command…

Delete everything in a folder in the terminal:

sudo rm -rf ~/Folder/*

`Warning – files deleted this way can’t be recovered.

Simple PHP email form with basic spam protection CAPTCHA

There are two pieces of code – the one which will display your email form, and a block of code to add into your “mailer” page – a page dedicated to sending the messages and displaying confirmations and errors.

Feel free to edit or tweak the code, download the images to your own server and use however you wish.

The form

<!-- email box ~ -->
<div style="width:400px;text-align:right;padding:0px 0px 0px 0px; margin:0px 0px 0px 0px;">
<form action="send.php" method="post" style="padding:0px 0px 0px 0px; margin:0px 0px 0px 0px;">
<p style="padding:0px 0px 0px 0px; margin:0px 0px 0px 0px;">
Name: <input type="text" name="email_name" size=20><br>
Email: <input type="text" name="email_email" size=20>
<?php
$one = 1;
$two = 0;
$three = 0;
$four = 0;
while ($one % 2) $one = rand (10000,99999);
while (!($two % 2)) $two = rand (10000,99999);
while (!($three % 2)) $three = rand (10000,99999);
while (!($four % 2)) $four = rand (10000,99999);
?>
<br>Are you a human or internet virus?
<br>Choose the odd one out:
</p>
<div style="padding:0px 0px 0px 0px; margin:0px 0px 0px 0px;">
<input type="radio" name="email_valid" value="<?php echo $four ?>" Checked=1> <img src="https://pushka.com/p/i/sys/lion.png" alt="This is a public domain image">
<input type="radio" name="email_valid" value="<?php echo $two ?>"> <img src="https://pushka.com/p/i/sys/elephant.png" alt="This is a public domain image">
<input type="radio" name="email_valid" value="<?php echo $one ?>"> <img src="https://pushka.com/p/i/sys/lifter.png" alt="This is a public domain image">
<input type="radio" name="email_valid" value="<?php echo $three ?>"> <img src="https://pushka.com/p/i/sys/penguin.png" alt="This is a public domain image">
</div>
<p style="width:200; text-align:left;padding-bottom:0px; margin:0px 0px 0px 0px;padding-top:0px; padding-left:150px;">Message:</p>
<textarea rows="7" cols="30" name="email_msg" style="padding:0px 0px 0px 0px; margin:0px 0px 0px 0px;">
</textarea><br>
<input type="submit" value="Send">
</form>
</div>

The sender and confirmation message generator (should be in the main text region of your regular website theme)

<div title="main"><h1>Send</h1>
<div style="width:400px;"><br /><br />
<?php
$name = $_POST["email_name"];
$email = $_POST["email_email"];
$valid = $_POST["email_valid"];
$message = $_POST["email_msg"];
$error = 0;
if (strlen($email) == 0) {
echo "<img src='https://pushka.com/p/i/sys/cross.png'> Please enter an email<br>";
$error =1;}
elseif (strpos($email,"@") === false | strlen($email) < 6){
echo "<img src='https://pushka.com/p/i/sys/cross.png'> Please enter a valid email in the form X@X.XX<br>";
$error=1;}
if (strlen($message)==0){
echo "<img src='https://pushka.com/p/i/sys/cross.png'> Please enter a message<br>";
$error=1;}
if ($valid%2){
echo "<img src='https://pushka.com/p/i/sys/cross.png'> There was an error with the image validation, please select the odd one out.<br>";
$error=1;}
if (strlen($name) == 0) $name = $email;
$message = "This message was sent from pushka.com/p - from " . $name . " \n ---------------------------- \n \n " . $message . " \n \n ---------------------------- \n \n \n";
if ($error==0){
echo "<img src='https://pushka.com/p/i/sys/tick.png'> Email Sent<br><br><FORM><INPUT TYPE='button' VALUE='Back' onClick='history.go(-1);return true;'> </FORM> <br>";
$to = 'you@mail.com';
$subject = 'Message from pushka.com/p';
$headers = 'From: ' . $email . " \r\n" .
'Reply-To: ' . $email . " \r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
}
else{
echo "<br><FORM><INPUT TYPE='button' VALUE='Back' onClick='history.go(-1);return true;'> </FORM> <br>";
}
?>
<br><br>
</div>
</div>

 Here is an example

The emails are sent to the Cosmic Owl, who may or may not ever respond to you

[widgets_on_pages id=”PHPemailForm”]

You can have both blocks of code on the same page if you have action=””

Featured Video rather than Image for WordPress

Some templates have a featured image, but sometimes you want a video instead… But not all the time..

You can set some custom fields, and then add in PHP – if the field has something in it – display the embedded video (at the same size the featured image would have been…)

The text in the custom field should just be the ID code for YouTube or Vimeo (or you can add your own if you want… but you need to add the embed code to the PHP)

The code gets the ID and inserts it into the embed code.

<?php
if (post_custom(‘a YouTube ID Code’)) {
echo ‘<iframe width=”640″ height=”402″ src=”https://www.youtube.com/embed/’ . get_post_meta($post->ID, ‘a YouTube ID Code’, $single = true) . ‘” frameborder=”0″ allowfullscreen></iframe>’ ;
}
else if (post_custom(‘a Vimeo ID Code’)){
echo ‘<iframe src=”http://player.vimeo.com/video/’ . get_post_meta($post->ID, ‘a Vimeo ID Code’, $single = true) . ‘?title=0&amp;byline=0&amp;portrait=0″ width=”400″ height=”225″ frameborder=”0″ webkitAllowFullScreen allowFullScreen></iframe>’ ;
}else{
?>

 

add the YouTube or Vimeo ID code to a custom field:

  • a YouTube ID Code
  • a Vimeo ID Code

EG:

  • bH9tJXm2Bcw
  • 31934775

From the original YouTube links:

  • https://www.youtube.com/watch?=bH9tJXm2Bcw&feature=channel_video_title
  • http://vimeo.com/31934775