TinyURL widget - shorten your URL's for free!

Enter a long URL to make tiny:

Friday, July 29, 2016

Why I hate a majority of stackoverflow participants

If you want to see an example of why lonely introverted Tech workers can't be trusted to work effectively with others.



http://stackoverflow.com/questions/38593588/reading-a-value-with-a-timer-in-c/38595314#38595314

Wherein I try to help the person asking a question. And rather than helping me help that person, I get assaulted by a moron lacking any empathy spouting format rules in the mode of rude. Notice Inspectable never once did any actual work!

This is the kind of thing that makes people avoid these  help sites, people feel stupid asking questions or answering them, and then they get some rude moron making the situation worse through bad manners and unsympathetic actions.

I post on many stack exchange sites, go to the English or Buddhist stacks and you will find polite people trying to exchange and learn, and most of all consider the ideas on display. They do not act the same as IT workers that troll stack overflow. I know there are a few good ones.  I have worked with people that helped me. But they are in the minority, the angry ones that do no work seem to take the game rules to extreme for personal reasons outside helping people.

I wonder if stack overflow will survive the decade.

So this is a major reason why I post my own blog solutions, because some little shit can't stroll along and squash what I wrote without even trying the solutions.

Tuesday, July 26, 2016

Septic Pump Maintenance


A few days ago, we had a powerful hailstorm, the worst since 2006/2005 when the entire house was pummeled by hail the size of softballs.

This time the hail was the size of fastballs





It just so happened that we had requested a septic pump truck to empty our septic system two days before the storm.  The guy came and emptied it, and then when I was paying for it he said the water level had been really high, that the pump might not been working. 

So I will relay all the information I have learned as I recount how I fixed my septic system.  It was hard won information from trial and error, from fixing it in -40C when tampon strings burned out the pump motor,  what I changed after fixing it 4 times in 13 years and how to make it easier and faster to fix.


I live in a cold climate, it can get as low as -55C with wind chill.  The first recommended fix, if your system was installed by an amateur, is to make a fortified manhole instead of the flimsy cheap stuff a "professional" would install.  The system I inherited had a regular electrical socket mounted through a wood plank. The septic tank opening was surrounded by plywood planks.  Some professional.  I built a 2-tall concrete garden brick building around the top, I filled it with sand and redid the electrical to a proper IP54 box for exposed sockets.






I made my system with 2 covers, an inner atop the man hole and the outer above the concrete wall.  


This is the outer cover.


 This is the custom inner cover.


It has happened that the electrical connections outside the manhole were wet and froze over.  The last time, I can tell from fixing it with bare fingers at -40C, you want your pump to stop is in the dead of winter. What you can use, which is a real source of heat, is the ambient heat from microbial action (bugs eating poo) to warm up around the plugs. You position the electrical connections inside the wellhead above the water spill zone. So long as you make sure they are properly protected from water build up, they will only get moist but stay warm. I use a single outdoor cord to connect to the socket to the electrical block in the warmer air. I tape the electrical to the top of the outlet pipe connected to the septic pump.



My septic system uses the outlet pipe as both the outport and check valve. The guy was too cheap to install a proper valve, but the up, over, and down pipe design makes an effective check valve when the pump stops. The trick is it needs a hole drilled into the pipe to prevent a vapour lock situation.  The first time I fixed it, I got it all done, and then turned it on and nothing happened. I sat there aghast at how all parts were in and nothing moved. Upon some searching, the answer appeared.  One 1/32 inch hole on the upward pipe and it stabilizes the pressure.


The original connection was a pipe fitting male to female. He glued a connection on the right angle pipe and it becomes quite a pain.  I can assure you if you remove the septic pump then try and replace it and don't set it on the pedestal properly, if the ends are slightly dirty (there is effluent all over this system in parts you don't expect) or frozen because you had the pieces on the ground in the cold, that you will spend more time than you need to trying to screw the ends together. You don't want to snap the ends or rip the pipe out either while trying to work them together.  I replaced the female connector with a rubber sleeve and sealing clamps called a coupler in this case 2inch to 2inch. All I need is to loosen one clamp screw and it peels right out and I can reseat it just as easily.

First step in determining what is broken, assemble replacement parts.  Since I was pulling out the septic pump anyway, and I have to remove the electrical connections, I will replace parts as I go. If you weren't aware most mechanical floats have a 2 year warranty so if they are questionable you may as well replace them.  I got a new cable, electrical tape, and zap straps.



I bought a $47 replacement 15 foot 90 degree mechanical switch to for the turn on switch.  When the water gets to the top of the range you want, you want the switch to finally turn on.  Then when it reaches the bottom, you want it to turn off. The 450467 has a long cord in case I need to hook it right to the top socket. I buy the longer ones then if I need to connect to the outlet with the pump I can do it. Excess cord can just be wrapped in the top of the hole near the  electrical block.



