Skip to content

Instantly share code, notes, and snippets.

@ninadsp
Last active November 4, 2017 12:46
Show Gist options
  • Save ninadsp/6098996 to your computer and use it in GitHub Desktop.
Save ninadsp/6098996 to your computer and use it in GitHub Desktop.
Code snippets from my blog (http://ninad.pundaliks.in/blog)
$: echo -e "\ahi \nsent by user" > /dev/tty1
hi
sent by user
$ echo -e "Bringing down eth0 interface in 5 mins \a.\nPlease log out!\n-Admin">/dev/pts/1
#Launchpad ppa's for amarok 1.4 in jaunty!
deb http://ppa.launchpad.net/bogdanb/ppa/ubuntu jaunty main
deb-src http://ppa.launchpad.net/bogdanb/ppa/ubuntu jaunty main
$ dcop amarok player play
$ dcop amarok player stop
$ dcop amarok player isPlaying
$ dcop amarok player mute
$ dcop amarok player setVolume [volume in percentage]
$ cat UbuntuCodeofConduct-1.0.1.txt | grep name | wc -l
15
alias ls='ls --color=auto'
alias dir='ls --color=auto --format=vertical'
alias vdir='ls --color=auto --format=long'
alias ll='ls -l'
alias la='ls -A'
alias l='ls -CF'
#!/bin/bash
cat /proc/acpi/thermal_zone/THRM/temperature;
exit 0;
ninad@ml-228:~$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda6 15G 9.9G 4.1G 71% /
varrun 696M 136K 696M 1% /var/run
varlock 696M 0 696M 0% /var/lock
procbususb 696M 52K 696M 1% /proc/bus/usb
udev 696M 52K 696M 1% /dev
devshm 696M 0 696M 0% /dev/shm
lrm 696M 38M 659M 6% /lib/modules/2.6.24-16-generic/volatile
/dev/sda5 61G 49G 9.5G 84% /home
/dev/sda1 20G 20G 0 100% /media/sda1
/dev/sda2 15G 14G 1.9G 88% /media/sda2
<?php
/**
* FlxZipArchive, Extends ZipArchiv.
* Add Dirs with Files and Subdirs.
*
* <code>
* $archive = new FlxZipArchive;
* // .....
* $archive->addDir( 'test/blub', 'blub' );
* </code>
*/
class FlxZipArchive extends ZipArchive {
/**
* Add a Dir with Files and Subdirs to the archive
*
* @param string $location Real Location
* @param string $name Name in Archive
* @author Nicolas Heimann
* @access private
**/
public function addDir($location, $name) {
$this->addEmptyDir($name);
$this->addDirDo($location, $name);
} // EO addDir;
/**
* Add Files & Dirs to archive.
*
* @param string $location Real Location
* @param string $name Name in Archive
* @author Nicolas Heimann
* @access private
**/
private function addDirDo($location, $name) {
$name .= '/';
$location .= '/';
// Read all Files in Dir
$dir = opendir ($location);
while ($file = readdir($dir))
{
if ($file == '.' || $file == '..') continue;
// Rekursiv, If dir: FlxZipArchive::addDir(), else ::File();
$do = (filetype( $location . $file) == 'dir') ? 'addDir' : 'addFile';
$this->$do($location . $file, $name . $file);
}
} // EO addDirDo();
}
?>
<?php
//Don't forget to remove the trailing slash
$the_folder = '/path/to/folder/to/be/zipped';
$zip_file_name = '/path/to/zip/archive.zip';
$za = new FlxZipArchive;
$res = $za->open($zip_file_name, ZipArchive::CREATE);
if($res === TRUE) {
$za->addDir($the_folder, basename($the_folder));
$za->close();
}
else
echo 'Could not create a zip archive';
?>
ninad@ml-228:~$ free -m
total used free shared buffers cached
Mem: 1391 1359 31 0 56 765 -/+ buffers/cache: 538 853
Swap: 1019 459 559
website/dir$:cat * | grep [your string goes here]
ps -A | grep [process name]
#!/bin/bash
# Timepass script to experiment with imagemagick
for x in 0 1 2 3 4 5 6
do
convert -size 100x100 plasma:fractal -font Helvetica-Bold -pointsize 90 -tile gradient:white-gray -stroke white -annotate +26+78 $x $x.jpg;
echo -e "$x.jpg generated\n";
done;
unset x;
exit 0;
convert -size 150x150 xc:none -background none \
-fill white -stroke grey60 \
-draw "rectangle 0,0 110,110" 0.jpg \
-geometry +5+5 -composite -rotate -10 \
-draw "rectangle 0,0 110,110" 1.jpg \
-geometry +5+5 -composite -rotate -10 \
-draw "rectangle 0,0 110,110" 2.jpg \
-geometry +5+5 -composite -rotate -10 \
-draw "rectangle 0,0 110,110" 3.jpg \
-geometry +5+5 -composite -rotate -10 \
-draw "rectangle 0,0 110,110" 4.jpg \
-geometry +5+5 -composite -rotate -10 \
-draw "rectangle 0,0 110,110" 5.jpg \
-geometry +5+5 -composite -rotate -10 \
-draw "rectangle 0,0 110,110" 6.jpg \
-geometry +5+5 -composite -rotate +10 \
-trim +repage -background gray -flatten \
poloroid_spread.gif
$ sudo mount /path/to/jaunty/iso /cdrom -o loop
$ sudo ./cdromupgrade
$ cd /etc/apt/
$ sudo mv sources.lst.d/ sources.lst.d.backup/
$ sudo mkdir sources.lst.d
$ sudo aptitude install dpkg apt aptitude
$ sudo aptitude safe-ugrade
$ sudo aptitude full-upgrade
$ cd /home/user/.psi/avatars
$ montage -background "#9DAABA" -frame 10 -mattecolor "#FFFFFF" -shadow * /home/user/montage.jpg
Server: 127.0.0.1
Address: 127.0.0.1#53
Non-authoritative answer:
Name: google.com
Address: 64.233.187.99
Name: google.com
Address: 72.14.207.99
Name: google.com
Address: 64.233.167.99
if [ ! -d “/path/to/dir” ] ; then
mkdir -p /path/to/dir;
echo “Directory did not exist. Created”;
fi;
if [ -d “/path/to/dir” ] ; then
#do nothing
else
mkdir -p /oath/to/dir;
echo “Directory did not exist. Created”;
fi;
$(document).ready(function() {
$("#response").hide();
$("#submit").click(function(event) {
event.preventDefault();
$("#response").text("Processing...").show("slow");
$.ajax({ type: 'POST',
url: 'twitter_ajax.php',
data:{ajax_req: true,
username: $("#username").val(),
password: $("#password").val(),
status: $("#status").val()
},
success: function(data){
var output = "";
output += "Tweet ID : "+data.id+"<br />";
output += "Text : "+data.text+"<br />";
output += "Username : "+data.user.name+"<br />";
$("#response").html(output);
}
})
});
});
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<fieldset>
<legend>Twitter Details</legend>
<ul>
<li>
<label for="username">Username: </label>
<input id="username" name="username" type="text" />
</li>
<li>
<label for="password">Password: </label>
<input id="password" name="password" type="password" />
</li>
<li>
<label for="status">Status: </label>
<textarea id="status" name="textarea"> </textarea>
</li>
<li>
<input id="submit" name="submit" type="submit" value="Post Tweet" />
</li>
</ul>
</fieldset>
<div id="response"></div>
</body>
</html>
<?php
if($_REQUEST['ajax_req'] == true)
{
//Process the tweet
$username = $_REQUEST['username'];
$password = $_REQUEST['password'];
$status = $_REQUEST['status'];
$auth_string = $username.":".$password;
$postdata = array('status' => $status );
$options = array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $postdata,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_URL => 'https://twitter.com/statuses/update.json',
CURLOPT_USERPWD => $auth_string
);
$ch = curl_init();
curl_setopt_array($ch, $options);
$data = curl_exec($ch);
curl_close($ch);
Header('Type: application/json')
die($data);
}
?>
ninad@ml-228:~$ uptime
18:06:43 up 5 days, 6:24, 1 user, load average: 0.47, 0.39, 0.28
$ who
user tty2 2008-08-25 01:19
root tty1 2008-08-25 01:19
user :0 2008-08-22 13:31
root pts/1 2008-08-22 14:32 (172.34.2.12)
ninad@ml-228:~$ who -b
system boot 2008-08-15 11:45
ninad@ml-228:~$ who
ninad :0 2008-08-15 11:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment