The offical website of Jason Charney and his services
FINALLY! SOME UPDATES! This website is being reconstructed. Some content will go away soon. If you want to see my new stuff, visit my github: https://github.com/jrcharney/.
I finally was at my wits end using GNU Screen on SSH, especially since on my computer, tmux is my terminal multiplexer of choice.
The collective knowledge of the internet lead me to a post on Trevor Suarez's website, blennd.com, where a post from last summer caught my attention on how to install tmux on a remote SSH account. Firstly, I need to check if my web host was cool with this. After finding on objections to the installation of this powerful light-weight program, the next thing to do was to figure out how to install it.
To my fortune, one of the commentors to Suarez's post named Craig Laparo, came up with a Bash script for installing tmux. Before I considered running this script, I checked to see if there were any updates to libevents or tmux. I applied the updated file paths to the script. Ran the script, based on mostly Laparo's script and ran into some issues.
Firstly, deleting the temp directory where the software packages were installed was a bad idea to include in the script. If there was an error log, that would also be deleted. So I commented that out after the first time when things didn't work.
Secondly, Suarez may have done right by exporting variables to the local environment. However, these variables reset or delete themselves on logout. Fortuantely, Laparo caught this and suggested storing the exports into a file. He suggested .bashrc but that was the wrong file to do it in. After figuring out what went wrong, it turns out .bash_profile is the correct file to place the exports in AND where one can also store their alias commands. The former has been corrected. The latter, I intend on doing more of in the future.
In a nutshell, this is what the file looks like. (You might need to scroll past the header)
There are still a few tweaks I'd like this script to do like what todo with upgrade and whether or not the tee command should have been used in the end since the first set of exports are used for the current session and the second set is meant for future sessions.
Other than that, I'm considering applying the same process to Shell-FM and IRSSI even though my webhost has IRSSI. Shell-FM needs it's own IRSSI script. It's on the Todo list now.
Hopefully by the end of the week, I will be able to let readers read posts individually. It shouldn't be hard to do.
UPDATE: I made some changes to the script! Exports now happen at the begining rather than the end. So be sure to edit them according to your systems needs!
Since I can't really call my project "jCanvas" or "jDraw", I've decided to call this project that I am working on that makes using HTML5 Canvas with jQuery much more intuitive.
Thus the name of this project will be called Jill. Why bother making it "jIll" since "Jill" seems so much more idea. Jill is short for jQuery Illustrator and it has no relationship to Adobe Illustrator.
Jill works with jQuery to make using HTML5 Canvas easy to use. For now, Jill is designed to draw elements. Eventually more interactivity (events) will work there way into the programming part. For now, I've used Jill to illustrate a couple of examples from O'Reilly's Canvas Pocket Reference by David Flanagan.
Using Jill should make drawing Canvas elements as easy as using jQuery. For instance, I've read almost ever book that is on the market on the subject of how to use the HTML5 element. Some used a library like jCanvas, Modernizer, or some other library where they implement their own style of using JavaScript. This is not how one learns JavaScript nor how to use HTML5 Canvas. Most of these libraries don't even use jQuery to create a program that works on all platforms. Events in JavaScript are probably the most frustrating of these examples because everyone has their own style of handling events, especially for different browsers. Think of it as learning Spanish with the vernacular used in Spain (which is used in most Spanish Dictionaries and probably should be called "The Queen's Spanish" as they still have a monarchy) but not understanding the dialect or slang used in Mexico or the South American countries.
Just as jQuery has made using JavaScript easy to use, my plan is to do the same for HTML5 Canvas and possibly JavaScript events (interactivity and animation especially) used with Canvas.
Using Jill should also allow for multiple instances of Canvas contexts to be used without having to think of a new name for the context feature that can only be used once per Canvas element. Here we can use the same one but as a variable for a drawing function. It is my intention in the near future to apply Jill's functionality to previous blog entries that used canvas elements so that when I finally get the tagging system set up, the page that shows multiple canvases doesn't return an error. This was sort of a mental block for me for the past few months. But because Jill works, I can now proceed setting up such a system. (Also, have you noticed the Todo widget is back up. I'm still working out a few issues, but at least my list has bullets again and isn't some messy blob of text.)
One of the first issues I ran into when using jQuery to create a Canvas element was that the Canvas width and height attributes were misinterpreted as CSS attributes. Fortunately, jQuery offers a solution to fix that.
At the moment, this appear to be the heart of Jill: The makeCanvas() function
makeCanvas() uses a callback function that fetches a drawing function, like drawSquare(ctx), and substitutes func with drawSquare. Eventually, I'll extend this for arguments. But for now, I like how this works.
So now that I've figured out how to use jQuery to create and use Canvas elements, there will likely be more examples in the near future. It's about time!
This year, the big trend in music is a genre called dubstep. Like it or hate it, it has inspired a lot of musicians, and even more non musicians, to learn how to use their computers to produce music.
Despite knowing a couple of tunes on the piano, my small hands sort of make it difficult for me to do chords on the piano. (Maybe I need to find a smaller piano?)
Regardless, today I though I'd take a few hours to take some advice from YouTube on how to create a song using music software. As usual, the amount of software out there for Windows and Mac users out numbers what Linux users have. But what we lack in quantity, we make up with quality. The music I made was made with LMMS
At first, I though I was following one of the piano tutorials correctly to create some Benny Benassi song that was remixed by Skrillex. Turns out that after I though I was baking a cake, I ended out with a roasted turkey dinner instead. (That's a good thing!) In retrospect, I'm glad I made those mistakes. I'm not a fan of Benny Benassi to begin with and the orignial song was so soft. The song I made was more upbeat, probably because I used so many 1/8th notes. At any rate, these mistakes were so worth it.
Now keep in mind, this song I made was just to demo LMMS's capabilities to produce music. I didn't ad any special effects or make any edits. And because I'm only using a tiny netbook to do it all, don't count on me making any 10 minute songs. I'm considering using this song for a few demonstrations in the future than involve HTML5 Audio and Video elements. Here comes one right now.
Of course, if .ogg isn't your format, you can always use ffmpeg and convert it to .mp3. This is a definite must if you want to play the song in mpeg321 or MOC. (Note the command for the latter is mocp due to some other software.)
I love using the command line music players, especially since I like using programs like tmux, vim and irssi. I'm of the opinion, the more command line stuff you use, the more you can remember and stay focused with coding projects.
MOC (Music on Console) is pretty cool. But the default theme is a big blue nightmare. Forunately, you can change the theme and the programmers of MOC realized for a lot of folks, blue just isn't their color. The MOC themes are located in /usr/share/moc/themes/. You will likely need to create a config file. Using vim, create the file ~/.mog/config and write the following line.
Then save the file and quit.
You need to change the permissions of the new file. If you forget to change the permissions on the config file you will get a fatal error and MOC won't run.
There is one other hack I'd like to share before I wrap this post up: Using Shell-FM to play Last.FM. Basically, all you need is a Last.FM account, Shell-FM, a config file (which I will show shortly), and this shell script that I whipped up. Install shell-fm. Download my script. Create ~/.shell-fm.rc
Save and quit. Read through my shell script for a few other instructions. Then run my program: ~/lastfm. This should start playing your radio station. For instruction using shell-fm type ?.
Finally! That's everything! Enjoy your Memorial Day!
One last thing before I close this post. Happy 101st Birthday to Vincent Price. If Jody Price is reading this, you still owe me a pair of egg feet!
It is around 2 AM when I am writing this but through some marvelous intervention and some persistent help, I handled three separate crisis today involving my computer.
The trouble started around 3:20PM when I figured I had a few minutes this afternoon to sort a few files in my Downloads directory. While I was the 2000 or so images and files in the directory, Ubuntu Unity pretty much choked. The mouse could still move, but everything else was frozen.
Crisis 1: The Deep Freeze
Linux has a very good record of never crashing. The applications that use Linux (especially Ubuntu's) is another story.
When in the course of events your computer freezes, DON'T PANIC! As those words of Douglas Adams hold true, your first step is to switch to another pseudoterminal, or pts. The current pts you are using is likely pts/7. This is where X or Gnome or KDE usually sets up shop. You switch ptses using CTRL+ALT+1 (you could also use CTRL+ALT+2 or CTRL+ALT+3 or etc.). You then login with your user name and password.
The next step is you need to find the troublemakers. Ideally, using ps -AHF would list all the processes that are going on the computer and with detail. To a lesser detail, you could use ps -AH. Either way, this list will spout off a long list of processes neatly structured thanks to the -H option but more complicated no-thanks to the -F option should you use it.
A couple of other general hacks for any Linux/UNIX/BSD newbie would be to use a pipe--that is, a chained command--to view things as a scrollable list (ps -AHF | less -eFMXR) or to look for the things you are looking for by using a pattern search (i.e. ps -AHF | grep "chromium-browser"). Knowing these is also helpful for other commands.
Anyway, back to the trouble makers. Zombies (or rather Zombie Processes) are a good place to start. If you use -F in the ps command, you will see a column marked S for "status". Anything that is marked R is running and S for sleeping is normal. But if you see Z, that is a sign of a zombie process. You can start by killing those using sudo kill pid where pid is the process ID number that corresponds with the PID column. But be warned! If their is a process you are trying to save, killing the zombies may not be the best of ideas. (See Crisis #2 later.)
The next ones you'll want to 86 would be the heavy users. Web Browsers have a nasty habit of this. Often the web browser will have a list of parallel processes going. To kill all of those at the same time use sudo killall -9 chromium-browser for example. You'll have to restart the browser when you get back to the regular pts, but it's much easier than opening the GUI program of the Memory manager or something like that.
Woo! Crisis solved right? Well, for most people yes. However, I my case, no. You see, when I typed in CTRL+ALT+7 to get back to the regular pts, it was about 4:00 PM. The clock on the terminal was still stuck at 3:20 PM.
Crisis 2: The Rescue Mission
Often times, we are tempted to reach for the power button to start things over. But, that would be foolish if you left things open, especially things that you didn't save yet in vim on whatever console emulator you are using.
Someone has finally fixe this problem. A young chap by the name of Nelson Elhage created a program for moving running processes to another pts called reptyr.
Now I know some of the more experienced programmers reading this are like "You could also use injcode or neercs" but we're not using those applications in this post.
In order for this important hack to work, you will also need a screen multiplexer program like screen or--my preference--tmux. Either program will do, but the latter has colors and can be run inside another instance of the program. Knowing both of these program is a must for anyone who wants to use these programs when there isn't a crisis going on. I'd love to explain how they work, but that is for another time.
If you don't have any of these programs installed, consider sudo apt-get install reptyr tmux or whatever else floats your boat (i.e. screen, injcode and/or neercs for the last two arguments).
Let's do a ps -AHF | less -eFMXR and look for the program we want retrieve. In the TTY column, lets say the program tmux is holding like five different windows that have bash going and within them maybe a few vim sessions.
In a normal situation, you could CTRL+Z and disown program from the current terminal. However, these programs that are running are not in the current terminal. So you will want to temporarily hack the kernel. That's right! I said the kernel. That thing you really shouldn't touch unless you are developing upon it or if there is an emergency.
The guy who developed this program had though offered the adivce of using sudo echo 0 > /proc/sys/kernel/yama/ptrace_scope would be a good work around for why distributions like Ubuntu won't let you move the set of processes. Firstly, the reason you can't change this is for security reasons. Making this permissible will open a hole in your kernel that could be exploited by some nay-do-well who could inject code and hijack the computer. (Hence the name of that one program, injcode.) But since this is an emergency and a problem with your own computer, you'll want to set things back to normal later when you are done. At any rate, the proper description of this issue will be addressed in Crisis #3
So you've identified the process you want to move. You've turned off the ptrace_scope for the moment. Now it's time to move it. reptyr -s pid will change the pts of that process, which we'll say was at pts/0 but is now at pts/12 or some other place.
Many of the resolutions I've found explained how to bring these processes back to life with screen using screen -ls followed by screen -x pid where the pid is the Process ID of the rescued screen, ssh, bash, vim, or whatever. (Notice, I didn't say tmux because putting a tmux inside a screen doesn't work. Another advantage to using tmux over screen.)
How I fixed it took a little bit of forethought. I first opened tmux using, well, tmux. I then turned off ptrace_scope temporarily, then I ran reptyr -s the_pid_I_wanted. I used tmux's console feature to run the following commands: CTRL+B then c for a new window; ps -AHF|less -eFMXR to look up the PIDs of the old parents that didn't have a pts (? was in the TTY column.); Killed those old processes.); then CTRL+B then :choose-session -t the_window_number_I_was_in then picked the set of windows that were not attached that I wanted.
If that was too complicated, I have decided to write a more terse explaination after this next sub-section.
So you've identified the process you want to move. You've turned off the ptrace_scope for the moment. Now it's time to move it. reptyr -s pid will change the pts of that process, which we'll say was at pts/0 but is now at pts/12 or some other place.
Crisis 3: The tee Party
As I stated in the previous section, sudo echo 0 > /proc/sys/kernel/yama/ptrace_scope did not work. I tried everything I could think of. I tried sudo sed -i "s/0/1/" and I tried using sudo vim. But the kernel would not allow this change, which would have reset itself on restart of the computer if by chance I didn't reset it later. (There's a more permanent way to set it, but I would not advise doing it.)
The work around used the tee command. Instead of pushing data in to a file through a standard output method (>), I used a pipe instead.
echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope
A recap summary
That was a long explaination so let's recap.
CTRL+ALT+1 # Switch to a blank terminal and log in.
$ ps -AH | less # Look up the PID and TTY (pts) of the process you want to save and the PIDs you want to kill.
$ tmux # Open the multiplexer program
$ echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope # Temporarily disable ptrace_scope in the kernel.
$ reptyr -s save_me_pid # Have reptyr move the process you want to save. (This PID's child processes will also be saved if there are any.)
CTRL+B c # Create a new window in tmux
$ sudo kill kill_bad_pids # Kill the old PIDs that previously manipulated the pid you want to save.
CTRL+B :choose-session -t this_window_number # Envoke a menu to choose the detached set of windows the saved process represents. (Arrows move up and down the list. Return selects. Esc cancels.)
$ echo 1 | sudo tee /proc/sys/kernel/yama/ptrace_scope # Re-enable ptrace_scope for security.
And you are back in business! Or at least get a chance to save stuff before rebooting the computer.
The Lifelines
One of the reasons this took solong was because an old piece of software called Privoxy prevented me from using lynx from looking up a solution. Privoxy sort of gummed up everything by setting a proxy to route Lynx to 127.0.0.1:8118 because there was an environment variable set. If this is a problem for you like it was for me, consider unset http_proxy if by chance http_proxy shows up when you env | grep "http_proxy". At any rate, Lynx is a must have piece of software when you can't use Chrome, Firefox, or Opera.
Secondly, it helps to seek outside help. IRC is the place to do that if you are a geek. The best IRC software hands down is IRSSI. I think I may have mentioned that in the past, but it's worth repeating. ##linux is more helpful than #bash in case you are wondering.
Well, that's it. I stood up all night to write this piece. But before I go I want to mention, I'm on Google+ now. So in case LinkedIn wasn't enough to snoop around on what I do when I'm not working on stuff, there you go.. Hopefully, the rest of the day will be better.
Last post, I stated that I would get the ToDo List to take an XML file and use jQuery to convert it into part of the page's HTML. So far, it hasn't panned out like I've wanted.
The good news is, If you want to see the XML file (while I have the permission set to let you) as an XML file processed with XSLT and defined with a DTD, you can take a look at what I want the results of my jQuery to look like when I finally get it to work. I ended out created an XSLT file hoping that if the jQuery replaceWith elements weren't going to work, let XML handle it. Turns out it doesn't work like that.
I have used XML before and used XSLT to process the XML data to look like a web page. This was slightly before I figured out how PHP works and ultimately, developed as a precursor to my old GCC tutorial which I wrote back in college. (I had a CSS file for it, but it's probably not it the same directory at the moment. It should be fixed soon.)
I'm verily sure that I will have this solved very soon. Rest assure, things are working, just not in the way I wanted.