วันจันทร์ที่ 9 ธันวาคม พ.ศ. 2556

How can I fix a locale warning from perl?

# Setting for the new UTF-8 terminal support in Lion
export LC_CTYPE=en_US.UTF-8
export LC_ALL=en_US.UTF-8
# Setting for the new UTF-8 terminal support in Lion
LC_CTYPE=en_US.UTF-8
LC_ALL=en_US.UTF-8

วันอาทิตย์ที่ 1 กันยายน พ.ศ. 2556

how to set cornerRadius for only top-left and top-right corner of a UIView

Here's a method - I'm sure it could be shortened.... :D
-(UIView *)roundCornersOnView:(UIView *)view onTopLeft:(BOOL)tl topRight:(BOOL)tr bottomLeft:(BOOL)bl bottomRight:(BOOL)br radius:(float)radius {

UIRectCorner corner; //holds the corner


//Determine which corner(s) should be changed
if (tl) {
    corner = UIRectCornerTopLeft;
}
if (tr) {
    corner = UIRectCornerTopRight;
}
if (bl) {
    corner = UIRectCornerBottomLeft;
}
if (br) {
    corner = UIRectCornerBottomRight;
}
if (tl && tr) { //top
    corner = UIRectCornerTopRight | UIRectCornerTopLeft;
}
if (bl && br) { //bottom
    corner = UIRectCornerBottomLeft | UIRectCornerBottomRight;
}
if (tl && bl) { //left
    corner = UIRectCornerTopLeft | UIRectCornerBottomLeft;
}
if (tr && br) { //right
    corner = UIRectCornerTopRight | UIRectCornerBottomRight;
}

if (tl & tr & bl & br) {
    corner = UIRectCornerAllCorners; 
}

UIView *roundedView = view;
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:roundedView.bounds byRoundingCorners:corner cornerRadii:CGSizeMake(radius, radius)];
CAShapeLayer *maskLayer = [CAShapeLayer layer];
maskLayer.frame = roundedView.bounds;
maskLayer.path = maskPath.CGPath;
roundedView.layer.mask = maskLayer;

return roundedView;
}
    UIButton *openInMaps = [UIButton new];
    [openInMaps setFrame:CGRectMake(15, 135, 114, 70)];
    openInMaps = (UIButton *)[self roundCornersOnView:openInMaps onTopLeft:NO topRight:NO bottomLeft:YES bottomRight:NO radius:5.0];

วันอังคารที่ 13 สิงหาคม พ.ศ. 2556

TSMessages

This framework provides an easy to use class to show little notification views on the top of the screen. (à la Tweetbot).
The notification moves from the top of the screen underneath the navigation bar and stays there for a few seconds, depending on the length of the displayed text. To dismiss a notification before the time runs out, the user can swipe it to the top or just tap it.
There are 4 different types already set up for you: Success, Error, Warning, Message (take a look at the screenshots)
It is very easy to add new notification types with a different design. Add the new type to the notificationType enum, add the needed design properties to the configuration file and set the name of the theme (used in the config file and images) in TSMessagesView.m inside the switch case.
Take a look at the Example project to see how to use this library. You have to open the workspace, not the project file, since the Example project uses cocoapods.




วันจันทร์ที่ 12 สิงหาคม พ.ศ. 2556

NJKWebViewProgress: progress for webview

NJKWebViewProgress is a progress interface library for UIWebView. Currently, UIWebView don't have official progress interface. You can implement progress bar for your in-app browser using this module.




iOS-NBUKit: Component For Working With Photos Providing A Camera View, Gallery, Image Filter View, And More

Customizable camera, assets, image editing, gallery, picker and UIKit subclasses.

faceimageview - A UIImageView clone that adjusts image content to show faces.

UIImageView clone with a catch:

FaceImageView automatically scales its image to fill the bounds and keep any faces detected in view. This can be useful if you want to display people-based dynamic content with UIViewContentModeScaleToFill but are having issues with it displaying the wrong part of the image, like the background, or someone's feet.

The class uses the CoreImage face detection APIs available in iOS 5.0 or later. This API works in many clear cases, but is not all that reliable. If no faces are detected in an image, FaceImageView defaults to centering the image, like UIImageView's behavior with UIViewContentModeScaleToFill.

