I'm getting a little git gist happy. :) So here's something just for kicks. I'm gonna start posting other things than bash. Perhaps more python and php code. ATM I'm reading "JavaScript: The Good Parts" I highly recommend this book, it's a good read. Been meaning to read it for a while to brush up on my js coding skills, because I plan on doing a lot of nodejs development here in the near future for a import/export system.
Wednesday, September 8, 2010
running aliases and functions with sudo, and Blogger bashing
I don't remember where I got this like 3 years ago. Just thought I'd share it because it's very useful. Maybe it will be as useful for you as it is for me.
Blogger seems to always mess up my indentations. So it's not really good for python code. However, this is a bash function to wrap aliases and functions in sudo. I wish blogger wouldn't do that. But wait folks that's not all. It assists me in losing changes too. Gotta love that. If you see me switch over to posterous or not blog on here anymore, then you will know why. Not much incentive to use a system that screws with your text or text formating. hahaha, even Gov. Arnold has a posterous.
Better yet I will place code in a gist and keep ranting :) (I'll leave the below function declaration so you can see how ugly it looks)
sudo ()
{
local c o t parse
# Parse sudo args
OPTIND=1
while getopts xVhlLvkKsHPSb:p:c:a:u: t; do
if [ "$t" = x ]; then
parse=true
else
o="$o -$t"
[ "$OPTARG" ] && o="$o $OPTARG"
fi
done
shift $(( $OPTIND - 1 ))
# If no arguments are left, it's a simple call to sudo
if [ $# -ge 1 ]; then
c="$1";
shift;
case $(type -t "$c") in
"")
echo No such command "$c"
return 127
;;
alias)
c=$(type "$c"|sed "s/^.* to \`//;s/.$//")
;;
function)
c=$(type "$c"|sed 1d)";\"$c\""
;;
*)
c="\"$c\""
;;
esac
if [ -n "$parse" ]; then
# Quote the rest once, so it gets processed by bash.
# Done this way so variables can get expanded.
while [ -n "$1" ]; do
c="$c \"$1\""
shift
done
else
# Otherwise, quote the arguments. The echo gets an extra
# space to prevent echo from parsing arguments like -n
# Note the lovely interactions between " and ' ;-)
while [ -n "$1" ]; do
c="$c '$(echo " $1"|sed -e "s/^ //" -e "s/'/'\"'\"'/")'"
shift
done
fi
# Run the command with verbose options
echo Executing sudo $o -- bash -x -v -c "$c" >&2
command sudo $o bash -xvc "$c"
else
echo sudo $o >&2
command sudo $o
fi
}
Blogger seems to always mess up my indentations. So it's not really good for python code. However, this is a bash function to wrap aliases and functions in sudo. I wish blogger wouldn't do that. But wait folks that's not all. It assists me in losing changes too. Gotta love that. If you see me switch over to posterous or not blog on here anymore, then you will know why. Not much incentive to use a system that screws with your text or text formating. hahaha, even Gov. Arnold has a posterous.
Better yet I will place code in a gist and keep ranting :) (I'll leave the below function declaration so you can see how ugly it looks)
sudo ()
{
local c o t parse
# Parse sudo args
OPTIND=1
while getopts xVhlLvkKsHPSb:p:c:a:u: t; do
if [ "$t" = x ]; then
parse=true
else
o="$o -$t"
[ "$OPTARG" ] && o="$o $OPTARG"
fi
done
shift $(( $OPTIND - 1 ))
# If no arguments are left, it's a simple call to sudo
if [ $# -ge 1 ]; then
c="$1";
shift;
case $(type -t "$c") in
"")
echo No such command "$c"
return 127
;;
alias)
c=$(type "$c"|sed "s/^.* to \`//;s/.$//")
;;
function)
c=$(type "$c"|sed 1d)";\"$c\""
;;
*)
c="\"$c\""
;;
esac
if [ -n "$parse" ]; then
# Quote the rest once, so it gets processed by bash.
# Done this way so variables can get expanded.
while [ -n "$1" ]; do
c="$c \"$1\""
shift
done
else
# Otherwise, quote the arguments. The echo gets an extra
# space to prevent echo from parsing arguments like -n
# Note the lovely interactions between " and ' ;-)
while [ -n "$1" ]; do
c="$c '$(echo " $1"|sed -e "s/^ //" -e "s/'/'\"'\"'/")'"
shift
done
fi
# Run the command with verbose options
echo Executing sudo $o -- bash -x -v -c "$c" >&2
command sudo $o bash -xvc "$c"
else
echo sudo $o >&2
command sudo $o
fi
}
rants about stuff and CourtesyFlush
I haven't blogged in a while. So, ummm. I really am not sure what to blog about. It kinda seems like an old fad for me to blog. I just like to mostly read what others have to say and learn from others. It's nice to give back though. I like to give back. Just I do it in a lot of other ways.
So I am still looking for a good job. I can't believe this has to be so difficult. Most places never give me a chance though. It's the recruiters that are the problem, because they aren't programmers looking to hire programmers. What ends up happening is they find someone that knows not a lot, but knows how to talk and brown-nose better than me. I wish to be interviewed by actual people that know what is going on. Not ones you can read about on TheDailyWTF. This is mostly the case when it comes to windows users. I laugh at windows. Because IT IS garbage. Ofcourse this is my personal opinion. I just prefer Linux. Not that I wouldn't write code on it or for it. Because it does get the job done, and in the end thats all that really matters. I'm sure my prayers will be answered though. I believe it with all my heart, brain and soul :)
I been running my computer business for a while now. It's not bad. Definitely beats working for someone else. That all depends on the conditions though. I love to work. It helps me deal.
A little while back I started another project. I have roughly 1000 bash aliases and functions now. It becomes very cumbersome to manage all those. So I created a little pyGTK application with quickly. I called it CourtesyFlush. It's on Launchpad. It scratches my itch. I added a bunch of code in there preparing for some new function in parsing the files and stuff like that. So look beyond that. I basically built it like junk. Because It's how I find out where to go with it. Once I figure out what features it requires I will rethink and OOP the code. I call it progressive building. Like climbing a ladder. As you climb up the ladder you progress up the ladder.
About the logo.

