Thursday, April 14, 2016
Saturday, December 26, 2015
بکش تا بروز شه (SwipeRefreshLayout)
قدم اول: اضافه کردن support library v4
کد زیر رو به gradle اضافه می کنیم
dependencies {
…
compile ‘com.android.support:support-v4:23.1.0’
…
}
قدم دوم: اضافه کردن SwipeRefreshLayout به Layout
android:id=”@+id/swipe_refresh”
android:layout_width=”match_parent”
android:layout_height=”wrap_content”>
android:id=”@+id/recycler_view”
android:layout_width=”match_parent”
android:layout_height=”match_parent” />
قدم سوم: نمایش SwipeRefresh در هنگام لود
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
swipeRefresh.setRefreshing(true);
}
}, ۱۰۰);
قدم چهارم: پیاده سازیه OnRefreshListener
swipeRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
//دریافت داده ها از سرور
}
});
قدم آخر: تغییر رنگ SwipeRefreshLayout
swipeRefresh.setColorSchemeResources(R.color.accent);
Thursday, August 20, 2015
یکسری وب سایت و ابزار بدرد بخور برای اندروید کارا
آموزشی
- Context, What Context: این مطلب در رابطه با انواع کانتکست های اندرویده و اینکه از هر کدومشون کجا باید استفاده و کجا نباید استفاده کرد.
- Android Material Design Slidenerd Style: آموزش فوق العاده کاربردی در رابطه با طراحی متریال دیزاین.
- Context, What Context: این مطلب در رابطه با انواع کانتکست های اندرویده و اینکه از هر کدومشون کجا باید استفاده و کجا نباید استفاده کرد.
- Android Material Design Slidenerd Style: آموزش فوق العاده کاربردی در رابطه با طراحی متریال دیزاین.
ابزارها
- Android Asset Studio: یه ابزاره حسابیه برای درست کردن انواع آیکون ها مثل آیکن اعلان، اکشن بار، لانچر و ...
- DP/PX Convertor: تبدیل DP، پیکسل، اینچ و ... به هم
- App Mirror: مجموعه ای کامل از اپلیکشن های اندرویده که به راحتی قابله دانلود روی مرورگر هست
- Mocking Bot: یه وب سایت خوب و رایگان برای درست کردن ماک برنامه
- Android Asset Studio: یه ابزاره حسابیه برای درست کردن انواع آیکون ها مثل آیکن اعلان، اکشن بار، لانچر و ...
- DP/PX Convertor: تبدیل DP، پیکسل، اینچ و ... به هم
- App Mirror: مجموعه ای کامل از اپلیکشن های اندرویده که به راحتی قابله دانلود روی مرورگر هست
- Mocking Bot: یه وب سایت خوب و رایگان برای درست کردن ماک برنامه
کتابخانه ها (Library)
- ButterKnife: یه کامپونته خیلی خفن که تو همه پروژه ها ازش استفاده می کنم، کارش اینه که ویجت ها (TextView, Button , ...) رو با یه خط انوتیت (Annotate) می شه وارد کرد به اکتیویتی یا فرگمنت، حتما توصیه می کنم یه چک بکنین
- ASNE: یه کتابخانه کامل برای کار با شبکه های اجتماعی مثل: Twitter, Linkedin, Google Plus, Facebook, Instagram , ...
- timber: یه لاگر فوق العاده کاربردی نسبت به Log کلاس پیش فرض اندروید، با این کتابخانه می تونید لاگ های دیباگ و ورباس (Timber.d , Timber.v) رو تو نسخه نهایی غیر فعال کنید و لاگ های ارور و هشدار (Timber.e , Timber.w) رو از طریق exception reporter (مثل google analytics) ارسال کنید برای خودتون.
- Android-Iconics : تو اندروید یکی از سخت ترین کارا اضافه کردن آیکونه، این کتابخونه با استفاده از فونت های آیکونی با جاش این مشکل رو حل کرده.
- ButterKnife: یه کامپونته خیلی خفن که تو همه پروژه ها ازش استفاده می کنم، کارش اینه که ویجت ها (TextView, Button , ...) رو با یه خط انوتیت (Annotate) می شه وارد کرد به اکتیویتی یا فرگمنت، حتما توصیه می کنم یه چک بکنین
- ASNE: یه کتابخانه کامل برای کار با شبکه های اجتماعی مثل: Twitter, Linkedin, Google Plus, Facebook, Instagram , ...
- timber: یه لاگر فوق العاده کاربردی نسبت به Log کلاس پیش فرض اندروید، با این کتابخانه می تونید لاگ های دیباگ و ورباس (Timber.d , Timber.v) رو تو نسخه نهایی غیر فعال کنید و لاگ های ارور و هشدار (Timber.e , Timber.w) رو از طریق exception reporter (مثل google analytics) ارسال کنید برای خودتون.
- Android-Iconics : تو اندروید یکی از سخت ترین کارا اضافه کردن آیکونه، این کتابخونه با استفاده از فونت های آیکونی با جاش این مشکل رو حل کرده.
پلاگین برای اندروید استادیو
- ParcelableGenerator: برای تولید Parcelable اندروید، کلاس رو بسازید، فیلد ها رو بهش اضافه کنید بعدش کلید میانبر ALT + Insert رو بزنید و گزینه Parcelable رو انتخاب کنید. :D
- ADB Idea: یه میانبر خوب برای اجرای دستورات پر کاربرد بر روی گوشی ای که به سیستم وصله، دستوراتی مثل حذف نرم افزار، بستن نرم افزار، پاک کردن کش، و اجرای مجدد نرم افزار
این مجموعه در حال تکمیله اگه شما هم ابزار بدرد بخوری می شناسید معرفی کنید
- ParcelableGenerator: برای تولید Parcelable اندروید، کلاس رو بسازید، فیلد ها رو بهش اضافه کنید بعدش کلید میانبر ALT + Insert رو بزنید و گزینه Parcelable رو انتخاب کنید. :D
- ADB Idea: یه میانبر خوب برای اجرای دستورات پر کاربرد بر روی گوشی ای که به سیستم وصله، دستوراتی مثل حذف نرم افزار، بستن نرم افزار، پاک کردن کش، و اجرای مجدد نرم افزار
Monday, June 29, 2015
OpenJDK VS Oracle JDK
مشکلی که همیشه موقع نصب جاوا برام پیش میاد اینه که اوپن JDK رو کارایی بهتری داره و یا اوراکل JDK، این دفعه مشکل رو با کمی تحقیق حل کردم:
هنریک استال معاون مدیریت اجرایی گروه جاوا تو شرکت اوراکل در این رابطه نوشته (متن به صورت خلاصه ترجمه شده):
این دو بسیار به هم شبیه اند، برای ایجاد نسخه ی اوراکل JDK تنها چند تکه به آن اضافه می کنیم،
به طور مثال:
- پلاگین جاوا (اجرا کننده ی Applet ها) و وب استارت (اجرا کننده ی نرم افزار جاوا به صورت یک کلیک)
- یکسری از کامپوننت های کد بسته دیگر شرکت ها مثل graphics rasterizer و بعضی از فونت های استفاده شده
- یکسری از کامپوننت های کد باز دیگر شرکت ها مثل Rhino ( راینو: موتور جاوا اسکریپت که به طور کامل با جاوا پیاده سازی شده است و توسط شرکت موزیلا توسعه داده می شود)
در ادامه هنریک نوشته : نیت ما کد باز کردن تمامی قسمت های اوراکل JDK هست به جز قسمت هایی که دارای امکانات تجاری هستند مثل Jrockit Mission Control (ابزاری برای مانیتور کردن و پروفایل کردن نرم افزار های جاوا که هنوز این محصول از طرف اوراکل ارائه نشده) باقی قسمت ها با کامپوننت های متن باز جابه جا خواهند شد.
طبق گفته این دوست عزیز از نظر کارایی تفاوت چندانی نمی کنه که از کدام JDK استفاده کنیم، برای همین من ترجیح می دم از اوپن JDKاستفاده بکنم که هم کد بازه و هم با یک دستور تو اوبونتو نصب می شه
sudo apt-get install openjdk-8-jdk
Thursday, February 19, 2015
کتابخانه کار با رابط درگاه اینترنتی بانک ملت برای جاوا
برای کار با درگاه بانک ملت یه کتابخانه (یا همون library) با IntelliJ IDEA درست کردم، گفتم اینجا بزارم تا بقیه هم بتونن استفاده کنند.
کار با این کتابخانه خیلی راحته، نمونه کد زیر از متد bpPayRequest بانک ملت استفاده می کنه و در خواست تراکنش رو برای بانک ارسال می کنه. مابقی API های بانک ملت همانند مثال زیر یک متد دارند با یکسری پارامتر های ورودی و خروجی معین شده توسط خود بانک ملت.
IPaymentGateway service = new PaymentGatewayImplService().getPaymentGatewayImplPort();
String response = service.bpPayRequest(
12,
"USER NAME",
"PASSWORD",
mellatBank.getId() ,
mellatBank.getPrice(),
mellatBank.getLocalDate(),
mellatBank.getLocalTime(),
"",
"response url",
0
);
از این کتابخانه برای سایت آنلاین دارو استفاده کردم
اینم لینک دانلود کتابخانه
Labels:
API,
بانک ملت,
جاوا,
درگاه اینترنتی,
درگاه بانک,
کتابخانه,
نمونه کد
Thursday, December 11, 2014
Bad Smells in Code
Duplicated Code
If you see the same code structure in more than one place, you can be sure that your program will be better if you find a way to unify them.
Long Method
The object programs that live best and longest are those with short methods.
There is still an overhead to the reader of the code because you have to switch context to see what the sub procedure does. Development environments that allow you to see two methods at once help to eliminate this step, but the real key to making it easy to understand small methods is good naming. If you have a good name for a method you don't need to look at the body.
There is still an overhead to the reader of the code because you have to switch context to see what the sub procedure does. Development environments that allow you to see two methods at once help to eliminate this step, but the real key to making it easy to understand small methods is good naming. If you have a good name for a method you don't need to look at the body.
Large Class
When a class is trying to do too much, it often shows up as too many instance variables. When a class has too many instance variables, duplicated code cannot be far behind.
Long Parameter List
In our early programming days we were taught to pass in as parameters everything needed by a routine. This was understandable because the alternative was global data, and global data is evil and usually painful. Objects change this situation because if you don't have something you need, you can always ask another object to get it for you. Thus with objects you don't pass in everything the method needs; instead you pass enough so that you the method can get to everything it needs.
Divergent Change
Divergent change occurs when one class is commonly changed in different ways for different reasons.
Shotgun Surgery
Shotgun surgery is similar to divergent change but is the opposite. You whiff this when every time you make a kind of change, you have time to make a lot of little changes to a lot of different classes. When the changes are all over the place, they are hard to find, and it's easy to miss an important change.
Feature Envy
The whole point of objects is that they are a technique to package data with the processes used on that data. A classic smell is a method that seems more interested in a class other than the one it actually is in.
Data Clumps
Data items tend to be like children; they enjoy hanging around in groups together. Often you'll see the same three or four data items together in lots of places: fields in a couple of classes, parameters in many method signatures.Bunches of data that hang around together really ought to be made into their own object.
Primitive obsession
You use primitives in the system to pass data, rather than objects, and it gets in the way of understanding the code. Eg. passing arrays everywhere.
Switch Statements
One of the most obvious symptoms of object-oriented code is its comparative lack of switch (or case) statements. The problem with switch statements is essentially that of duplication. Often you find the same switch statement scattered about a program in different places.The object-oriented notion of polymorphism gives you an elegant way to deal with this problem.
Parallel Inheritance Hierarchies
Parallel inheritance hierarchies is really a special case of shotgun surgery. In this case, every time you make a subclass of one class, you also have to make a subclass of another. You can recognize this smell because the prefixes of the class names in one hierarchy are the same as the prefixes in another hierarchy.
Lazy Class
Each class you create costs money to maintain and understand. A class that isn't doing enough to pay for itself should be eliminated. Often this might be a class that used to pay its way but has been downsized with refactoring. Or it might be a class that was added because of changes that were planned but not made. Either way, you let the class die with dignity.
Speculative Generality
You get it when people say, "Oh, I think we need the ability to this kind of thing someday" and thus want all sorts of hooks and special cases to handle things that aren't required. The result often is harder to understand and maintain.
Temporary Field
Sometimes you see an object in which an instance variable is set only in certain circumstances. Such code is difficult to understand, because you expect an object to need all of its variables. Trying to understand why a variable is there when it doesn't seem to be used can drive you nuts.
Message Chains
You see message chains when a client asks one object for another object, which the client then asks for yet another object, which the client then asks for yet another another object, and so on. You may see these as a long line of getThis methods, or as a sequence of temps. Navigating this way means the client is coupled to the structure of the navigation. Any change to the intermediate relationships causes the client to have to change.
Middle Man
One of the prime features of objects is encapsulation—hiding internal details from the rest of the world. Encapsulation often comes with delegation. You ask a director whether she is free for a meeting; she delegates the message to her diary and gives you an answer. All well and good. There is no need to know whether the director uses a diary, an electronic gizmo, or a secretary to keep track of her appointments.
However, this can go too far. You look at a class's interface and find half the methods are delegating to this other class. After a while it is time to use Remove Middle Man and talk to the object that really knows what's going on.
However, this can go too far. You look at a class's interface and find half the methods are delegating to this other class. After a while it is time to use Remove Middle Man and talk to the object that really knows what's going on.
Inappropriate Intimacy
Sometimes classes become far too intimate and spend too much time delving in each others private parts. We may not be prudes when it comes to people, but we think our classes should follow strict, puritan rules.
Data Class
These are classes that have fields, getting and setting methods for the fields, and nothing else. Such classes are dumb data holders and are almost certainly being manipulated in far too much detail by other classes. In early stages these classes may have public fields. If so, you should immediately apply Encapsulate Field before anyone notices.
Refused Bequest
Subclasses get to inherit the methods and data of their parents. But what if they don't want or need what they are given? They are given all these great gifts and pick just a few to play with. The traditional story is that this means the hierarchy is wrong.
Comments
Don't worry, we aren't saying that people shouldn't write comments. In our olfactory analogy, comments aren't a bad smell; indeed they are a sweet smell. The reason we mention comments here is that comments often are used as a deodorant. It's surprising how often you look at thickly commented code and notice that the comments are there because the code is bad. Comments lead us to bad code that has all the rotten whiffs we've discussed in the rest of this chapter.
If you need a comment to explain what a block of code does, try Extract Method. If the method is already extracted but you still need a comment to explain what it does, use Rename Method. If you need to state some rules about the required state of the system, use Introduce Assertion.
Summary of the "Refactoring: Improving the Design of Existing Code"
If you need a comment to explain what a block of code does, try Extract Method. If the method is already extracted but you still need a comment to explain what it does, use Rename Method. If you need to state some rules about the required state of the system, use Introduce Assertion.
Summary of the "Refactoring: Improving the Design of Existing Code"
Saturday, October 4, 2014
Code Refactoring
What Is Refactoring ?
Refactoring is the process of changing a software system in such a way that it does not alter the external behavior of the code yet improves its internal structure. It is a disciplined way to clean up code that minimizes the chances of introducing bugs. In essence when you refactor you are improving the design of the code after it has been written.
Tip: When you find you have to add a feature to a program, and the program's code is not structured in a convenient way to add the feature, first refactor the program to make it easy to add the feature, then add the feature.
The First Step in Refactoring
Whenever I do refactoring, the first step is always the same. I need to build a solid set of tests for that section of code. The tests are essential because even though I follow refactorings structured to avoid most of the opportunities for introducing bugs, I'm still human and still make mistakes. Thus I need solid tests.
Tip: Any fool can write code that a computer can understand. Good programmers write code that humans can understand.
Why Should You Refactor?
I don't want to proclaim refactoring as the cure for all software ills. It is no "silver bullet." Yet it is a valuable tool, a pair of silver pliers that helps you keep a good grip on your code. Refactoring is a tool that can, and should, be used for several purposes.
Refactoring Helps You Find Bugs
Help in understanding the code also helps me spot bugs. I admit I'm not terribly good at finding bugs. Some people can read a lump of code and see bugs, I cannot.
However, I find that if I refactor code, I work deeply on understanding what the code does, and I put that new understanding right back into the code. By clarifying the structure of the program, I clarify certain assumptions I've made, to the point at which even I can't avoid spotting the bugs.
It reminds me of a statement Kent Beck often makes about himself, "I'm not a great programmer; I'm just a good programmer with great habits." Refactoring helps me be much more effective at writing robust code.
Refactoring Helps You Program Faster
This sounds counterintuitive. When I talk about refactoring, people can easily see that it improves quality. Improving design, improving readability, reducing bugs, all these improve quality. But doesn't all this reduce the speed of development
I strongly believe that a good design is essential for rapid software development.
I strongly believe that a good design is essential for rapid software development.
Indeed, the whole point of having a good design is to allow rapid development. Without a good design, you can progress quickly for a while, but soon the poor design starts to slow you down. You spend time finding and fixing bugs instead of adding new function.
Changes take longer as you try to understand the system and find the duplicate code. New features need more coding as you patch over a patch that patches a patch on the original code base. A good design is essential to maintaining speed in software development. Refactoring helps you develop software more rapidly, because it stops the design of the system from decaying. It can even improve a design.
When Should You Refactor
In almost all cases, I'm opposed to setting aside time for refactoring. In my view refactoring is not an activity you set aside time to do. Refactoring is something you do all the time in little bursts. You don't decide to refactor, you refactor because you want to do something else, and refactoring helps you do that other thing.
Refactor When You Need to Fix a Bug
In fixing bugs much of the use of refactoring comes from making code more understandable. As I look at the code trying to understand it, I refactor to help improve my understanding. Often I find that this active process of working with the code helps in finding the bug. One way to look at it is that if you do get a bug report, it's a sign you need refactoring, because the code was not clear enough for you to see there was a bug.
When Shouldn't You Refactor
There are times when you should not refactor at all. The principle example is when you should rewrite from scratch instead. There are times when the existing code is such a mess that although you could refactor it, it would be easier to start from the beginning.
A clear sign of the need to rewrite is when the current code just does not work. You may discover this only by trying to test it and discovering that the code is so full of bugs that you cannot stablilize it.
A clear sign of the need to rewrite is when the current code just does not work. You may discover this only by trying to test it and discovering that the code is so full of bugs that you cannot stablilize it.
The other time you should avoid refactoring is when you are close to a deadline. At that point the productivity gain from refactoring would appear after the deadline and thus be too late.
Summary of the "Refactoring: Improving the Design of Existing Code" book
Wednesday, August 27, 2014
معرفی دو تا کتاب و یک مجله خواندنی
ماهنامه سلام دنیا
قسمتی از سخن سردبیر
یکی از بزرگترین مزایای مدل نرمافزار آزاد / متنباز و در دیدگاهی فراتر «جامعه آزاد / متنباز»، شروع حرکتهای ساده و کوچک، بر اساس نیاز جامعه است. بدین ترتیب که نیاز دیده میشود (خلق نمیشود)، گروهی دست به کار میشوند، جامعه مشارکت میکند، کیفیت روزبهروز بهبود مییابد و در نهایت همه سود میبرند. رویه مجله سلام دنیا هم همین است؛ شاید بهترین را منتشر نکرده باشیم، اما شروع کردیم و قطعا میتوانیم بهتر شویم.
فقط برای تفریح
داستان یک انقلابی اتفاقی
این کتاب، نوشته لینوس توروالدز خالق لینوکس و دیوید دیاموند است. یک خبرنگار مدت ها با لینوس وقت گذرونده و حرف هاش رو شنیده و نتیجه اش شده این کتاب که با نام انگلیسی Just For Fun توسط انتشارات TEXERE منتشر شده.وب سایت کتاب
دریافت فایل پی دی اف کتاب