A small demo app is included to try out different images and view sizes.
https://github.com/dingbat/faceimageview

RNBlurModalView



RNBlurModal adds depth to the traditional modal/alert view. Calling the view is incredibly similar to setting up and showing a UIAlertView. You can also setup your own custom views and display them with a blurry background. The goal is to truly draw the user's focus directly to your alert using natural effects. This project works on all iOS devices at all orientations with ARC.

✔Sources: https://github.com/rnystrom/RNBlurModalView

วันศุกร์ที่ 28 มิถุนายน พ.ศ. 2556

รับสอน web , mobile app

หารายได้เสริม รับสอน รับปรึกษาโปรเจคจบ( แต่ไม่ทำให้ )

Web Developer Training Courses 1:1

HTML5 : ชม. ละ 150 บาท
CSS3 : ชม. ละ 150 บาท
PHP + SQL : ชม. ละ 300 บาท
JavaScript + jQuery: ชม. ละ 300 บาท
NodeJS : ชม. ละ 300 บาท

Mobile Developer Training Courses 1:1

iOS Apps Objective-C Basic : ชม. ละ 300 บาท
iOS Apps Objective-C Adv : ชม. ละ 400 บาท
Android Apps Java Basic : ชม. ละ 300 บาท
Android Apps Java Adv : ชม. ละ 400 บาท

contact me ---- http://www.aommiez.com/ ^___^

ปล.ลืมบอก ว่าผมเข้าหัวสายแลนไม่เป็นนะครับ T_T

ปล2. ไม่รับงานที่ต้องนั่ง Onsite หรือนั่งที่บริษัท Full-Time นะครับ ด้วยเหตุผลส่วนตัว แต่ถ้า Remote ได้ ไม่มีปัญหาครับ

วันศุกร์ที่ 10 พฤษภาคม พ.ศ. 2556

RHEL / Centos 6: Install Nginx Using Yum Command

CentOS Linux v6.x user type the following command:
# wget http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm
# rpm -ivh nginx-release-centos-6-0.el6.ngx.noarch.rpm

RHEL v6.x user type the following command:
# wget http://nginx.org/packages/rhel/6/noarch/RPMS/nginx-release-rhel-6-0.el6.ngx.noarch.rpm
# rpm -ivh nginx-release-rhel-6-0.el6.ngx.noarch.rpm
Type the following yum command to install nginx web-server:
# yum install nginx

Step #3: Turn on nginx service

Type the following command:
# chkconfig nginx on

How do I start / stop / restart nginx web-server?

Type the following commands:
# service nginx start
# service nginx stop
# service nginx restart
# service nginx status
# service nginx reload

Step #4: Configuration files

  1. Default configuration directory: /etc/nginx/
  2. Default SSL and vhost config directory: /etc/nginx/conf.d/
  3. Default log file directory: /var/log/nginx/
  4. Default document root directory: /usr/share/nginx/html
  5. Default configuration file: /etc/nginx/nginx.conf
  6. Default server access log file: /var/log/nginx/access.log
  7. Default server access log file: /var/log/nginx/error.log
To edit the nginx configuration file, enter:
# vi /etc/nginx/nginx.conf
Set or update worker_processes as follows (this must be set to CPU(s) in your system. Use thelscpu | grep '^CPU(s)' command to list the number of CPUs in the server)
worker_processes  2;
Turn on gzip support:
gzip  on;
Save and close the file. Edit the file /etc/nginx/conf.d/default.conf, enter:
# vi /etc/nginx/conf.d/default.conf
Set IP address and TCP port number:
    listen       202.54.1.1.1:80;
Set server name:
    server_name  www.cyberciti.biz;
Save and close the file. Start the server:
# service nginx start
Verify that everything is working:
# netstat -tulpn | grep :80
# ps aux | grep nginx

Firewall configuration: Open TCP port # 80

Edit the file /etc/sysconfig/iptables, enter:
# vi /etc/sysconfig/iptables
Add the following lines, ensuring that they appear before the final LOG and DROP lines for the INPUT chain to open port 80:
 
-A INPUT -m state --state NEW -p tcp --dport 80 -j ACCEPT
 