Yes, that is a toilet. Yes, that is python floating in the toilet. Yes, it looks like dung. Yes, It's funny to me, I find it amusing. I love python. It's an awesome language. I made the logo using InkScape (a opensource vector graphics application like Adobe Illustrator). Moving on.
I honestly barely ever use this application. Just once in a while. Mostly I just go with vim, nano, pico, cat or gedit.
Here are some of the current features this program has.
list functions and aliases and show source in a sourceview
display vte console to run aliases and functions
autorun and repeat running of aliases and functions up to 9999 times, no kidding(basically it just wraps your command in a for loop, no biggie. still saves even more time though)
and many more...
heres a screenshot(theres no guarantee this image will stay up)

Here are some features I still plan on adding at some point in time.
OliveGTK's gannotate
tilda's keybindings
commandlinefu in search
tabbed vte console
tabbed sourceview
and many more I can't remember atm...
This program is actually nothing really big. At least I don't think of it as a big deal. It just saves me some time at times.
If you like this program, let me know. If you find any bugs, let me know. If you want me to add more features, let me know. If you want to help, let me know. Anything else? let me know. Honestly, If you find bugs or something I expect you to try to fix it yourself. I may take a long while to fix it, depending on some life variables and such. If it pays though it'll get fixed 10 minutes ago. :) Like with anything else. Don't expect me to do any hand holding, unless it is your breast. haha, just kidding.
I like to know stuff, If you haven't figured it out yet. Knowledge is power, I thrive on that stuff. It's like food, only for my brain.
A lot of things in life are hit and miss. To make good stuff, you have to make a lot of garbage. Plus sometimes you may think something is so awesome that everyone needs or wants it, and the reality is that's not the case. Yet, sometimes you may do something as the spur of the moment and it'll get so much attention that it blows your mind. Anyway, I have nothing more to say now. Back to reading and learning more stuff.
English is not my primary/native language. Which means that you may get insulted. If you can get passed that though then more power to you. There's more important things to worry about than proper wording, pronunciation or the arrangement of words, IMHO. Some may say otherwise. Liba/Riba, same thing.
So I am still looking for a good job. I can't believe this has to be so difficult. Most places never give me a chance though. It's the recruiters that are the problem, because they aren't programmers looking to hire programmers. What ends up happening is they find someone that knows not a lot, but knows how to talk and brown-nose better than me. I wish to be interviewed by actual people that know what is going on. Not ones you can read about on TheDailyWTF. This is mostly the case when it comes to windows users. I laugh at windows. Because IT IS garbage. Ofcourse this is my personal opinion. I just prefer Linux. Not that I wouldn't write code on it or for it. Because it does get the job done, and in the end thats all that really matters. I'm sure my prayers will be answered though. I believe it with all my heart, brain and soul :)
I been running my computer business for a while now. It's not bad. Definitely beats working for someone else. That all depends on the conditions though. I love to work. It helps me deal.
A little while back I started another project. I have roughly 1000 bash aliases and functions now. It becomes very cumbersome to manage all those. So I created a little pyGTK application with quickly. I called it CourtesyFlush. It's on Launchpad. It scratches my itch. I added a bunch of code in there preparing for some new function in parsing the files and stuff like that. So look beyond that. I basically built it like junk. Because It's how I find out where to go with it. Once I figure out what features it requires I will rethink and OOP the code. I call it progressive building. Like climbing a ladder. As you climb up the ladder you progress up the ladder.
About the logo.