Since the pump might not be turning on, this is the suspect switch not the lower one at the bottom that prevents the motor from running dry.  There are 2 float switches in the electrical block. I will replace this one first run and see if that fixes it.

The second step is to unhook the septic pump, remove the pump and pipe, remove the electrical block, remove the pump plug, and plug the pump straight into the electrical socket. If the pump won't turn on then, it's shot.



With this new system, it takes 2 minutes to disconnect and pull out. One other benefit of the concrete wall is that you can lean on the rim and not fear shattering the plexiglass manhole - that would allow sand or dirt to get in.


Here is the septic system with the pump removed. I don't use gloves because I want to make sure I have a firm grip on the pipe/cable while working it around out of the hole. Expect you will get dirty and smell like shit. The rewards for a job well done is a shower.



Here is the septic pump, at bottom and the outlet pipe all the way at the top of image. Right beside the motor is the low end mechanical switch that turns off to stop motor burnout. Halfway up is another coupling I will explain. At the top is the electrical block.

If you cut the outlet pipe too short, you need to replace it. If you cut the outlet pipe too long you need to pull it all apart, recut, and replace it. By adding a coupler above the septic pump, you can make a quick adjustment, you can fit a 2 inch outlet pipe onto a 3 inch pipe on the septic pump as this one in the image above is. This also allows you to twist the direction of the pump versus the outlet pipe. It all becomes easier with an extra $5 part.


I use stereo wire doubled up as the hauling cable tied to the pump ring instead of using the pipe to lift it out.  This saves a little time because you can haul heavier and you don't risk damaging the pipe installing / reinstalling.

I pulled apart the electrical block, I unwrapped electrical tape, reinstalled the septic pump and plugged the pump by itself back into the electrical socket. It worked and I left the pump on to empty out the water.  Then I removed the septic pump so I could replace the mechanical switch. 


Here is the original float switch and the new one laid on top. If you want it to work the same the first thing you connect is the new float switch tied with zap straps at the same point with the same length under the line. This allows the switch to turn on for the right setting of your tank.  Once that is done you can snip the old switch and pull the dead cable out of the run. 



Once that float is installed, you connect all the plugs into an electrical block and then wrap them. You soft connect it to the top of the outlet pipe with electrical tape rather than zap straps and then wrap the extra cord lengths in a bundle. Last time I used gun tape this time I used electrical tape.  I replace the old electrical cord and taped it as well to the pipe.


If you've done everything properly, took your time and made sure your setting was right, then it's reinstall, connect, and plug it in. This fix took 1 hour 12 minutes, compared to the worst of many hours over many days in dribs and drabs.












Saturday, July 9, 2016

HOE TO: Air Spade to excavate under concrete using compressor

This post covers how to use a compressor and a pneumatic excavation tool, made in this case from copper pipe, a ball valve, and fitting, to dig under a concrete slab without a lot of effort. For small hole, a 1/2 inch 3 foot copper pipe works fine.  I use my small compressor with about 50 PSI, mainly because I am not in a hurry and can wait for it to store up air.

This hole under a 3 foot concrete slab took about 3.5 hours. The intended pipe was a 1/4 inch sprinkler pipe so I didn't need anything more than common stuff you would have at home: a screwdriver, ear defenders,  electrical cable, and about 20 feet of 200PSI compressor line.




I learned about air spades when working at General Dynamics and they were a potential system for mine clearance as they spread pressure around an excavating land mine; this means they could expose landmines with lesser risk of initiating fuses. In those applications the air pressure could be much greater than what I would recommend using on home made versions.

In this case, the goal is to use air pressure to expose and remove just enough dirt to run a pipe through.



I made this air spade out of copper because you need a semi-hard metal that can take some force from prodding and withstand enough pressurization. I solder the shit out of the connections, they are full welds and can survive prodding into the ground and scratching on concrete.

A reducer nozzle soldered to one end, a 1/2 inch ball valve soldered to the other and a compressor fitting is all you need.



I use 50 PSI and crimp the reducer into a venturi. You want an opening that can't swallow a rock so it runs without bursting the pipe, and can be used to prod and loosen rocks and soil.  While you aren't digging with a shovel, you are actively stabbing the rocks and soil to jar loose rocks.  The air pushes loose fill out the hole.


Copper won't take steel-type forcing, not without exploding or bending so you will apply steady firm force and move the tip around. Since the parts for this amount to $30 or so, I would recommend replacing one after a few uses rather than risk splayed copper shards in your hand.


  You could go without a valve but this way you can build up pressure.

This is the hole location, running a 1/4 inch pipe under sidewalk to the irrigation pipe in the garden. We, I, shovelled out 2 tons of gravel and we are going to lay sod in the dead space under the Mugo pines. Last step with our hot dry climate is irrigation!


