MoshPit.js - Controlled chaos for your views, states, and screen sizes.

izzy's playlists!
I'd rather be in outer space 🛸

PR's Tumblrdome

if i look back, i am lost

roma★

⁂
h
d e v o n
Cosmic Funnies
Misplaced Lens Cap
"I'm Dorothy Gale from Kansas"

❣ Chile in a Photography ❣

blake kathryn
occasionally subtle

Andulka
Show & Tell
we're not kids anymore.
hello vonnie

ellievsbear
Sade Olutola
seen from United States
seen from United States
seen from United States

seen from United States
seen from Poland
seen from United States

seen from Türkiye
seen from United States
seen from United States
seen from United States
seen from United States

seen from United States
seen from France
seen from United States
seen from United States
seen from United States
seen from United States
seen from Poland

seen from United Kingdom
seen from United States
@chadillac-blog
MoshPit.js - Controlled chaos for your views, states, and screen sizes.
[SOLVED] Arch Linux : pacman : ERROR -> invalid or corrupted package (PGP signature)
Ran into this and couldn't upgrade. After a bit of Googling around and looking at thread after thread after thread of discussion about flags, config files, sigLevels, etc. I found a 1 line fix that didn't required any of the aforementioned "maybes".
# pacman-key --refresh-keys
fixed.
The issue is one of the authors of a package you have installed has since updated their PGP signature they use to sign and verify their packages. Your local key for said package is unaware of this and pacman thinks you're being duped by an untrustworthy package. This fix just runs through your keychain and requests the most recent keys for all of the packages you care about.
Once the key fetching is done running your upgrade should go off without a hitch. If it doesn't... talk to my friend Google, he'll know more than I.
"TypeError: Cannot call method 'log' of undefined" meet smarter_console.js
Web developer tools have come a long way over the past 10 years, I remember writing custom logging and debugging classes that used pop-up windows and forin loops to inspect objects. We now have a great suite of tools in many browsers and we utilize them often. However some issues still persist, even with these tools.
Old browsers don't support them, meaning your console.log call with generate the fatal error used in the title of this post. This means you'll have to either wrap your interaction calls in a if statement making sure they exist, or you'll have to remove or comment them in production code. If you remove them in production code, you can't use them in production code. Sometimes it's handy to have them in a production environment the downside obviously being all of your production .log calls dumping a lot of data to the browser console 100% of the time when in reality you need it less that 1% of the time.
Facing this little gotcha I decided to write a smarter console wrapper/shim for dealing with the aforementioned cases and adding support (not great support, but support) for older browsers. Also adding the ability to suppress calls in a production environment and to enable them at will should you need them.
You can find out more about this lib and it's use on it's github page.
https://github.com/chadillac/smarter_js_console
ThinkPad : Linux : Scrolling after reboot
After a reboot my gpointing-device-settings would never stick for middle mouse button emulation and scrolling. After looking around this seems to be a bug with the gpointing-device-settings application, but buried in the bug report comments a user has found a fix/hack.
This workaround seems to fix the issue on my X220 and makes the scrolling persistent even after reboot.
In the file /usr/share/X11/xorg.conf.d/20-thinkpad.conf (if it doesn't exist, create it.) put the following contents:
Section "InputClass" Identifier "Trackpoint Wheel Emulation" MatchProduct "TrackPoint" MatchDevicePath "/dev/input/event*" Driver "evdev" Option "EmulateWheel" "true" Option "EmulateWheelButton" "2" Option "Emulate3Buttons" "false" Option "XAxisMapping" "6 7" Option "YAxisMapping" "4 5" EndSection
reference: https://bugs.launchpad.net/ubuntu/+source/gpointing-device-settings/+bug/489830/comments/30 (thanks Tommi!!!)
easy ejabberd clustering (multi-master, fault tolerant, failover)
First and foremost, for general cluster configuration steps see this post:
http://chad.ill.ac/post/35967173942/easy-ejabberd-clustering-guide-mnesia-mysql
Once you have a functioning cluster using those steps and you want to add multi-master support for better failover and fault tolerance of your ejabberd cluster come back here and read this post.
Why?
After getting our small cluster up and running we started testing cluster failure handling. We quickly discovered that no matter how many slaves you had deployed as soon as your master node experienced issues the entire cluster became inoperable. To make things worse fixing the master didn't fix the cluster, you would have to completely cycle the ejabberd instances of every slave to get them working properly again, or input the mnesia commands to make master communicate with the slaves. This is messy, it's stupid, but most importantly it pretty much kills the benefit of having a cluster in the first place. If you have a single point of failure that is capable of crippling an entire cluster... well, it's going to bite you in the ass.
What to do about it:
After about a day of piecing together old mailing lists, stackoverflow posts and articles on mnesia replication, several forums talking about modifying ejabberdctl, and tinkering we were able to finally track down a multimaster cluster that could handle any of the nodes dying without bringing down the entire cluster. The fix doesn't so much involve ejabberd as it involves just using proper erlang/mnesia replication and removing dependencies on remote tables for underlying data stores used for route and session management by ejabberd.
I've updated the plugin to support this functionality so deploying failover masters is easier. We're only running a small cluster of 3 nodes so we've deployed all 3 nodes as masters, this allows us to kill/cycle any of them without any special procedures needed to leave/join a cluster after failure/reboot/etc. That being said I cannot comment on the performance issues one might experience running a masters only cluster at a massive scale so using a handful of masters with regular non-copy/remote slaves might be a better architecture if you're dealing with large clusters, but I don't know, so I can't advise one way or the other at this point. You could also run additional masters with their own slaves as a failover cluster.
Plugin:
https://github.com/chadillac/ejabberd-easy_cluster/blob/master/easy_cluster.erl
Usage:
To use the plugin to create a second, third, Nth master node is super simple.
note: this requires doing a complete mnesia db copy over the network, this might hang for a bit if your databases are large or network latency is high (or both)
easy_cluster:join_as_master('ejabberd@any_master_node.domain.com').
That's it, you're done!
I hope this tool helps you out and saves you some time.
Handlebars (Handlebarsjs) + Precompiled Templates = Error: has no method 'merge'
After a server move we started encountering errors after precompiling our handlebars templates. Googling didn't help much but after playing around with various versions of the compiler and runtime (both of ours were old on the older server) it seems like using runtime 1.0.0 with the older 1.0.11 version of the handlebars CLI compiler works.
Installing older version of compiler via NPM:
$ npm install [email protected] -g
I hope you didn't waste too much time and found this solution quicker than I was able to.
Strophe.js -> disconnect on page unload
UPDATE: I deleted my outdated repos, Strophe.js has been updated to support this out of the box now. The below code still shows how to properly apply this functionality and has been updated to support the default Strophe lib.
There are a few discussions online regarding this procedure and most of them are misleading, incorrect, or wrong. To reliably kill a jabber connection using Strophe.js you'll need to force a synchronous (blocking) connection and run through the disconnect steps. A couple important things to note here that most discussions seem to skip over. Strophe doesn't natively support synchronous connections. Another thing I see is people saying you should set the sync flag before calling the flush method. My testing basically came to the conclusion we should flush the connection with an async call, but should switch to a synchro call immediately before issuing the disconnect. If you enable synchro before running flush your browser session will become unresponsive... for a while.
Step 1: patch Strophe to support synchronous connections
github diff
Step 2: setup your onunload handler
jQuery
$(window).bind('unload', function(){ StropheConnection.flush(); StropheConnection.options.sync = true; StropheConnection.disconnect(); });
Vanilla JS
window.onunload = function() { StropheConnection.flush(); StropheConnection.options.sync = true; StropheConnection.disconnect(); };
Batch file renaming, extension changing (bash, find, & awk)
I had a ton of files on a remote server I needed to change the extension on. Using find -exec didn't seem like the right solution after a couple minutes of Googling so I decided to use my favorite trick of bash pipes, awk, and sh. Below I'll show you the one-liner I used and then we'll break it down and explain what we're doing.
The Command:
find . -name '*.html' | awk '{printf "mv "$0; sub(/html/,"php"); print " "$0}' | sh
The Breakdown:
We'll start by breaking up the command into it's individual pieces
find . -name '*.html'
First we find all of the files matching our search, in this example we're looking for all files in our current directory (including sub-directories, find is recursive by default)
awk '{printf "mv "$0; sub(/html/,"php"); print " "$0;}'
Here we take the input coming out of find via a pipe. We'll essentially use that output to write a shell command on the fly. Since this command looks kind of messy we'll break it down piece by piece
1: awk '{ 2: printf "mv "$0; 3: sub(/html/,"php"); 4: print " "$0; 5: }'
line 1: Call awk and begin our program with
'{
line 2: Output the first part of our "on the fly" shell command (note we use printf to suppress the default newline included in print)
mv 1.html
line 3: Modify the input
1.html ==> 1.php
line 4: Output the now modified input of our "on the fly" shell command (and here we use print, because that default newline is wanted)
1.php
line 5: Close our awk program
}'
let's look at some example input and output
$ ls 10.html 1.html 2.html 3.html 4.html 5.html 6.html 7.html 8.html 9.html $ find . -name '*.html' | awk '{printf "mv "$0; sub(/html/,"php"); printf " "$0"\n"}' mv 10.html 10.php mv 1.html 1.php mv 2.html 2.php mv 3.html 3.php mv 4.html 4.php mv 5.html 5.php mv 6.html 6.php mv 7.html 7.php mv 8.html 8.php mv 9.html 9.php
sh
Now that we have our commands being written by awk all we have to do is redirect their output into sh for execution.
and that's it, you're done. See that wasn't so bad. It's worth noting this technique can use a standard ls if you're doing a blanket rename. It's also worth noting this technique can be expanded even further to allow all types of renaming/batching logic. I've used a technique much like this for doing batch video conversion, log renaming, etc.
easy ejabberd clustering guide (mnesia, mysql, & postgres)
Ejabberd is a great little XMPP server, however it's documentation makes me want to rip my fucking face off. I have just spent way to long getting things configured (this is partly due to mysql5 support and 3rd party modules, dual NIC machines, public dns records... clustering issues were just icing on the cake) and I'm going to (hopefully) make your life a little easier. To get things working properly I pieced together multiple tutorials and official documentation... which seems absurd considering the popularity of the ejabberd. So below are the nitty gritty details and a helper module I wrote... because inputing mnesia commands into a debug shell for multiple slave node is... retarded.
before we begin, I want to point out that if you're using mysql or postgres for authentication, offline messaging, etc. it doesn't really matter to ejabberd for clustering purposes, although it is important when joining the cluster (which the official documentation seems to forget).
first things first, let's configure our master node
(we're assuming at this point you've installed ejabberd from source without a prefix, have it properly configured, and can successfully connect and message using it)
1: shut down your "master node"
ejabberdctl stop
2: edit ejabberdctl.cfg (/etc/ejabberd/ejabberctl.cfg)
2.1: change node name:
ERLANG_NODE=ejabberd@'master.domain.com'
2.2: change ip we listen on: (get this from ifconfig)
note: look closely, that's a tuple, don't use .'s use ,'s
INET_DIST_INTERFACE={192,168,10,100}
3: clear your ejabberd mnesia tables after hostname change
note: hostname changes are a pain, it's easier to just let ejabberd rebuild the mnesia db's at startup.
rm /var/lib/ejabberd/*
4: add hostname to /etc/hosts using address and hostname from confg
192.168.10.100 master.domain.com
5: start master node, and make sure it's running
ejabberdctl start
ejabberdctl status
now we'll need to configure our slaves
(once again we're assuming the server is properly installed and functional as a stand alone server)
1: if the server is running, stop it.
ejabberdctl stop
2: update ejabberctl.cfg (/etc/ejabberd/ejabberdctl.cfg
2.1: change node name:
ERLANG_NODE=ejabberd@'slave1.domain.com'
2.2: change ip we listen on: (get this from ifconfig)
note: look closely, that's a tuple, don't use .'s use ,'s
INET_DIST_INTERFACE={192,168,10,150}
3: clear your ejabberd mnesia tables after hostname change
note: hostname changes are a pain, it's easier to just let ejabberd rebuild the mnesia db's at startup.
rm /var/lib/ejabberd/*
4: copy .erlang.cookie from "master node" (/var/lib/ejabberd/.erlang.cookie)
note: this is the unique cookie from [email protected], not the one already residing on slave1
5: add hostnames to /etc/hosts using address and hostname from confg
192.168.10.100 master.domain.com 192.168.10.150 slave1.domain.com
6: create and compile easy_cluster module
6.1: go to server binaries folder
cd /lib/ejabberd/ebin/
6.2: create empty module file
touch easy_cluster.erl
6.3: put the following contents in easy_cluster.erl and save the file
https://github.com/chadillac/ejabberd-easy_cluster/blob/master/easy_cluster.erl
6.4: compile easy_cluster.erl
erlc easy_cluster.erl
6.5: confirm compilation succeeded
note: you should see easy_cluster.beam in the directory if compilation was successful
ls | grep easy_cluster.beam
7: start the slave node & confirm it's running
ejabberdctl start
ejabberdctl status
8: drop into a debugging session on the live server
note: you'll see a warning message, just hit enter to continue
ejabberdctl debug
note: if you successfully drop a debug console, your prompt will resemble this
Erlang (BEAM) emulator version 5.6.5 [source] [64-bit] [smp:4] [async-threads:0] [hipe] [kernel-poll:true] Eshell V5.6.5 (abort with ^G) ([email protected])1>
9: test to see if we can connect to the node
note: at the end of each line we put a . this tells erlang to process our command
easy_cluster:test_node('[email protected]').
if "server is reachable" we can continue, if it's not, make sure you did ALL of the steps above.
10: join the cluster
easy_cluster:join('[email protected]').
11: suspend your debug session by hitting Ctrl+c Ctrl+c
12: you're done, go drink a beer, you probably need it.
12.04 - Ubuntu/Linux Audio Skipping/Stuttering
I recently built a new machine for work and was having a lot of issues with audio (on linux, what a shock ;)). I'd read up on some different fixes and none of them seemed to fix the issues I was having with my system. After about a week of woes and a lack of music I decided to open up the box and swap the audio cable from HD to AC97 just to see if it might fix the issue. Low and behold audio plays fine without issue using the older standard. I don't reap the benefits of HD audio, but not being an audiophile and working with middle of the road headphones I can't tell a difference anyways.
So just a heads up, if software can't fix your skipping audio, maybe give your hardware a try.
Linux simple h264 batch conversion
You'll need HandBrakeCLI (http://handbrake.fr/downloads2.php) and a terminal. To convert a video (the easiest way possible, thanks to HandBrake mind you, ffmpeg was giving me a lot of issues) is really simple, but depending on your machine, the quality, the size, etc. it can take a good bit of resources and a good bit of time to complete one of these encodings. If you're not keen to sitting around watching progress counters and ETAs there will surely be down time between encoding tasks as you'll have to manually keep an eye on them. Using some common *nix tools we can make this automated and easy to use.
Basic HandBrakeCLI encoding:
HandBrakeCLI -Z Universal -i infile.avi -o outfile.mp4
The above will take a standard avi format video and convert it to an h264 format video, simple.
Batch Conversion:
ls *.avi | awk '{print "HandBrakeCLI -Z Universal -i \x22"$0"\x22 -o \x22"$0".mp4\x22"}' | sh
The above will (assuming you're in a directory with several .avi files) will go over each file, build the appropriate conversion command for HandBrakeCLI and then pipe that into sh to execute the command. I've been doing mass conversions for web streaming purposes using this technique, so far I've converted over 600 individual videos and still going strong.
"If you can get Nyan Cat into the servers MOTD you're more than welcome to do so..."
CHALLENGE ACCEPTED
Booting OS X with Grub2
I installed Ubuntu on a Mac Mini at work and needed to get back into OS X for some testing. The default configured Grub entries wouldn't load for OS X (hd0, part0). After looking over the net and digging through lines and lines of Grub conf I found a little blurb from another user saying they'd tried this and it worked... so if you're beating yourself up over OS X and Grub2 give this a try and see if it works... it did for me.
open up your Grub2 conf file, which in Ubuntu is located at
/boot/grub/grub.cfg
Then at the bottom of the menu entries I added:
menuentry "Mac OS X (Custom/Bootable)" --class osx --class darwin --class os { set root=(hd0,0) exit }
This entry gets me booted into rEFIt at which point I can properly boot into OS X Lion without issues. From this point forward the machine will default into rEFIt until you choose to boot into Linux again... which will push you back into Grub2 for future boots.
"If it's stupid but it works, it isn't stupid."
Note: I'd already installed and had rEFIt running from the previous Ubuntu install
Bash'isms (SVN+Awk+Grep+Cut+Bash one liners)
A couple bash 1 liners I threw together recently that I've found to come in very handy so I thought I'd share.
The back story is simple, yearly reviews, talk about what you've done, yadda yadda yadda. Well, I don't remember honestly. I've done A LOT. That's not going to fly in a serious meeting with "The Bobs". So I needed a way to look over my years work, as a refresher of little and big projects alike. No problem SVN to the rescue... but our SVN has a lot of developers, and several commits per day of new features, bug fixes, tweaks, etc. After consulting the SVN docs I was pretty shocked to find no way to pull logs based on the user submitting said changes... one would expect something along the lines of:
svn log -uchad
And one would be wrong in assuming such a feature exists. Some Google time turned up convoluted and down right ugly solutions. I decided to have a go at it with my bash-fu... for practice and profit. Below is an easy way using a couple common *nix tools to get the info you want fast and easy. In the following examples data you'll need to replace will be wrapped in %'s with example data in []'s (e.g. %username[chad]%)
Get all svn commits for a given username:
svn log | grep '| %username[chad]%' | cut -d' ' -f1 | awk '{print "svn log -"$1}' | bash
Get all svn commits for a given username in a year/month/day:
svn log | grep %date[YYYY-MM-DD]% | grep '| %username[chad]%' | cut -d' ' -f1 | awk '{print "svn log -"$1}' | bash
Get all modified files for a users commited for a day/week/etc.:
svn log | grep %date[YYYY-MM-DD]% | grep '| %username%' | cut -d' ' -f1 | awk '{print "svn log -v -"$1}' | bash | grep %files['/trunk']%
GrooveShark App (kind of) [Linux, Chrome]
I love GrooveShark, I love them so much that I looked for a stand alone app without much luck. I usually just ran it in a background Chrome instance but I just wanted to be able to click a button and have all my Groovy goodness without tabs, or address bars, etc.
It took about 10 minutes, but here it is, super simple.
Step 1: Install Google Chrome
(http://www.google.com/chrome/)
Step 2: Setup launcher with the -app flag
/path/to/google-chrome -app=http://grooveshark.com
example: /opt/google/chrome/google-chrome -app=http://grooveshark.com
This flag will cause Chrome to launch without common browser elements like the address bar, buttons, bars, etc.
Optional Steps: (for great justice)
Pick an icon for your launcher
Nexus S + MIUI + Netflix = Working
You'll need root, and you'll need a 2.3+ ROM installed.
In
/system/build.prop
You'll have to edit the lines.
ro.product.model=[model_name_here]
...
ro.product.manufacturer=unknow
To
ro.product.model=Nexus S
...
ro.product.manufacturer=samsung
Reboot the phone and install the Netflix app from the market or install the .apk manually from your sdcard.
For navigating to / and editing build.prop I suggest using ES File Explorer as it supports root, navigating to /system/ and writing to the file all in a single app.
Note: For safety sake you might want to copy an unedited version of build.prop to your sdcard (/mnt/sdcard/) for safe keeping should you need to revert back to the old file easily.
Protip: If you're running a rooted device with a 2.3 ROM using these flags on your phone will make the Netflix app usable.
Ubuntu / Debian : List software from repository
This will list packages coming from a specific repository
grep <repository_name> /var/lib/apt/lists/* | grep tar | cut -d' ' -f4 | sort -u
Example
$ grep backbox /var/lib/apt/lists/* | grep tar | cut -d' ' -f4 | sort -u
aircrack-ng_1.1-1backbox1.debian.tar.gz autotools-dev_20100122.1backbox1.tar.gz backbox-about_1.2.tar.gz backbox-artwork_1.6.tar.gz ...