Is valid page

Wednesday, March 17th, 2010

A little function I use to double check the items in a friendly url to see if they only use valid characters.

  1. // Check if the page name is correct
  2. function isValidPage($page){
  3.         $safe = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '_', '.');
  4.         $pageCheck = preg_split('//', strtolower($page), -1, PREG_SPLIT_NO_EMPTY);
  5.  
  6.         // Make sure that the page name has only safe variables
  7.         foreach($pageCheck as $key => $val){
  8.                 if(!in_array($val, $safe)) return false;
  9.         }
  10.         return true;
  11. }

Display clean php code for copying

// Check if the page name is correct
function isValidPage($page){
	$safe = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '_', '.');
	$pageCheck = preg_split('//', strtolower($page), -1, PREG_SPLIT_NO_EMPTY);

	// Make sure that the page name has only safe variables
	foreach($pageCheck as $key => $val){
		if(!in_array($val, $safe)) return false;
	}
	return true;
}

Is date

Wednesday, March 17th, 2010

See if a string is actually a date (used for friendly urls mostly)

  1. // See if a string from the url is an actual date
  2. function isDate($var){
  3.         $time = strtotime(str_replace('-', ' ', $var));
  4.         if($time){
  5.                 if(strlen($var) == 8){
  6.                         return Array('month', $var, $time);
  7.                 }elseif(strlen($var) == 11){
  8.                         return Array('day', $var, $time);
  9.                 }
  10.         }
  11.         return false;
  12. }

Display clean php code for copying

// See if a string from the url is an actual date
function isDate($var){
	$time = strtotime(str_replace('-', ' ', $var));
	if($time){
		if(strlen($var) == 8){
			return Array('month', $var, $time);
		}elseif(strlen($var) == 11){
			return Array('day', $var, $time);
		}
	}
	return false;
}

Html symbols