First dig out small holes and remove enough vegetation you can be comfortable working on both sides. The holes start small and you are going to work from both sides but in case there is a large rock don't dig out too much- you might be moving. Air spades can't break rocks - at least not small ones. You want to dig shallow holes from both ends. As your spade gets longer into the hole, you want to extend the holes on both sides so you keep the spade under the concrete and not digging a larger hole.




The steeper the angle, the longer the hole and in the future the softer steeper hole will pour moisture into it which you don't want for frost heave reasons. You want the hole hugging the concrete.  N.B. I blow out my lines in the fall so they aren't going to freeze.


Once the hole is prepped, you can begin.  Of course you are working from both sides so you only have to go about half way from either side. This air spade could dig a whole sidewalk from one side but it would take longer.


I start loosening with a screwdriver and while you are working excavate the loose soil from the hole mouth.



Important, the more dirt you clear from the hole mouth, the more air will push dirt right out of the hole for you. If you don't clear while you work, you will just dig more yourself. Let the spade work. I did leave the spade on and went for a pee break and it did some work blowing out loose dirt but you really need to actively grind to work faster. Stab, blow, and remove loose dirt are the repeated actions.

Here's a small video from the excavation end.



Notice how the angle of attack is lower as you dig out the entrance. 

I use gloves even though it's low pressure because the venturi might rip skin back and I normally have skin tears on my hands. I've seen the video of compressors ripping skin back to the elbows, not worth the risk. 


 I use a prodding motion and alternate working both sides.

 Once you have gotten the spade fully in, you will see dirt shooting out the other side.




The gravel spoil on this photo came from the middle.



Last task is to feed the pipe through the hole. I tape the pipe to the air spade and shove it through.


Line is through in 3.5 hours in this case with dry soil that consisted of clay and sediment.


Thanks for reading my how to/ hoe to guide to air excavating.

Variable argument C functions with va_arg

Most tutorials online and those left standing for C give simplistic examples for the variable argument functions in <stdarg.h> for handling variable argument passing of various types.  The examples show you a simple data type like an integer and so on.

In this example, you can pass larger data types like structs into a variadic function just as easily. This means one can reproduce a simpler version of encapsulation/ polymorphism as in OOP languages. To present it first; here is a simple example that passes a struct, and then a struct inside a struct.



This passes a position struct containing x,y,z as coordinates, and the the same struct is passed to another function that accesses the inner position struct.   As a more complicated example, this suffices.

Now, when on considers pointer to functions and unions can be part of a struct, then you have all the encapsulation needed to contain an object struct that can be passed as argument. With unions, one can make a polymorphic version of a struct that can pass many types within the same container struct.

Tuesday, May 10, 2016

A real n-ary tree exemplar with GNodes from glib-2.XXX

This post presents a realistic GNodes unbalanced n-ary tree exemplar in C using Gnome glib-2.XXX.You can find more information on the API here.

I wanted to design a client/server node structuring system based on distance metric from a common point, so it made sense to explore  unbalanced trees. I wasn't familiar with them nor GLib at the outset. This work took about 2 days of fidgeting.

Online examples are bare presentations of the basic function calls. Here is a completed application that does something. The code you need is here ntree-distance.c.

This one presents an n-tree made from 3D Euclidean distances to and from an arbitrary point (city) and structures them on bounded distance neighbourhood balls. Essentially, the closest cities are siblings, those beyond a minimum metric are children, and those beyond a second metric are grandchildren. One could extend the paradigm as far as one likes.

The data for these cities is randomly generated, cities are then fed into a for loop that sorts them.  At the end of the code it uses the GLib g_tree_traverse and executes a simple printf function to display the data at each node.

