The following example function takes 3 parameters, performs an operation using an SQL function, and returns the result.
CREATE FUNCTION SPLIT_STR(
x VARCHAR(255),
delim VARCHAR(12),
pos INT
Here’s an example of how to use metaclass programming to intercept class method calls similar to the method_missing technique in Ruby:
class ClassMethodInterceptor(type):
def __getattr__(cls, name):
return lambda *args, **kwargs: \
cls.static_method_missing(name, *args, **kwargs)
#!/bin/bash | |
# Author [email protected] | |
svn_url="$(svn info . | grep 'URL:' | cut -c6-)" | |
echo "Repository ${svn_url}" | |
svn log -v --xml . > templog.log | |
touch svnlog.log |
function rgbToHex(r, g, b) { | |
return "#" + ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1); | |
} |
def rgb_from_str(s): | |
# s starts with a #. | |
r, g, b = int(s[1:3],16), int(s[3:5], 16),int(s[5:7], 16) | |
return r, g, b | |
def find_nearest_colour(R,G, B, colorD): | |
mindiff = None | |
for d in colorD: | |
r, g, b = rgb_from_str(colorD[d]) |
ssh -i ~/.ec2/my.pem [email protected] "cat /var/log/secure | grep 'refused connect'"
When using SSH to run commands across multiple machines without exchanging your public key, you need to type in your password for each machine. A quick and simple way of setting this up is to create a public key:
ssh-keygen -t rsa
Get the absolute position of every link in an html document using JavaScript:
/**
* The HTML <area> coords attribute needs the position of the left, top, right, bottom corner
* of the rectangle. Element.getBoundingClientRect returns a text rectangle object that encloses
* a group of text rectangles.
*/
function getElementAbsolutePosition(element) {
var pos = {};
pos.left = 0;