Yes, that is a toilet. Yes, that is python floating in the toilet. Yes, it looks like dung. Yes, It's funny to me, I find it amusing. I love python. It's an awesome language. I made the logo using InkScape (a opensource vector graphics application like Adobe Illustrator). Moving on.
I honestly barely ever use this application. Just once in a while. Mostly I just go with vim, nano, pico, cat or gedit.
Here are some of the current features this program has.
list functions and aliases and show source in a sourceview
display vte console to run aliases and functions
autorun and repeat running of aliases and functions up to 9999 times, no kidding(basically it just wraps your command in a for loop, no biggie. still saves even more time though)
and many more...
heres a screenshot(theres no guarantee this image will stay up)

Here are some features I still plan on adding at some point in time.
OliveGTK's gannotate
tilda's keybindings
commandlinefu in search
tabbed vte console
tabbed sourceview
and many more I can't remember atm...
This program is actually nothing really big. At least I don't think of it as a big deal. It just saves me some time at times.
If you like this program, let me know. If you find any bugs, let me know. If you want me to add more features, let me know. If you want to help, let me know. Anything else? let me know. Honestly, If you find bugs or something I expect you to try to fix it yourself. I may take a long while to fix it, depending on some life variables and such. If it pays though it'll get fixed 10 minutes ago. :) Like with anything else. Don't expect me to do any hand holding, unless it is your breast. haha, just kidding.
I like to know stuff, If you haven't figured it out yet. Knowledge is power, I thrive on that stuff. It's like food, only for my brain.
A lot of things in life are hit and miss. To make good stuff, you have to make a lot of garbage. Plus sometimes you may think something is so awesome that everyone needs or wants it, and the reality is that's not the case. Yet, sometimes you may do something as the spur of the moment and it'll get so much attention that it blows your mind. Anyway, I have nothing more to say now. Back to reading and learning more stuff.
English is not my primary/native language. Which means that you may get insulted. If you can get passed that though then more power to you. There's more important things to worry about than proper wording, pronunciation or the arrangement of words, IMHO. Some may say otherwise. Liba/Riba, same thing.
Tuesday, November 17, 2009
Codeigniter 1.7.2 and userauth 0.9.2t7
Been a long time since i wrote anything to this blog. Good thing for all you Codeigniter fans this quick post is about userauth. UserAuth is a simple ACL(Access Control List) Login for CI (CodeIgniter).
To complete a successful install of userauth version 0.9.2t7 just copy the files into your bare codeigniter install. It's safe to copy all files in all the folders in your application folder. Except for the config folder, all the files in this folder you have to merge with your install. You would only have to worry about this if ci version your using is very new and has new variables.
Once you merge all the files in the application/config folder you need to edit the file models/user_group_model.php
In the user_group_model you only need to replace all instances of "use_table" (without quotes) with "from" (also without quotes).
That's it. You should have a working install of ci userauth mini-app. This process should actually work with any version. You just have to merge the code and files. Enjoy.
To complete a successful install of userauth version 0.9.2t7 just copy the files into your bare codeigniter install. It's safe to copy all files in all the folders in your application folder. Except for the config folder, all the files in this folder you have to merge with your install. You would only have to worry about this if ci version your using is very new and has new variables.
Once you merge all the files in the application/config folder you need to edit the file models/user_group_model.php
In the user_group_model you only need to replace all instances of "use_table" (without quotes) with "from" (also without quotes).
That's it. You should have a working install of ci userauth mini-app. This process should actually work with any version. You just have to merge the code and files. Enjoy.
Sunday, March 15, 2009
python append all subdirectories to sys.path
This is my pather class. It appends/prepends the application subdirectories to sys.path
#!/usr/bin env python
#
# -*- coding: UTF-8 -*-
#
# PyNutButter BETA Version 0.1.0.1
#
# Copyright 2009 - Infinity and Beyond by Alex Goretoy, All Rights Reserved.
#
# Permission to use, copy, modify, and distribute this software and its
# documentation for any purpose and without fee is hereby granted,
# provided that the above copyright notice appear in all copies and that
# both that copyright notice and this permission notice appear in
# supporting documentation, and that the name of Vinay Sajip
# not be used in advertising or publicity pertaining to distribution
# of the software without specific, written prior permission.
# VINAY SAJIP DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
# ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
# VINAY SAJIP BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
# ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
# IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#
# SEE ALSO LICENSE FILE IN PROJECT ROOT DIRECTORY
#
__author__ = "Aleksandr Ilyich Goretoy"
__status__ = "beta" #production
__version__ = "0.1.0.1"
__date__ = "14 March 2009"
import os
import sys
class _pather(object):
def __init__(self,cwd="",send="append",depth=0,height=1):
"""
pwd - directory to get listing from
send - append or prepend to sys.path
depth - 0 is current dir, 1 is next level directory
height - root, dirs, files
"""
self.path=[]
self._path=[]
self.send=send
if cwd is not "":
self.set_paths(cwd,send,depth,height)
return None
def append(self,path):
for i in range(len(sys.path)):
try:
if str(path) == str(sys.path[i]):
if sys.path.index(path)>0:
del sys.path[i]
except(ValueError,IndexError):
pass
self._path=self.path
self.path=path
return sys.path.append(str(self.path))
def prepend(self,path):
for i in range(len(sys.path)):
if str(path) == str(sys.path[i]):
del sys.path[i]
self._path=self.path
self.path=path
return sys.path.prepend(str(self.path))
def set_path(self,value,prepend="",append=""):
self.pathstr="%s/%s/%s"%(prepend,value,append)
if self.send == "append":
self.append(self.pathstr)
else:
self.prepend(self.pathstr)
def set_paths(self,pwd,send="append",depth=0,height=1):
self.send=send
self.pathlist= list( ( (root,dirs,files) for root, dirs,files in os.walk(pwd) ) )[depth][height]
if self.send == "append":
list((self.append("%s/%s"%(pwd,x)) for x in self.pathlist if not x.startswith(".")))
else:
list((self.prepend("%s/%s"%(pwd,x)) for x in self.pathlist if not x.startswith(".")))
python append application working directories subdirectory to sys.path
This is a little script to show how to append the application working directories subdirectories when os.environ['PWD'] _not_ in application directory
doing only os.environ['PWD'], os.get_cwd() or os.path.dirname is _not_ enough and will cause errors in your application if a user opens it in different directory than where the script is
#!/usr/bin/env python
import os,sys
print __file__
print os.environ["PWD"]
s=os.environ["PWD"]+"/"+os.path.dirname(__file__)
sys.path.append(s+"/python_stdout_colors")
print sys.path
doing only os.environ['PWD'], os.get_cwd() or os.path.dirname is _not_ enough and will cause errors in your application if a user opens it in different directory than where the script is
Subscribe to:
Posts (Atom)