In order to make children and grandchildren nodes at the start with no data entered, one can make notional child and grandchild nodes etc. to whatever depth is required. So in the code are a base, a middle, and a far (and a farthest I didn't include) GNode that are used to make a 4-depth tree structure before the data is available.

One important thing to note about GNodes is that there is a deep copy but no remove function. There is no direct way to remove a single child without destroying the rest under since the links are all pointers not a more complicated form of structure.  There is an unlink so one can construct a different tree from items but that may not be helpful.  Of course this means I have extra tree nodes at every level but I considered it as beneficial for my purpose because if in the future I removed other siblings I can maintain the tree skeleton as it were.

You will note in printouts the notional nodes appear as 0.0000 in the list for tree traversed so they are easy to pick out. As we append nodes at each level the notional tree elements are also 0 child so there is another way to ignore them.

Included in the gist github is a Makefile and the original notional GNode file from IBM that wasn't very helpful... like IBM...


I have included a copy of the old gnode.c code for examination, a glibtest.c from MIT I found if you need to sanity check your GLIB, a Makefile that will compile the ntree-distance.c and the glibtest.c  if you need them but the main file is ntree-distance.c





Monday, April 11, 2016

Creating and using a .this pointer in C language structs



This blog post contains examples of how to create a this pointer in C. You may know "this.xxxx" is a C++ attribute of objects. Well like many things you can emulate it in C because C is far more flexible without the bloating that object oriented languages provide for lazy programmers to make mistakes.

Of course, in order to emulate in C it requires more knowledge/experience than the average starting programmer can do. And as websites develop bit rot for older technology these things get lost unless others decide to pick up the challenge to maintain them.  I do not claim to be the first to do this, I am sure it's been done, but I am the one making a clear explanation and re-introducing it as it were.

I tried to post to stack exchange but I do not meet the process nazi's interpretation of a good question so I won't bother providing them my help. I would rather be helpful than process-correct and I don't get paid to educate so I stick to the facts without superfluity in a non-educational idiom.

<\whining>

One can make a resident pointer to a struct of the same type like so:


You don't need the first cca_t I just use it to make my understanding easier.

Before a struct has been defined one can't refer to it. Some sort of causal loop error in programming form.  But one can declare it as a struct while defining the struct- itself?!? Another metaphysical argument I don't need to go into. I know this will work on GCC with default warnings and error flags and that's all I care about. I cannot confirm if it works with C-XXXX standard in general terms. CAVEAT EMPTOR. If you do find out it works I would appreciate 40 ms of your time to respond back below and we can leave all the comments in one spot for people to find them. Like me in 6 months when I return.

So the "this" pointer is a pointer without an array. Notice I include a pointer to a pointer to  the same struct being defined. In this case I am making a same-typed pointer (to pointer) that will be the receptor of similar pointers from neighbouring cells. I was making a cellular automata at the time so that was the context. I wanted to be able to define modular units that might end up on different threads in this version. So they can access in the same program frame addressing but not necessarily the same operation unit / lightweight process.

So far so good. Now, when you initialize / construct the dynamic struct with malloc:




You point the this at the pointer you will return at the end of the function.

In this instantiation, I make cell surfaces dependent on the same neighbour number to 0 cell means neighbour 0 and also state[0] for any values passed back and forth. Now I can iterate once and get it all.  I don't make a set pattern for cell walls because they might have arbitrary connectedness.

Now when I want to assign a neighbour to a cell it works something like this:




I assign b's b->this variable to the neighbour slot open in a's neighbour list.
And likewise assign a's this to b. I also assign the cell walls (neighbour connection) using the ADDRESS OF of the pointer not the VALUE of the pointer. Since the neighbour is inside the larger struct passed and we are using  a pointer -> pointer -> struct we are accessing the value by default when we aim at the second struct within a struct that was passed inside a function variable declaration because these are nested structs within structs.  I know that sounds like double talk but I am unrolling the order of operations and presenting it in a way that when you look at other explanations will make sense.

Pointers take time to understand and remember that pointers give a value or an address, not an array, when accessed. That's why a pointer to element with offset indexing leads to another pointed-to element. An array is guaranteed for your program's sake (as far as it can see) to be a contiguous length of memory of type.

The struct is a value when accessed one way, it is an address when accessed the other.

I don't like the *( a + i).element method of writing C structs because it is a babyish technique taught by naive professors that have never dared to make more complicated nested code. Some claim it is faster and I don't dispute that but I doubt they've tried harder because they stop teaching at the semester end. Probably because when you present the same material every year no one challenges you to prove you can do more. It makes sense for basic applications which is what they can show you. But working code lives and gets more complex. Programmers don't.

I claim it's babyish because I dare them to keep this kind of nested logic straight in their mind when writing it.

*((((a+i)+j)+k)+l)+m).element

So

&(b->state[b->neighbour_number]).st

gives us the address of the pointed to state address (.st) inside the nested pointers and this can continue with a rational understanding of the content within like so:

&(b->state[b->neighbour_number]->neuron[b->cell_number]->synapse[b->geo_number]).st

ad infinitum with a rational way to understand what was written. I can make iterator names that make sense and I can understand 10 files all at once. All the element indices can be maintained at the top level and iterated which is really the operation that most code undergoes. But what is different here is people can make a direct understanding of the things operating on things because that is the level humans work at. That is what costs the most time; understanding what code does not writing perfect code. Machines are better in most cases for optimization except for ATLAS as far as I know. R. Clint Whaley is an uber nerd and he writes sparse matrix optimizations by hand.

I follow the unix philosophy  writing understandable code and leaving optimization as another step:

"Worse is better"

I work in research so I don't worry about development as much as making sure it works. But with a top level iteration mechanism the GCC compiler can then unroll for loops for speed or optimize for memory. But the human being writes code and then goes off for 3 months and then has to come back to it.

This is why writing things like a .this pointer make it easier to grasp what you wrote and then evolve it quickly with patterns that make sense.