دنیای قشنگ نو
آلدوس هاکسلی
دنیایِ قشنگ نو یا دنیای شگفت انگیز جدید (به انگلیسی: Brave New World) یک رمان علمی-تخیلی پادآرمانی (Dystopian) است که در سال ۱۹۳۲ به قلم آلدوس هاکسلی نویسنده و شاعر انگلیسی منتشر شده است. وقایع این رمان در سال ۲۵۴۰ در شهر لندن می گذرد و آرمانشهری را به تصویر می کشد که در آن مهندسی ژنتیک به آفرینش انسانها با ویژگی های از پیش تعیین شده منجر شده، نظام اخلاقی جامعه با تشکیل حکومت جهانی و از میان بردن جنگ و فقر و نابودی کامل خانواده و تولید مثل به کلی پوست انداخته و دانش روان شناسی به طرز حیرت انگیزی اعتلا یافته و تنها هدف انسان ایجاد سعادت و از میان بردن رنج های غیر ضروری ست.دریافت فایل پی دی اف کتاب
Tuesday, August 19, 2014
جابه جایی پورت در لینوکس یا Port Forwarding
به کمک iptables لینوکس می خوایم یک پورت مشخص مثل 9090 رو به یه آدرس ای پی و پورت مشخص دیگه وصل کنیم.
با Port Forwarding کار های زیادی می شه انجام داد مثل :
با Port Forwarding کار های زیادی می شه انجام داد مثل :
- جدا کردن سرور آپاچی و سرور دیتابیس (Load Balancing)
- در مواقعی که فیلتر شکن ها اجازه نمی دن سرور خارجی بهمون وصل بشه با جابه جایی مبدا می شه فیلتر شکن رو گول زد
- به عنوان سرور آینه (Server Mirroring)
- و ...
برای شروع به یک سرور لینوکسی نیاز داریم،
اول از همه ip forward رو با دستور زیر فعال می کنیم :
sudo sysctl net.ipv4.ip_forward=1
حالا باید رول ها رو تنظیم کنیم :
sudo iptables -t nat -A PREROUTING -p tcp -d x.x.x.x --dport 80
-j DNAT --to-destination y.y.y.y:8014
x.x.x.x: این آدرسه خود سرور پراکسی هستش که روی پورت ۸۰ تنظیم شده
y.y.y.y: این هم آدرس کلاینتم هستش که روی پورت ۸۰۱۴ تنظیم شده
بعد از اجرا کردن دستور بالا دستور زیر رو اجرا کنید:
iptables -t nat -A POSTROUTING -j MASQUERADE
با دستور بالا مبدا رو عوض می کنیم و کلاینت ها فکر می کنن از خود سرور پراکسی ما دارن داده ها رو دریافت می کنن
تمام ، با این کار اگه به سرور x.x.x.x روی پورت 80 وصل بشیم سرور ما رو جا به جا می کنه و پاکت های ارسالی رو برای y.y.y.y روی پورت 8014 ارسال می کنه
برای دیدن لیست Rule ها دستور زیر رو بزنید:
iptables -t nat --line-numbers -L
و برای پاک کردنشون هم دستور زیر رو همراه با شماره خط دستور قبلی وارد کنید :
iptables -t nat -D PREROUTING 6
برای استفاده از روش SNAT به جایه MASQUERADE از دستور زیر استفاده کنید:
iptables -t nat -A POSTROUTING -p tcp -o eth0 -j SNAT --to-source x.x.x.x
با دستور بالا آدرس مبدا پاکت ها رو به x.x.x.x تغییر می دهیم
Tuesday, July 22, 2014
برای همیشه از شر پنجرههای System Program Problem Detected اوبونتو راحت بشین
کنونیکال تلاش زیادی می کنه تا کیفیت نسخه گنو/لینوکسش رو بالا ببره و یکی از ابزارهاش در اینکار، Apport است؛ برنامه ای برای ریپورت اتوماتیک مشکلات پیش اومده در برنامهها. چون اکثر آدمها حرفه ای نیستن و نمی دونن باید مشکلات برنامه ها رو چطوری بازتولید و ریپورت کنن، این سرویس سعی می کنه در صورت دیدن هر کرشی در هر برنامهای، اون رو در var/crash/ ذخیره و بعد ریپورت کنه. دقیقا همین دایرکتوری است که وقتی فایلی توش باشه، باعث می شه موقع بوت شدن اوبونتو شما این پنجره رو ببینین:
این پنجره ذاتا چیز بدی نیست ولی خب اکثر ما ریپورت نمی کنیم و دوست هم نداریم کامپیوترمون هی بوت شدن یکسری «ارور» بده! به همین خاطر اگر می خواین از شر این پیشنهادهای بی شرمانه ریپورت کردن راحت بشین، اول اون دایرکتوری رو خالی کنین تا دیگه موقع بوت اوبونتو پیشنهاد ریپورت نده و بعد اگر کلا می خواین هیچ وقت چیزی رو ریپورت نکنین به فایل زیر برین و اون متغیر رو از از یک به صفر تغییر بدین:
و از دست اون پنجرههای منحوس که همیشه باعث می شن من فکر کنم اوبونتوم خرابه، راحت بشین.
برگرفته شده از وبلاگ جادی
برگرفته شده از وبلاگ جادی
Monday, June 30, 2014
مقداردهی خصیصه های html در ember.js
مشکل از اینجا شروع می شه که می خواین تو ember یه خصیصه ی html رو به صورت داینامیک مقدار دهی کنید ، فکر کنید تکه کد زیر رو داخل قالب ember دارین :
<textarea placeholder="my static value"></textarea>
خب حالا می خوایم متغیر myDynamicValue رو به عنوان خصیصه ی placeholder به textarea بدیم ، شاید فکر کنید تکه کد زیر همین کار رو انجام می ده :
<textarea placeholder="{{myDynamicValue}}"></textarea>
اما کاملا در اشتباهید با تکه کد زیر می توانید این کار رو انجام بدید:
{{bindAttr <<your attribute>>="<<your value>>"}}
به عنوان مثال:
<textarea {{bindAttr placeholder="myDynamicValue"}} ></textarea>
به همین راحتی !!!!!!!!!!!
Friday, June 6, 2014
اکشن بار بر روی اندروید 2.1 به بالا (Action Bar)
اگه برای اپلیکیشن تون می خواین اکشن بار بزارین و کاربراتون از نسخه 3 به بالا استفاده می کنن با خواندن مطلب پایین در ۳ ثانیه می توانید این کارو انجام بدید.
اگه دارین این رو می خوانین یعنی باسه کاربراتون ارزش قائلید و از نسخه های 2.1 به بالا می خواین پشتیبانی کنید ، آستیناتون رو بدین بالا که یه ذره کار سخته :D . اگه دارین از Eclipse استفاده می کنید با جاش این صفحه رو ببندین و بعد از اینکه پروژه تون رو بردین رو IntelliJ IDEA یا Android Studio ادامه مطلب رو بخوانین.
1. اول از همه باید Android Support Library رو از Android sdk manager نصب کنید
1. اول از همه باید Android Support Library رو از Android sdk manager نصب کنید
2. در Intellij Idea به مسیر زیر برید:
File -> Project Structure ...
3. در قسمت Libraries دو فایل jar (داخل اندروید SDK) زیر را اضافه کنید
Sdk Path/extras/android/support/v7/appcompat/lib/android-support-v4.jar
Sdk Path/extras/android/support/v7/appcompat/lib/android-support-v7-appcompat.jar
4. در قسمت Modules ، ماژول appcompat را از مسیر زیر ایمپورت کنید و در تب Dependencies دو تا فایل jar ی که در مرحله قبل اضافه کردید رو اینجا هم اضافه کنید مثل عکس زیر
Sdk Path/extras/android/support/v7/appcompat
5. تا اینجای کار android-support-v7 رو به پروژه اضافه کردید حالا مانده ازش استفاده کنیم ، داخل فایل AndroidManifest.xml به تگ Activity (اکتیویتیه اصلیه پروژه و یا هر جایی که می خواین اکشن بار بزارین) تکه کد زیر رو وارد کنید
android:theme="@style/Theme.AppCompat.Light"
فایل AndroidManifest.xml پروژه من :
6. کلاس اکتیویتی که می خواین اکشن بار داشته باشه رو باز کنید و از کلاس ActionBarActivity ارث ببرید !! (extend کنید)
تمووم شد آورین ، برای اینکه با نحوه کار اشکن بار آشنا بشین مطلب زیر رو بخونید
Tuesday, May 27, 2014
Maven چیست ؟
Maven یک ابزار مدیریت و تعریف پروژه بر پایه مفهوم POM - Project Object Model می باشد. Maven به زبان Yiddish (زبان یهودیان اشکنازی در هزار سال پیش) بمعنی مخزن دانش می باشد.
Maven یک روش جامع برای مدیریت پروژه از زمان کامپایل تا انتشار تا مستند سازی تا همکاری تیمی فراهم می سازد ، در یک جمله Maven یک چارچوب مدیریت پروژه (Project Management Framework) می باشد.
اهداف Maven
- آسان سازی فرایند build
- فراهم سازی یک سیستم build یکپارچه
- فراهم سازی اطلاعات کیفی پروژه
- فراهم سازی دستورالعمل هایی برای استفاده مجدد از بهترین تجربه های توسعه
- امکان افزودن قابلیت های جدید به پروژه بصورت نامحسوس
Maven چه چیزی هست و چه چیزی نیست ؟ یک ابزار build نیست ، یک چارچوب اسکریپت نویسی نیست ، Maven را نمی توان با چند جمله به سادگی تشریح کرد ، Maven ترکیبی از ایده ها ، استانداردها و نرم افزار است. پس Maven چیست ؟
- مجموعه ای از استانداردهای build
- یک مدل برای مخزن محصولات (Artifact Repository) (مانند jar فایل ها)
- یک موتور نرم افزاری که وظیفه مدیریت و تعریف پروژه ها را بر عهده دارد
- تعریف یک استاندارد چرخه کار برای build ، تست و deploy خروجی پروژه
- فراهم کردن یک Framework برای استفاده مجدد از تجربیات خوب یک پروژه برای تمامی پروژه های (در قالب ایجاد plug-in)
با تشکر از دوست خوبم LUKE
منبع : barnamenevis.org
Tuesday, May 13, 2014
نصب پلاگین جاوا بر روی کروم با لینوکس اوبونتو
بعد از ۳ ۴ ساعت بالاخره تونستم پلاگین بد قلق جاوا رو روی کروم نصب کنم !! روی فایرفاکس و کرومیوم تست کردم هیچ کدومش درست نصب نمی شد البته ورژن قدیمیه فایرفاکس با IcedTea کار کرد اما کرش هم زیاد می کرد.
بعد از نصب کروم و جاوا ۸ که نحوه نصبش رو تو چند تا پست قبلی بهتون گفته بودم می رین داخل پوشه ی کروم در مسیر :
/opt/google/chrome
و پوشه ی plugins رو ایجاد می کنید :
mkdir plugins
داخل پوشه رفته و لینکی از پلاگین جاوا ایجاد می کنید :
ln -s /usr/lib/jvm/jdk1.8.0/jre/lib/amd64/libnpjp2.so .
جاوا از نسخه ی ۷ به بعد پیش فرض Security Level رو روی Very قرار داد و این یعنی اینکه یکسری از Applet ها رو اجازه ی اجرا شدن بهشون نمی ده از جمله VNC ها برای رفع این مشکل داخل پوشه جاوا رفته و پوشه bin رو باز می کنیم و دستور زیر را می زنیم
javaws -viewer
حالا یه پنجره باز می شه به نام Java Control Panel داخل تب Security می شیم و Security Level رو روی Medium می زاریم ;)
Wednesday, April 23, 2014
تنظیم کردن XDebug + Phpstorm
اول چک کنین XDebug نصب داشته باشین !!
فایل 20-xdebug.ini رو از مسیر زیر باز کنید
/etc/php5/conf.d//etc/php5/conf.d
xdebug.remote_enable=1
فایل php.ini رو باز کنید و کانفیگ زیر رو در آخر فایل اضافه کنید
[Zend]
zend_extension=""
xdebug.var_display_max_data=3000
xdebug.var_display_max_depth=30
xdebug.var_display_max_children=512
xdebug.collect_params=4
xdebug.remote_enable = 0
xdebug.remote_handler = "dbgp"
xdebug.remote_host = "127.0.0.1"
xdebug.profiler_append = 1
End:
دقت کنید ،مسیر xdebug.soی رو که یادداشت کرده بودید رو در قسمت وارد کنید
آپاچی رو یه ریستارت کنید و برید سراغ Phpstorm بعد از اجرا شدن به Project Setting رفته و در زیر منوی PHP ، بر روی Servers کلیک کنید ، مطابق با عکس زیر بر روی دکمه ی + کلیک کنید و مثل عکس تنظیم کنید:
بعد از انجام تنظیمات سرور به منوی Edit Configuration برید:
بعد از باز شدن پنجره بر روی دکمه + کلیک کنید و PHP WEB APPLICATION رو انتخاب کنید و مطابق عکس زیر تنظیم کنید:
خوووب حالا همچی تمومه یه قایل PHP باز کنید و یه Break Point بزارید و بر روی اون حشره در نوار ابزار کلیک کنید و یا از کلید ترکیبیه : Alt + Shift + D استفاده کنید و حالشوو ببرین ;)
دمه اون بچه هایی رو که بهم این مطلب رو یاد دادن گرم ;)
Tuesday, April 8, 2014
جاوا ۸ وارد می شود
جاوا ۸ در تاریخ ۱۸ مارچ ۲۰۱۴ به صورت رسمی منتشر شد ، با امکانات و پیشرفت هایی که به قول بعضی ها انقلابی در جاوا محسوب می شه.
از آنجایی که توضیح در رابطه با تمام امکانات جاوا ۸ زمان زیادی می بره به چند تا از مهمترین امکانات اشاره می کنم :
- Lambda expressions
- Java fx and new feature
- Streams
- Nashorn
Lambda Expressions
Lambda یکی از مهمترین ویژگی های جاوا ۸ محسوب می شه ، که اگه بخوام خلاصه توضیح بدم Lambda Expressions باعث سادگی و جمع و جور شدن کد می شه همین .
وقتی از Lambda استفاده می کنیم در زمان ترجمه به بایت کد ، قطعه کد lambda به یک تابع interface تبدیل می شه ، از این رو می تونیم تو نسخه های قدیمی تر جاوا هم برنامه مون را اجرا کنیم .
مثال زیر نمونه ای است از هنگامی که از Lambda Expressions استفاده می کنیم و زمانی که استفاده نمی کنیم:
وقتی از Lambda استفاده می کنیم در زمان ترجمه به بایت کد ، قطعه کد lambda به یک تابع interface تبدیل می شه ، از این رو می تونیم تو نسخه های قدیمی تر جاوا هم برنامه مون را اجرا کنیم .
مثال زیر نمونه ای است از هنگامی که از Lambda Expressions استفاده می کنیم و زمانی که استفاده نمی کنیم:
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
System.out.println(“Action Detected”);}});
public void actionPerformed(ActionEvent ae) {
System.out.println(“Action Detected”);}});
با استفاده از Lambda
button.addActionListener(e ->{
System.out.println(“Action Detected”);});
System.out.println(“Action Detected”);});
یک نمونه از استفاده از نخ ها (Thread خودمون)
Runnable runnable1 = new Runnable() {
@Override
public void run() {
System.out.println("Running without Lambda");
@Override
public void run() {
System.out.println("Running without Lambda");
با استفاده از Lambda
Runnable runnable2 = () -> { System.out.println("Running from Lambda"); };
همانطور که نگاه می کنید قطعه کدهای Lambda ساده تر و از خطوط کمتری استفاده می کنند.
سعی می کنم در آینده ای نزدیک درباره Lambda بیشتر توضیح بدم ;)
سعی می کنم در آینده ای نزدیک درباره Lambda بیشتر توضیح بدم ;)
Java fx and new feature
- اضافه شدن تم جدید Madena به java fx ، برای اطلاعات بیشتر به این لینک سر بزنید http://fxexperience.com/2013/03/modena-theme-update/
- کلاس SwingNode برای استفاده از کامپوننت های swing در java fx
- پیاده سازی بسته javafx.print برای گرفتن پرینت ، برای اطلاعات بیشتر http://docs.oracle.com/javase/8/javafx/api/javafx/print/package-summary.html
- کلاس WebView با ویژگی های جدید پیاده سازی شده و پشتیبانی از Html5 برای اطلاعات بیشتر http://docs.oracle.com/javase/8/javafx/embedded-browser-tutorial/index.html
- Java fx بر روی چیپ های Arm
Stream
stream یک ویژگی جدیده که قبلا تو زبان scala بوده و حالا به جاوا ۸ اومده ، استریم یک عملی را روی تک تک یک مجموعه اجرا می کنه ! که به دو صورت قابل استفاده است : ترتیبی و موازی مثال زیر نمونه کدی است که تمام فروشنده های تویوتا رو پیدا می کنه :
List toyotaSales;
toyotaSales = sales.filter(s -> s.getCar().getBrand().equals("Toyota"))
.collect(toList());
toyotaSales.forEach(System.out::println);
Nashorn
جاوا ۸ به ما این امکان رو داده تا بتوانیم کد های جاوا اسکریپت رو در JVM اجرا کنیم ، این یعنی اینکه شما می توانید در سمت سرور هم کد جاوا اسکریپت اجرا کنید و حالشو ببرید چیزی شبیه Node.js . که البته این امکان کاربرد های زیادی داره مثلا شما می تونید کد اعتبارسنج سمت کلاینت رو سمت سرور نیز اجرا کنید و امنیتتون رو بالا ببرید . خیلی جالبه هنوز جاوا ۸ نیومده Intellij یه دیباگر باسه کدهای جاوا اسکریپت تو جاواتون داده !!
یه مثال کوچولو از اجرای جاوا اسکریپت در جاوا :
یه مثال کوچولو از اجرای جاوا اسکریپت در جاوا :
ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine engine = manager.getEngineByName("nashorn");
String js="";
js += "print('Salam Java 8 !!');";
engine.eval(js);
از لینک زیر می توانید امکانات جدید جاوا ۸ رو در سایت اوراکل ببینید:
برای دانلود جاوا و اطلاعات بیشتر هم به لینک زیر برید:
Saturday, March 29, 2014
نصب Oracle JDK 8 بر روی اوبونتو
- در مرحله اول به لینک زیر می رویم و JDK لینوکس ۶۴ بیت یا ۳۲ بیت با فرمت Tar.gz را دریافت می کنیم ، البته یادتون نره که باید فیلتر شکن داشته باشید
- فایل دانلود شده را از حالت فشرده خارج می کنیم
- بعد از خارج کردن فایل از حالت فشرده فولدرd داریم به نام jdk1.8.0 که باید به مسیر /usr/lib/jvm/ انتقال دهیم ، در صورتی که پوشه ی jvm رو ندارید باید با دستور زیر بسازید
- فولدر jdk1.8.0 را به مسیر /usr/lib/jvm انتقال می دهیم
- برای اینکه Oracle Jdk 8 پیش فرض سیستم شود دستور های زیر را اجرا کنید
- با دستور زیر دسترسی های مورد نیاز جاوا رو بهش می دهیم
- دستور زیر را اجرا می کنیم
tar -xvf jdk-8-linux-i586.tar.gz (32bit)
tar -xvf jdk-8-linux-x64.tar.gz (64bit)
sudo mkdir -p /usr/lib/jvm
sudo mv ./jdk1.8.0 /usr/lib/jvm
sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.8.0/bin/java" 1
sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/jdk1.8.0/bin/javac" 1
sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/lib/jvm/jdk1.8.0/bin/javaws" 1
sudo chmod a+x /usr/bin/java
sudo chmod a+x /usr/bin/javac
sudo chmod a+x /usr/bin/javaws
sudo chown -R root:root /usr/lib/jvm/jdk1.8.0
sudo update-alternatives --config java
با اجرای دستور بالا لیستی مثل لیست زیر حواهیم داشت
There are 3 choices for the alternative java (providing /usr/bin/java).
Selection Path Priority Status
------------------------------------------------------------
0 /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java 1071 auto mode
1 /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java 1071 manual mode
* 2 /usr/lib/jvm/jdk1.7.0/bin/java 1 manual mode
3 /usr/lib/jvm/jdk1.8.0/bin/java 1 manual mode
شماره ی جاوا ۸ رو انتخاب می کنیم و دو تا دستور زیر را همانند دستور بالا اجرا می کنیم
sudo update-alternatives --config javac
sudo update-alternatives --config javaws
تمام شد حالا از کد نویسی با جاوا ۸ لذت ببرید ;)
Saturday, March 22, 2014
I NEED YOU NOW !
ترجمه آهنگ I need you now از گروه Lady Antebellum حالشو ببرین
Pictures perfect memories Scatted all around the floor
عکس های بهترین خاطره هامون روی زمین پخشه
Reaching for the phone cause, I can't fight it anymore
به سمت تلفن میرم چون بیشتر از این نمیتونم بجنگم
And I wonder if I ever cross your mind
من تعجب میکنم اگه تا حالا به ذهنت خطور کرده باشم
For me it happens all the time
من ولی همیشه به یاد توام
It's a quarter after one, I'm all alone and I need you now
یک ربع از ساعت 1 گذشته،من تنهای تنهام و بهت نیاز دارم
Said I wouldn't call but I lost all control and I need you now
گفتم که زنگ نمیزنم اما الان کنترلم رو از دست دادم و بهت نیاز دارم
And I don't know how I can do without, I just need you now
و نمیدونم که چه طوری میتونم انجامش بدم،من فقط الان بهت نیاز دارم
Another shot of whiskey, can't stop looking at the door
یه شات دیگه ویسکی،نمیتونم دست از نگاه کردن به در بردارم
Wishing you'd come sweeping in the way you did before
آرزو میکنم مثل قبل برگردی
And I wonder if I ever cross your mind
من تعجب میکنم اگه تا حالا به ذهنت خطور کرده باشم
For me it happens all the time
من ولی همیشه به یاد توام
It's a quarter after one, I'm a little drunk
یک ربع از ساعت 1 گذشته و من یه کمی مستم
And I need you now
و من بهت نیاز دارم
Said I wouldn't call but I lost all control and I need you now
گفتم که زنگ نمیزنم اما الان کنترلم رو از دست دادم و بهت نیاز دارم
Guess I'd rather hurt than feel nothing at all
فک کنم انقدر ضربه خوردم که هیچی احساس نمیکنم
It's a quarter after one, I'm all alone and I need you now
یک ربع از ساعت 1 گذشته،من تنهای تنهام و بهت نیاز دارم
Said I wouldn't call but I'm a little drunk and I need you now
گفتم که زنگ نمیزنم اما الان یه کم مستم و بهت نیاز دارم
And I don't know how I can do without, I just need you now
و نمیدونم که چه طوری میتونم انجامش بدم،من فقط الان بهت نیاز دارم
I just need you now
فقط بهت نیاز دارم
Oh baby I need you now
اوه عزیزم من بهت نیاز دارم
ترجمه از سایت http://nayablyrics.blogfa.com
Subscribe to:
Posts (Atom)































