neat_trim($your_text, 100);

function neat_trim( $string, $n, $close = '…' ) {

$len = strlen( $string );

if ($len > $n) {
preg_match('/(.{' . $n . '}.*?)b/', $string, $matches);
return rtrim($matches[1]) . $close;
} else {
return $string;
}

}

look in your /system/application/errors/ and find the error_404.php and put this (edited to match your site of course)

<?php
header(“HTTP/1.1 404 Not Found”);
header(“location:http://www.tldomain.com/index.php?/controller/sitemap/404″);
?>

So when the 404 page loads the 404 still gets logged by apache etc… but once that happens it gets rushed of to (in this case) the site map. The 404 variable tells the controller method in this case the site map to display a this page cannot be found message.

Generate Passwords with MyQL

Apr, 26 -- Categories: MySQL

Many applications store MD5-crypted passwords in the database. If you want to quickly create a new MD5-ed password, or you have forgotten your password, use the following query to get a new one:

SELECT MD5(”m0ntypy7hon”);

This query will return “4f249cbc2c10d41f866b64decd365e39″ which is the encrypted version of the string “ m0ntypy7hon”.

There are other function that crypt stings in MySQL using different algorithms, most notably PASSWORD() which is using MySQL”s own crypting algorithm.

SELECT PASSWORD( “m0ntypy7hon” ) ;

returns: “5216be9f6ead4434”

The XML

<data>

<button handle=”prim_butt1″ text=”Larry” x=”60″ y=”160″ ></button>

<button handle=”prim_butt2″ text=”Moe” x=”170″ y=”160″ ></button>

<button handle=”prim_butt3″ text=”Curly” x=”280″ y=”160″ ></button>

<button handle=”prim_butt4″ text=”Shemp” x=”390″ y=”160″ ></button>

</data>

Now The Actionscript:

package {

import flash.display.MovieClip;
import flash.events.*;
import flash.net.*;
import flash.text.*;

import mc_button_primary;

public class StarterClass extends MovieClip {

private var i:Number;
private var primButtonCount:Number;
private var xmlLoader:URLLoader;
private var dataXML:XML;
private var buttonPrimary:mc_button_primary;
private var urlArray = new Array();

public function StarterClass() {

trace(“StarterClass……….√ check”);

// create a loader for our xml file
xmlLoader = new URLLoader(new URLRequest(“nav_primary.xml”));
// oops couldn't get our xml file
xmlLoader.addEventListener(IOErrorEvent.IO_ERROR, noFile);
// got our file now go do something (myInitMethod) with it
xmlLoader.addEventListener(Event.COMPLETE, myInitMethod);

// THROW ERROR IF XML SHOOTS CRAPS
function noFile(evt:IOErrorEvent):void {
trace(“Error. Data file not found.”);
}

}

// and now to do something with our data
private function myInitMethod(evt:Event):void {

trace(“myInitMethod……….√ check”);

// make sure flash knows it xml
dataXML = XML(xmlLoader.data);

// number of buttons in our xml
primButtonCount = dataXML.button.length();

// loop thru each button and make the data useful
for (i=0; i< primButtonCount; i++) {

trace("foo > “+dataXML.button[i].@handle );

// this is an array that contains the button text and it looks like
// urlArray[”prim_butt1″] == “Larry”

// it's referenced it in the click event
urlArray[dataXML.button[i].@handle] = dataXML.button[i].@text;

// create a new button from the library object
buttonPrimary = new mc_button_primary();
// give it a name
buttonPrimary.name = dataXML.button[i].@handle.toString();
// put it on the stage
addChild( buttonPrimary );

// find our new named button and give it a handle
var bttn_handle = getChildByName( buttonPrimary.name );
// now use the handle to move it and add text
bttn_handle.x = dataXML.button[i].@x;
bttn_handle.y = dataXML.button[i].@y;
bttn_handle.button_Text.text = dataXML.button[i].@text;
// add a listener so you can do something when you click it
bttn_handle.addEventListener( MouseEvent.CLICK, myButton_CLICK );

}

}

// here is the click event
function myButton_CLICK(event:MouseEvent):void {

// the name comes fom the urlArray ceated above
trace( “The button clicked was > “+urlArray[ event.target.name ]);

}

}

}
StarterClass_xml_basic.zip

MySql Find/replace

Apr, 25 -- Categories: MySQL

UPDATE yourtable SET targetfield = REPLACE(targetfield, “foo”,“bar”);

This statement will replace all occurrences of the string “foo” with the string “bar” in all records of the “ targetfield” column. Apart from the string “bar” the rest of the text contained in the field will be unchanged.

Codeigniter app log helper

Apr, 24 -- Categories: PHP

This is for debugging only. Ok, again…. this is for debugging only. If you use this REMOVE it once it goes live. At worst you forget to add the tag that clears the log file each time and it bloats horribly and your site gets progressively slower and slower, then your server will crash, you’ll get fired and end up homeless. But if you remove it when your done it’s pretty handy.

This goes in a helper file of your choosing and make sure you load it:

$this->load->helper('the_helper_where_you_put_this_code');

Then put this in the helper file you loaded

if ( ! function_exists('app_log')) {

function app_log($arg) {

// this is your log file, so I referenced it by viewing
// domain.com/applog.htm
$log = './applog.htm';

// to empty the file and start over the first call should begin with init_log
if( preg_match(“/^init_log/”, $arg) ) {

// writes the the file name and whatever the arg is at the start of the file
if (!write_file($log, ''.$arg, 'w') ) {

// or dies
die( 'Unable to write to log file');

}

} else {

// adds whatever the $arg is to the end of the file
if ( ! write_file($log, ''.$arg, 'a+')) {

// or dies
die( 'Unable to write to log file');

}

}

}

}

To use the helper:

app_log('init_log -> Whatever you want goes here');

I usually make the above call in the constructor, then after that in your methods whatever you want to track use:

app_log('blah blah blah');

More SSH login goodness

Apr, 22 -- Categories: Linux

Save a text file as “login.command” or whatever but thats what I’m calling mine.

Enter this:

#!/bin/sh
ssh yourusername@yourdomain.com

Then you’ll need to make the file executable
“cd” to wherever your file is then run

chmod +x login.command

You may also have to do a get info and then select “Terminal” under “Open With”. You should now be able to double click the file and then the terminal will open and login to your server. If you drag that file under your “Places” in the sidebar your now one click away.

 

 

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

// for this example I just want to count down 30 Seconds
var remainingSeconds:int = 30;

// this is the function that the setInterval function calls
function countDownSeconds() {

// not a second off of the current number of seconds
remainingSeconds--;

// if we have run out of seconds do this
if (remainingSeconds == 0) {

trace(“DONE”);
clearInterval(myInterval);

} else {

trace(“tic”);

}

}

// this is the line that calls the specified function
// in this case “countDownSeconds” and it calls it every
// 1000 milliseconds in this case.

var myInterval = setInterval(countDownSeconds, 1000);

 

Here is roughly how I did that:

http://www.jamesborder.local/URLRequest.php (your url should be wherever your data is)

<?php

// create an array to put your junk in… then put it there
$variablesArray = array();
$variablesArray['var1'] = “foo”;
$variablesArray['var2'] = “bar”;

// let php build a nice string for you
$variablesArrayString = http_build_query($variablesArray);

echo $variablesArrayString;
// var1=foo&var2=bar

?>

-=-=-=-=-=-=-=-=-=-

Here is roughly what is in the .fla

// build your request…. your url/file will go here
var request:URLRequest = new URLRequest(“http://www.jamesborder.local/URLRequest.php”);
request.method = URLRequestMethod.GET;

// create
var loader:URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
loader.addEventListener(Event.COMPLETE, onCompleteHandler);
loader.load(request);

function onCompleteHandler(event:Event) {

trace(“completeHandler(“+event+”)”);
var var1 = event.target.data.var1;
var var2 = event.target.data.var2;

trace ('variable one: ' + var1);
trace ('variable two: ' + var2);

}

SSH login without password

Apr, 15 -- Categories: Linux

You need to know if you didn’t already this means: anybody that has access to your computer or access to the to rsa keys has complete access to your server without knowing the password.

I REPEAT:
Anybody that has access to your computer or access to the to rsa keys has complete access to your server without knowing the password.

Got it?

But this also means you can now log in without being prompted for username/password and that is sweet. Just maintain some good computer hygiene & keep your computer and your keys safe.

When you google this there are a lot of different instructions, and a lot of different ways for it to go badly. But the shot of the deal is you need to get these two files in your .ssh directory on your local computer:

id_rsa
id_rsa.pub

Then you need to get a copy of the id_rsa.pub saved into the .ssh as authorized_keys, or get the line from your id_ra.pub added to that file if it already exists. Then if you have the permissions right etc. etc. no more being prompted for your password.

So on your local machine do this:

If the .ssh directory doesn’t exist:

mkdir ~/.ssh
chmod 700 ~/.ssh

else

cd ~/.ssh
ssh-keygen -t rsa

Running the key generator looks like this for me:

Generating public/private rsa key pair.
Enter file in which to save the key (/Users/me/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /Users/me/.ssh/id_rsa.
Your public key has been saved in /Users/me/.ssh/id_rsa.pub.
The key fingerprint is:
XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX me@xxxxxpro.local
The key's randomart image is:
+--[ RSA 2048]----+
| &!..()= .|
| . . o.+d@+|
| E * + oo.+*|
| . * . …=|
| S . |
| |
| |
| |
| |
+-----------------+

just hit return for no pass phrase thats what we’re going for here.

Now your half way there. You need to get the public half of the key to the REMOTE computer and user account you want to log in TO:

scp ~/.ssh/id_rsa.pub you@yoursite.com:/home/youruser/id_rsa.pub

then login

ssh you@yoursite.com
Password:
mkdir .ssh
chmod 700 .ssh
cat id_rsa.pub >> .ssh/authorized_keys
chmod 644 .ssh/authorized_keys

then login to make sure it worked. I have done this may times and every time it didn’t work like I expected it was related to permissions or ownership some where.

then:
rm id_rsa.pub
 

First look inside the .fla and then inside the mc_button_primary and notice there is a little code inside there. Won’t work like you want to without it. You can add it to each instance via the myMethod() but it’s meant to be a button so let’s make this as simple as we can and put it here.

stop();
this.buttonMode = true;
this.mouseChildren = false;

StarterClass.as
Here is where something actually happens follow the comments.

package {

// here is the Adobe provided code that you need to import to make this happen
// get used to it. You'll be doing this alot.
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.text.*;

// import our fancy button from the library
import mc_button_primary;

public class StarterClass extends MovieClip {

// here's where our new button is born
private var buttonPrimary:mc_button_primary;

// this is the constructor, it is the function/method that is automatically called
function StarterClass() {

trace(“Starter class…..√ check”);

// call myMethod and create a button
myMethod();

}

function myMethod() {

trace(” myMethod……….√ check”);
trace(” StarterClass called myMethod()”);
trace(” myMethod() creates a button”);

// create a new button from the exported library item
buttonPrimary = new mc_button_primary();

// name the new button
buttonPrimary.name = “Linus”;

// put Linus on the stage
addChild( buttonPrimary );

// create a handle to reference Linus with
var bttn_handle = getChildByName( buttonPrimary.name );

// Put the name in the text field then center Linus on the stage
bttn_handle.button_Text.text = buttonPrimary.name;
bttn_handle.x = ( stage.stageWidth - bttn_handle.width ) / 2;
bttn_handle.y = ( stage.stageHeight - bttn_handle.height ) / 2;

// add an event listener to Linus so we know when he was clicked
bttn_handle.addEventListener( MouseEvent.CLICK, myButton_CLICK );

}

// here is the listener
function myButton_CLICK(e:MouseEvent):void {

trace(” myButton_CLICK is called when the button is clicked”);

}

}

}

StarterClass_wButton.zip

find /whatever/directory/here -type f -name “.DS_Store” -delete -print

for example:

find /Users/me/Documents/-Actionscript-Flash -type f -name “.DS_Store” -delete -print

or

find /home/vhosts/dev31 -type f -name “._*” -delete -print

Here are some subversion examples

find . -type d -name ‘.svn’ -print0 | xargs -0 rm -rdf

find ./ -name “.svn” | xargs rm -Rf

Yes I understand you can export to get rid of them. But there has been more than one occasion where I wanted to exactly this without purging thru subversion and I’m sure I’m not the only one that has ever wanted to… so here is how.

Friendly Code Numerical Code Display Hex Description
  &#09;     Horizontal Tab
  &#10;     Line feed
  &#32;   20 space
  &#33; ! 21 Exclamation point
&quot; &#34; 22 Double quote
  &#35; # 23 Number sign
  &#36; $ 24 Dollar sign
  &#37; % 25 Percent sign
&#38; &#38; & 26 #38ersand (and sign)
  &#39; 27 Single quote
  &#40; ( 28 Left parenthesis
  &#41; ) 29 Right parenthesis
  &#42; * 2A Asterisk (star)
  &#43; + 2B Plus
  &#44; , 2C Comma
  &#45; - 2D Minus (hyphen)
  &#46; . 2E Period
  &#47; / 2F Forward slash
  &#48; 0 30 Zero
  &#49; 1 31 One
  &#50; 2 32 Two
  &#51; 3 33 Three
  &#52; 4 34 Four
  &#53; 5 35 Five
  &#54; 6 36 Six
  &#55; 7 37 Seven
  &#56; 8 38 Eight
  &#57; 9 39 Nine
  &#58; : 3A Colon
  &#59; ; 3B Semi-colon
&lt; &#60; < 3C Less-than sign
  &#61; = 3D Equal sign
&gt; &#62; > 3E Greater-than sign
  &#63; ? 3F Question mark
  &#64; @ 40 At-sign
  &#65; A 41 Capital a
  &#66; B 42 Capital b
  &#67; C 43 Capital c
  &#68; D 44 Capital d
  &#69; E 45 Capital e
  &#70; F 46 Capital f
  &#71; G 47 Capital g
  &#72; H 48 Capital h
  &#73; I 49 Capital i
  &#74; J 4A Capital j
  &#75; K 4B Capital k
  &#76; L 4C Capital l
  &#77; M 4D Capital m
  &#78; N 4E Capital n
  &#79; O 4F Capital o
  &#80; P 50 Capital p
  &#81; Q 51 Capital q
  &#82; R 52 Capital r
  &#83; S 53 Capital s
  &#84; T 54 Capital t
  &#85; U 55 Capital u
  &#86; V 56 Capital v
  &#87; W 57 Capital w
  &#88; X 58 Capital x
  &#89; Y 59 Capital y
  &#90; Z 5A Capital z
  &#91; [ 5B Left square bracket
  &#92; \ 5C Back slash
  &#93; ] 5D Right square bracket
  &#94; ^ 5E Caret
  &#95; _ 5F Underscore
  &#96; ` 60 Grave accent
  &#97; a 61 Lowercase a
  &#98; b 62 Lowercase b
  &#99; c 63 Lowercase c
  &#100; d 64 Lowercase d
  &#101; e 65 Lowercase e
  &#102; f 66 Lowercase f
  &#103; g 67 Lowercase g
  &#104; h 68 Lowercase h
  &#105; i 69 Lowercase i
  &#106; j 6A Lowercase j
  &#107; k 6B Lowercase k
  &#108; l 6C Lowercase l
  &#109; m 6D Lowercase m
  &#110; n 6E Lowercase n
  &#111; o 6F Lowercase o
  &#112; p 70 Lowercase p
  &#113; q 71 Lowercase q
  &#114; r 72 Lowercase r
  &#115; s 73 Lowercase s
  &#116; t 74 Lowercase t
  &#117; u 75 Lowercase u
  &#118; v 76 Lowercase v
  &#119; w 77 Lowercase w
  &#120; x 78 Lowercase x
  &#121; y 79 Lowercase y
  &#122; z 7A Lowercase z
  &#123; { 7B Left curly brace
  &#124; | 7C Vertical bar
  &#125; } 7D Right curly brace
&tilde; &#126; ~ 7E tilde
  &#127;  7F Not defined
  &#128; 20AC Euro
  &#129;   Unknown
&sbquo; &#130; 201A Single low-quote
  &#131; ƒ 192 Function symbol (lowercase f with hook)
&dbquo; &#132; 201E Double low-quote
  &#133; 2026 Elipsis
&dagger; &#134; 2020 Dagger
&Dagger; &#135; 2021 Double dagger
  &#136; ˆ   Hatchek
&permil; &#137; 2030 Per million symbol
  &#138; Š 160 Capital esh
&lsaquo; &#139;   Left single angle quote
  &#140; Œ 152 OE ligature
  &#141;   Unknown
  &#142; Ž   Capital ž
  &#143;   Unknown
  &#144;   Unknown
&lsquo; &#145; 2018 Left single-quote
&rsquo; &#146; 2019 Right single-quote
&ldquo; &#147; 201C Left double-quote
&rdquo; &#148; 201D Right double-quote
  &#149; 2022 Small bullet
&ndash; &#150; 2013 En dash
&mdash; &#151; 2014 Em dash
&tilde &#152; ˜   Tilde
&trade; &#153; 2122 Trademark
  &#154; š 161 Lowercase esh
&rsaquo; &#155;   Right single angle quote
  &#156; œ 153 oe ligature
  &#157;   Unknown
  &#158; ž   Lowercase ž
&Yuml; &#159; Ÿ 178 Uppercase y-umlaut
&nbsp; &#160;   A0 Non-breaking space
&iexcl; &#161; ¡ A1 Inverted exclamation point
&cent; &#162; ¢ A2 Cent
&pound; &#163; £ A3 Pound currency sign
&curren; &#164; ¤ A4 Currency sign
&yen; &#165; ¥ A5 Yen currency sign
&brvbar; &#166; ¦ A6 Broken vertical bar
&sect; &#167; § A7 Section symbol
&uml; &#168; ¨ A8 Umlaut (Diaeresis)
&copy; &#169; © A9 Copyright
&ordf; &#170; ª AA Feminine ordinal indicator (superscript lowercase a)
&laquo; &#171; « AB Left angle quote
&not; &#172; ¬ AC Not sign
&shy; &#173; ­  AD Soft hyphen
&reg; &#174; ® AE Registered sign
&macr; &#175; ¯ AF Macron
&deg; &#176; ° B0 Degree sign
&plusmn; &#177; ± B1 Plus/minus sign
&sup2; &#178; ² B2 Superscript 2
&sup3; &#179; ³ B3 Superscript 3
  &#180; ´ B4 Acute accent
&micro; &#181; µ B5 Micro sign
&para; &#182; B6 Pilcrow sign (paragraph)
&middot; &#183; · B7 Middle dot
&cedil; &#184; ¸ B8 Cedilla
&sup1; &#185; ¹ B9 Superscript 1
&ordm; &#186; º BA Masculine ordinal indicator (superscript o)
&raquo; &#187; » BB Right angle quote
&frac14; &#188; ¼ BC One quarter fraction
&frac12; &#189; ½ BD One half fraction
&frac34; &#190; ¾ BE Three quarters fraction
¿ &#191; ¿ BF Inverted question mark
&Agrave; &#192; À C0 A grave accent
&Aacute; &#193; Á C1 A accute accent
&Acirc; &#194; Â C2 A circumflex
&Atilde; &#195; Ã C3 A tilde
&Auml; &#196; Ä C4 A umlaut
&Aring; &#197; Å C5 A ring
&AElig; &#198; Æ C6 AE ligature
&Ccedil; &#199; Ç C7 C cedilla
&Egrave; &#200; È C8 E grave
&Eacute; &#201; É C9 E acute
&Ecirc; &#202; Ê CA E circumflex
&Euml; &#203; Ë CB E umlaut
&Igrave; &#204; Ì CC I grave
&Iacute; &#205; Í CD I acute
&Icirc; &#206; Î CE I circumflex
&Iuml; &#207; Ï CF I umlaut
&ETH; &#208; Ð D0 Eth
&Ntilde; &#209; Ñ D1 N tilde (enye)
&Ograve; &#210; Ò D2 O grave
&Oacute; &#211; Ó D3 O acute
&Ocirc; &#212; Ô D4 O circumflex
&Otilde; &#213; Õ D5 O tilde
&Ouml; &#214; Ö D6 O umlaut
&times; &#215; × D7 Multiplication sign
&Oslash; &#216; Ø D8 O slash
&Ugrave; &#217; Ù D9 U grave
&Uacute; &#218; Ú DA U acute
&Ucirc; &#219; Û DB U circumflex
&Uuml; &#220; Ü DC U umlaut
&Yacute; &#221; Ý DD Y acute
&THORN; &#222; Þ DE Thorn
&szlig; &#223; ß DF SZ ligature
&agrave; &#224; à E0 a grave
&aacute; &#225; á E1 a acute
&acirc; &#226; â E2 a circumflex
&atilde; &#227; ã E3 a tilde
&auml; &#228; ä E4 a umlaut
&aring; &#229; å E5 a ring
&aelig; &#230; æ E6 ae ligature
&ccedil; &#231; ç E7 c cedilla
&egrave; &#232; è E8 e grave
&eacute; &#233; é E9 e acute
&ecirc; &#234; ê EA e circumflex
&euml; &#235; ë EB e umlaut
&igrave; &#236; ì EC i grave
&iacute; &#237; í ED i acute
&icirc; &#238; î EE i circumflex
&iuml; &#239; ï EF i umlaut
&eth; &#240; ð F0 eth
&ntilde; &#241; ñ F1 n tilde
&ograve; &#242; ò F2 o grave
&oacute; &#243; ó F3 o acute
&ocirc; &#244; ô F4 o circumflex
&otilde; &#245; õ F5 o tilde
&ouml; &#246; ö F6 o umlaut
&divide; &#247; ÷ F7 Division symbol
&oslash; &#248; ø F8 o slash
&ugrave; &#249; ù F9 u grave
&uacute; &#250; ú FA u acute
&ucirc; &#251; û FB u circumflex
&uuml; &#252; ü FC u umlaut
&yacute; &#253; ý FD y acute
&thorn; &#254; þ FE thorn
&yuml; &#255; ÿ FF y umlaut

RewriteEngine On
# these 2 lines takes requests on port 80 the default (not encypted) and forwards them to https://
RewriteCond %{SERVER_PORT} ^80
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R,L]

# these 2 lines add www to the url if it isn’t there
RewriteCond %{HTTP_HOST} ^tldomainname.com
RewriteRule ^(.*)$ https://www.tldomainname.com/$1 [R=permanent,L]

The only thing to do in the .fla is add “StarterClass” in the Document Class field under properties or under Publish Settings > Flash > Settings >Document Class. The actionscript has to be Version 3.

package {

import flash.display.MovieClip;

public class StarterClass extends MovieClip {

public function StarterClass() {

trace(“Starter class…..√ check”);

myMethod();

}

private function myMethod():void {

trace(“myMethod……….√ check”);

}

}

}

starter_class.zip

Mysql toggle a field value

Apr, 4 -- Categories: MySQL

UPDATE `my_table` SET `my_field` = (SELECT CASE `my_field` WHEN ‘1’ THEN ‘0’ ELSE ‘1’ END) WHERE `my_table_ID_Field` = ‘1’

UPDATE `my_table` SET `my_other_field` = (SELECT CASE `my_other_field` WHEN ‘foo’ THEN ‘bar’ ELSE ‘foo’ END) WHERE `my_table_ID_Field` = ‘1’

Here is the test table

CREATE TABLE `my_table` (
  `my_table_ID_Field` int(11) NOT NULL auto_increment,
  `my_field` int(11) NOT NULL,
  `my_other_field` varchar(64) NOT NULL,
  PRIMARY KEY (`my_table_ID_Field`)
);

——Dumping data for table `my_table`—

INSERT INTO `my_table` VALUES(1, 0, ‘foo’);