Wednesday, March 17th, 2010
Character Entity Decimal Hex Rendering in Your Browser
Entity Decimal Hex
Latin small f with hook = function = florin ƒ ƒ ƒ ƒ ƒ ƒ
Greek capital letter alpha Α Α Α Α Α Α
Greek capital letter beta Β Β Β Β Β Β
Greek capital letter gamma Γ Γ Γ Γ Γ Γ
Greek capital letter delta Δ Δ Δ Δ Δ Δ
Greek capital letter epsilon Ε Ε Ε Ε Ε Ε
Greek capital letter zeta Ζ Ζ Ζ Ζ Ζ Ζ
Greek capital letter eta Η Η Η Η Η Η
Greek capital letter theta Θ Θ Θ Θ Θ Θ
Greek capital letter iota Ι Ι Ι Ι Ι Ι
Greek capital letter kappa Κ Κ Κ Κ Κ Κ
Greek capital letter lambda Λ Λ Λ Λ Λ Λ
Greek capital letter mu Μ Μ Μ Μ Μ Μ
Greek capital letter nu Ν Ν Ν Ν Ν Ν
Greek capital letter xi Ξ Ξ Ξ Ξ Ξ Ξ
Greek capital letter omicron Ο Ο Ο Ο Ο Ο
Greek capital letter pi Π Π Π Π Π Π
Greek capital letter rho Ρ Ρ Ρ Ρ Ρ Ρ
Greek capital letter sigma Σ Σ Σ Σ Σ Σ
Greek capital letter tau Τ Τ Τ Τ Τ Τ
Greek capital letter upsilon Υ Υ Υ Υ Υ Υ
Greek capital letter phi Φ Φ Φ Φ Φ Φ
Greek capital letter chi Χ Χ Χ Χ Χ Χ
Greek capital letter psi Ψ Ψ Ψ Ψ Ψ Ψ
Greek capital letter omega Ω Ω Ω Ω Ω Ω
Greek small letter alpha α α α α α α
Greek small letter beta β β β β β β
Greek small letter gamma γ γ γ γ γ γ
Greek small letter delta δ δ δ δ δ δ
Greek small letter epsilon ε ε ε ε ε ε
Greek small letter zeta ζ ζ ζ ζ ζ ζ
Greek small letter eta η η η η η η
Greek small letter theta θ θ θ θ θ θ
Greek small letter iota ι ι ι ι ι ι
Greek small letter kappa κ κ κ κ κ κ
Greek small letter lambda λ λ λ λ λ λ
Greek small letter mu μ μ μ μ μ μ
Greek small letter nu ν ν ν ν ν ν
Greek small letter xi ξ ξ ξ ξ ξ ξ
Greek small letter omicron ο ο ο ο ο ο
Greek small letter pi π π π π π π
Greek small letter rho ρ ρ ρ ρ ρ ρ
Greek small letter final sigma ς ς ς ς ς ς
Greek small letter sigma σ σ σ σ σ σ
Greek small letter tau τ τ τ τ τ τ
Greek small letter upsilon υ υ υ υ υ υ
Greek small letter phi φ φ φ φ φ φ
Greek small letter chi χ χ χ χ χ χ
Greek small letter psi ψ ψ ψ ψ ψ ψ
Greek small letter omega ω ω ω ω ω ω
Greek small letter theta symbol ϑ ϑ ϑ ϑ ϑ ϑ
Greek upsilon with hook symbol ϒ ϒ ϒ ϒ ϒ ϒ
Greek pi symbol ϖ ϖ ϖ ϖ ϖ ϖ
bullet = black small circle • • •
horizontal ellipsis = three dot leader … … …
prime = minutes = feet ′ ′ ′
double prime = seconds = inches ″ ″ ″
overline = spacing overscore ‾ ‾ ‾
fraction slash ⁄ ⁄ ⁄
script capital P = power set = Weierstrass p ℘ ℘ ℘
blackletter capital I = imaginary part ℑ ℑ ℑ
blackletter capital R = real part symbol ℜ ℜ ℜ
trade mark sign ™ ™ ™
alef symbol = first transfinite cardinal ℵ ℵ ℵ
leftwards arrow ← ← ←
upwards arrow ↑ ↑ ↑
rightwards arrow → → →
downwards arrow ↓ ↓ ↓
left right arrow ↔ ↔ ↔
downwards arrow with corner leftwards = carriage return ↵ ↵ ↵
leftwards double arrow ⇐ ⇐ ⇐
upwards double arrow ⇑ ⇑ ⇑
rightwards double arrow ⇒ ⇒ ⇒
downwards double arrow ⇓ ⇓ ⇓
left right double arrow ⇔ ⇔ ⇔
for all ∀ ∀ ∀
partial differential ∂ ∂ ∂
there exists ∃ ∃ ∃
empty set = null set = diameter ∅ ∅ ∅
nabla = backward difference ∇ ∇ ∇
element of ∈ ∈ ∈
not an element of ∉ ∉ ∉
contains as member ∋ ∋ ∋
n-ary product = product sign ∏ ∏ ∏
n-ary sumation ∑ ∑ ∑
minus sign − − −
asterisk operator ∗ ∗ ∗
square root = radical sign √ √ √
proportional to ∝ ∝ ∝
infinity ∞ ∞ ∞
angle ∠ ∠ ∠
logical and = wedge ∧ ∧ ∧
logical or = vee ∨ ∨ ∨
intersection = cap ∩ ∩ ∩
union = cup ∪ ∪ ∪
integral ∫ ∫ ∫
therefore ∴ ∴ ∴
tilde operator = varies with = similar to ∼ ∼ ∼
approximately equal to ≅ ≅ ≅
almost equal to = asymptotic to ≈ ≈ ≈
not equal to ≠ ≠ ≠
identical to ≡ ≡ ≡
less-than or equal to ≤ ≤ ≤
greater-than or equal to ≥ ≥ ≥
subset of ⊂ ⊂ ⊂
superset of ⊃ ⊃ ⊃
not a subset of ⊄ ⊄ ⊄
subset of or equal to ⊆ ⊆ ⊆
superset of or equal to ⊇ ⊇ ⊇
circled plus = direct sum ⊕ ⊕ ⊕
circled times = vector product ⊗ ⊗ ⊗
up tack = orthogonal to = perpendicular ⊥ ⊥ ⊥
dot operator ⋅ ⋅ ⋅
left ceiling = APL upstile ⌈ ⌈ ⌈
right ceiling ⌉ ⌉ ⌉
left floor = APL downstile ⌊ ⌊ ⌊
right floor ⌋ ⌋ ⌋
left-pointing angle bracket = bra ⟨ 〈 〈
right-pointing angle bracket = ket ⟩ 〉 〉
lozenge ◊ ◊ ◊
black spade suit ♠ ♠ ♠
black club suit = shamrock ♣ ♣ ♣
black heart suit = valentine ♥ ♥ ♥
black diamond suit ♦ ♦ ♦