Save and close the file. Finally, restart the firewall:
# service iptables restart

http://www.cyberciti.biz/faq/install-nginx-centos-rhel-6-server-rpm-using-yum-command/

วันพฤหัสบดีที่ 25 เมษายน พ.ศ. 2556

centos 6 change repos thai

vi /etc/yum.repos.d/CentOS-Base.repo


[base]
name=CentOS-$releasever - Base
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
baseurl=http://mirror1.ku.ac.th/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
enabled = 1
#released updates
[updates]
name=CentOS-$releasever - Updates
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
baseurl=http://mirror1.ku.ac.th/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
enabled = 1
#additional packages that may be useful
[extras] name=CentOS-$releasever - Extras
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
baseurl=http://mirror1.ku.ac.th/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
enabled = 1
yum -v  repolist

centos config ip ,dns, gateway


Setup a default Gateway

vi /etc/sysconfig/network

NETWORKING=yes
NETWORKING_IPV6=yes
HOSTNAME=wan.nixcraft.in
GATEWAY=74.86.49.129


vi /etc/sysconfig/network-scripts/ifcfg-eth0

DEVICE="eth0"
HWADDR=specifc mac address
NM_CONTROLLED="no"
ONBOOT="yes"
BOOTPROTO="static"
IPADDR=ip address here.
NETMASK=netmask here.

vi /etc/resolv.conf

nameserver 8.8.8.8
nameserver 8.8.4.4


/etc/init.d/network restart

วันอาทิตย์ที่ 24 มีนาคม พ.ศ. 2556

nodejs mongo connect sample

var mongo = require('mongodb');


// Setup MongoDB
var Db = new mongo.Db(config.mongo.db, new mongo.Server(config.mongo.host, config.mongo.port, {auto_reconnect : true}), {});


Db.open(function(err,res){
        Db.authenticate('user', 'password', function(err, res) {
            if(res){
                console.log("Database opened");
            } else{
                console.log(err);
            }
        });
    });

Db.close();

nodejs mysql sample

var mysql = require("mysql");


var connection = mysql.createConnection({
    host: config.mysql.host,
    port: config.mysql.port,
    user: config.mysql.user,
    password: config.mysql.pass,
    database: config.mysql.db
});


connection.connect(function(error, results) {
    if(error) {
        console.log('Connection Error: ' + error.message);
        return;
    }
    console.log('Connected to MySQL');
});

connection.end();



connection.connect();

connection.query('SELECT 1 + 1 AS solution', function(err, rows, fields) {
  if (err) throw err;

  console.log('The solution is: ', rows[0].solution);
});

connection.end();


วันศุกร์ที่ 22 มีนาคม พ.ศ. 2556

nodejs validator

node-validator is a library of string validation, filtering and sanitization methods.
To install node-validator, use npm:
$ npm install validator
To use the library in the browser, include validator-min.js

Example

var check = require('validator').check,
    sanitize = require('validator').sanitize

//Validate
check('test@email.com').len(6, 64).isEmail();        //Methods are chainable
check('abc').isInt();                                //Throws 'Invalid integer'
check('abc', 'Please enter a number').isInt();       //Throws 'Please enter a number'
check('abcdefghijklmnopzrtsuvqxyz').is(/^[a-z]+$/);

//Sanitize / Filter
var int = sanitize('0123').toInt();                  //123
var bool = sanitize('true').toBoolean();             //true
var str = sanitize(' \t\r hello \n').trim();       //'hello'
var str = sanitize('aaaaaaaaab').ltrim('a');         //'b'
var str = sanitize(large_input_str).xss();
var str = sanitize('&lt;a&gt;').entityDecode();      //'<a>'

Web development

Often it's more desirable to check or automatically sanitize parameters by name (rather than the actual string). See this gist for instructions on binding the library to the request prototype.
If you are using the express.js framework you can use the express-validator middleware to seamlessly integrate node-validator.
Example http://localhost:8080/?zip=12345&foo=1&textarea=large_string
get('/', function (req, res) {
    req.onValidationError(function (msg) {
        //Redirect the user with error 'msg'
    });

    //Validate user input
    req.check('zip', 'Please enter a valid ZIP code').len(4,5).isInt();
    req.check('email', 'Please enter a valid email').len(6,64).isEmail();
    req.checkHeader('referer').contains('localhost');

    //Sanitize user input
    req.sanitize('textarea').xss();
    req.sanitize('foo').toBoolean();

    //etc.
});