Htaccess

Wednesday, March 17th, 2010

This is a very basic .htaccess file as I like to use it. It simply redirects any request to the index.php if it’s not an existing file and not an existing directory.

  1. <IfModule mod_rewrite.c>
  2.  
  3. RewriteEngine On
  4.  
  5. RewriteCond %{REQUEST_FILENAME} !-f
  6. RewriteCond %{REQUEST_FILENAME} !-d
  7. RewriteRule ^(.*)/? /index.php?loc=$1
  8.  
  9. </IfModule>

Display clean text code for copying

<IfModule mod_rewrite.c>

RewriteEngine On 

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/? /index.php?loc=$1

</IfModule>

It works as follows:

checks to see if mod-rewrite is enabled

You can add Options +FollowSymlinks on the line before RewriteEngine On
It needs to be enabled for mod rewrite to actually work

RewriteEngine On
Start the rewrite engine

RewriteCond %{REQUEST_FILENAME} !-f
Is a condition and returns true if the requested location is not an existing file.

RewriteCond %{REQUEST_FILENAME} !-d
Is a condition and returns true if the location is not an existing directory.

RewriteRule ^(.*)/? /index.php?loc=$1
Does the actual redirection, basicly it takes everything from behind http://www.mysite.domain/ and puts it behind loc=
So inside your index.php you can get the url as $_GET['loc']
You can then use PHP to analyse what was requested.

</IfModule>
The end of the rewriting.

There are lots of more complicated things you can do, but this is what I need more often and it does only the thing I need… which is good.

Finding mesh angles

Wednesday, March 17th, 2010

Here I’ll try to explain a method for finding out the angle of a mesh at a specific point/edge in python.

This method can for instance be used to create effects like with the ma baker or ma self scripts;


Finding the angle between two faces in Blender

Now this isn’t really complicated.

Lets say you retrieve two faces from Blender’s python API that are connected by an edge.

Lets call them face1 and face2 and face1.no retrieves the face normal of face1.

Then we can simply do the following to find the angle:

  1. myAngle = Mathutils.AngleBetweenVecs(face1.no, face2.no)

Display clean python code for copying

myAngle = Mathutils.AngleBetweenVecs(face1.no, face2.no)

The result though is only an angle between 0 and 90 degrees, to find out if that is positive or negative continue reading below.


Finding out whether the angle between two faces is convex or concave

A lot of the time you also want to know whether the angle is concave or convex (positive or negative).

To get that we get the vector from the midpoint of face1 to the midpoint of face2.

The midpoint of a face is retrieved by getting face1.cent.

Then we get the dot product of the face normal of face1 and the vector we just retrieved.

In python that could be:

  1. dotProduct = Mathutils.DotVecs(face1.no, (face2.cent - face1.cent))

Display clean python code for copying

dotProduct = Mathutils.DotVecs(face1.no, (face2.cent - face1.cent))

The resulting dot product will be either positive or negative depending on whether the angle is concave or convex.

Browser languages

Wednesday, March 17th, 2010

These are all the language codes you can retrieve from people’s browsers (in php with $_SERVER['HTTP_ACCEPT_LANGUAGE'] for instance)