List of validation methods

is()                            //Alias for regex()
not()                           //Alias for notRegex()
isEmail()
isUrl()                         //Accepts http, https, ftp
isIP()
isAlpha()
isAlphanumeric()
isNumeric()
isHexadecimal()
isHexColor()                    //Accepts valid hexcolors with or without # prefix
isInt()                         //isNumeric accepts zero padded numbers, e.g. '001', isInt doesn't
isLowercase()
isUppercase()
isDecimal()
isFloat()                       //Alias for isDecimal
notNull()
isNull()
notEmpty()                      //i.e. not just whitespace
equals(equals)
contains(str)
notContains(str)
regex(pattern, modifiers)       //Usage: regex(/[a-z]/i) or regex('[a-z]','i')
notRegex(pattern, modifiers)
len(min, max)                   //max is optional
isUUID(version)                 //Version can be 3 or 4 or empty, see http://en.wikipedia.org/wiki/Universally_unique_identifier
isDate()                        //Uses Date.parse() - regex is probably a better choice
isAfter(date)                   //Argument is optional and defaults to today. Comparison is non-inclusive
isBefore(date)                  //Argument is optional and defaults to today. Comparison is non-inclusive
isIn(options)                   //Accepts an array or string
notIn(options)
max(val)
min(val)
isArray()
isCreditCard()                  //Will work against Visa, MasterCard, American Express, Discover, Diners Club, and JCB card numbering formats

List of sanitization / filter methods

trim(chars)                     //Trim optional `chars`, default is to trim whitespace (\r\n\t )
ltrim(chars)
rtrim(chars)
ifNull(replace)
toFloat()
toInt()
toBoolean()                     //True unless str = '0', 'false', or str.length == 0
toBooleanStrict()               //False unless str = '1' or 'true'
entityDecode()                  //Decode HTML entities
entityEncode()
escape()                        //Escape &, <, >, and "
xss()                           //Remove common XSS attack vectors from user-supplied HTML
xss(true)                       //Remove common XSS attack vectors from images

Extending the library

When adding to the Validator prototype, use this.str to access the string and this.error(this.msg || default_msg) when the string is invalid
var Validator = require('validator').Validator;
Validator.prototype.contains = function(str) {
    if (!~this.str.indexOf(str)) {
        this.error(this.msg || this.str + ' does not contain ' + str);
    }
    return this; //Allow method chaining
}
When adding to the Filter (sanitize) prototype, use this.str to access the string and this.modify(new_str) to update it
var Filter = require('validator').Filter;
Filter.prototype.removeNumbers = function() {
    this.modify(this.str.replace(/[0-9]+/g, ''));
    return this.str;
}

Error handling

By default, the validation methods throw an exception when a check fails
try {
    check('abc').notNull().isInt()
} catch (e) {
    console.log(e.message); //Invalid integer
}
To set a custom error message, set the second param of check()
try {
    check('abc', 'Please enter a valid integer').notNull().isInt()
} catch (e) {
    console.log(e.message); //Please enter a valid integer
}
To attach a custom error handler, set the error method of the validator instance
var Validator = require('validator').Validator;
var v = new Validator();
v.error = function(msg) {
    console.log('Fail');
}
v.check('abc').isInt(); //'Fail'
You might want to collect errors instead of throwing each time
Validator.prototype.error = function (msg) {
    this._errors.push(msg);
    return this;
}

Validator.prototype.getErrors = function () {
    return this._errors;
}

var validator = new Validator();

validator.check('abc').isEmail();
validator.check('hello').len(10,30);

var errors = validator.getErrors(); // ['Invalid email', 'String is too small']

Contributors

  • PING - Fixed entity encoding
  • Dan VerWeire - Modified the behaviour of the error handler
  • ctavan - Added isArray and isUUID()
  • foxbunny - Added min(), max(), isAfter(), isBefore(), and improved isDate()
  • oris - Added in()
  • mren - Decoupled rules