af Afrikaans
sq Albanian
ar-sa Arabic(Saudi Arabia)
ar-iq Arabic(Iraq)
ar-eg Arabic(Egypt)
ar-ly Arabic(Libya)
ar-dz Arabic(Algeria)
ar-ma Arabic(Morocco)
ar-tn Arabic(Tunisia)
ar-om Arabic(Oman)
ar-ye Arabic(Yemen)
ar-sy Arabic(Syria)
ar-jo Arabic(Jordan)
ar-lb Arabic(Lebanon)
ar-kw Arabic(Kuwait)
ar-ae Arabic(U.A.E.)
ar-bh Arabic(Bahrain)
ar-qa Arabic(Qatar)
eu Basque
bg Bulgarian
be Belarusian
ca Catalan
zh-tw Chinese(Taiwan)
zh-cn Chinese(PRC)
zh-hk Chinese(Hong Kong)
zh-sg Chinese(Singapore)
hr Croatian
cs Czech
da Danish
nl Dutch(Standard)
nl-be Dutch(Belgian)
en English
en-us English(United States)
en-gb English(British)
en-au English(Australian)
en-ca English(Canadian)
en-nz English(New Zealand)
en-ie English(Ireland)
en-za English(South Africa)
en-jm English(Jamaica)
en-ca English(Caribbean)
en-bz English(Belize)
en-tt English(Trinidad)
et Estonian
fo Faeroese
fa Farsi
fi Finnish
fr French(Standard)
fr-be French(Belgian)
fr-ca French(Canadian)
fr-ch French(Swiss)
fr-lu French(Luxembourg)
mk Macedonian (FYROM)
gd Gaelic(Scots)
de German(Standard)
de-ch German(Swiss)
de-at German(Austrian)
de-lu German(Luxembourg)
de-li German(Liechtenstein)
el Greek
he Hebrew
hi Hindi
hu Hungarian
is Icelandic
in Indonesian
it Italian(Standard)
it-ch Italian(Swiss)
ja Japanese
ko Korean
ko Korean(Johab)
lv Latvian
lt Lithuanian
ms Malaysian
mt Maltese
no Norwegian(Bokmal)
no Norwegian(Nynorsk)
pl Polish
pt-br Portuguese(Brazil)
pt Portuguese(Portugal)
rm Rhaeto-Romanic
ro Romanian
ro-mo Romanian(Moldavia)
ru Russian
ru-mo Russian(Moldavia)
sz Sami(Lappish)
sr Serbian(Cyrillic)
sr Serbian(Latin)
sk Slovak
sl Slovenian
sb Sorbian
es Spanish(Spain – Traditional Sort)
es-mx Spanish(Mexican)
es-gt Spanish(Guatemala)
es-cr Spanish(Costa Rica)
es-pa Spanish(Panama)
es-do Spanish(Dominican Republic)
es-ve Spanish(Venezuela)
es-co Spanish(Colombia)
es-pe Spanish(Peru)
es-ar Spanish(Argentina)
es-ec Spanish(Ecuador)
es-c Spanish(Chile)
es-uy Spanish(Uruguay)
es-py Spanish(Paraguay)
es-bo Spanish(Bolivia)
es-sv Spanish(El Salvador)
es-hn Spanish(Honduras)
es-ni Spanish(Nicaragua)
es-pr Spanish(Puerto Rico)
sx Sutu
sv Swedish
sv-fi Swedish(Finland)
th Thai
ts Tsonga
tn Tswana
tr Turkish
uk Ukrainian
ur Urdu
ve Venda
vi Vietnamese
xh Xhosa
ji Yiddish
zu Zulu

Angle math

Wednesday, March 17th, 2010

This is just here so I don’t forget ;)

(small characters here refer to angles, capitals to lengths of sides)


An oblique triangle

A triangle without a 90 degree angle

Python equivalents of the above math are for instance (untested):

A = math.sin(a) / (math.sin(b)/B)

B = math.sin(b) / (math.sin(c)/C)

C = math.sin(c) / (math.sin(a)/A)


A right angle triangle

A triangle with a single 90 degree angle (a in this case)

Python equivalents of the above math are for instance:

c = math.asin(C/A)

c = math.acos(A/C)

c = math.atan(C/B)

A = math.sqrt(B*B+C*C)

Remember soscastoa!

click here to close

Help keep these files free,
and support further development!