<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-1972826170038884797</id><updated>2026-10-18T16:00:56.955-07:00</updated><category term="ASP.NET"/><category term="SQL Server"/><category term="C#"/><category term="IIS"/><category term="CSS"/><category term="WCF"/><category term="iOS"/><category term="jQuery"/><category term="Apache"/><category term="Batch Scripting"/><category term="C"/><category term="C++"/><category term="DI/ IOC"/><category term="Design Patterns"/><category term="Entity Framework"/><category term="Misc"/><category term="PHP"/><category term="SSRS"/><category term="Threads"/><category term="VBA"/><category term="Windows"/><title type='text'>Anuj&#39;s Share IT</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://anujyadavcse.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1972826170038884797/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://anujyadavcse.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/1972826170038884797/posts/default?start-index=26&amp;max-results=25&amp;redirect=false'/><author><name>Anuj Yadav</name><uri>http://www.blogger.com/profile/11344768057475167404</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3-ODntmQstTHRlTt1oA-YBvV6br318GA_rLr7G3-SM_X-xD27XUU07WojozfU-SDPyaIFEyOgi4zM5D-6G5P-cUfca2SDi5DEhYOiGE7cGBikp2zqmsG9Xp-0_boZJQ/s220/DSC_02080z-1.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>59</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-1972826170038884797.post-8071692981334439787</id><published>2016-04-07T21:31:00.001-07:00</published><updated>2016-04-07T21:31:22.971-07:00</updated><title type='text'>Java 8 JMX Default Metrics</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
This is more of a note. Here you can find default types and attributes for JMX on top of Java 8.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Code: &lt;span style=&quot;color: #cc0000;&quot;&gt;I will clean and explain it later :(&lt;/span&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;trebuchet ms&amp;quot; , sans-serif;&quot;&gt;
private static void WriteAttributes(final MBeanServer mBeanServer, final ObjectName http)
            throws InstanceNotFoundException, IntrospectionException, ReflectionException
    {
        MBeanInfo info = mBeanServer.getMBeanInfo(http);
        MBeanAttributeInfo[] attrInfo = info.getAttributes();

        System.out.println(&quot;Attributes for object: &quot; + http +&quot;:\n&quot;);
        for (MBeanAttributeInfo attr : attrInfo)
        {
            System.out.println(&quot;  &quot; + attr.getName() + &quot;\n&quot;);
        }
    }
&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;
Attributes for object: java.lang:type=MemoryPool,name=Metaspace:&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; Name&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; Type&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; Valid&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; Usage&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; PeakUsage&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; MemoryManagerNames&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; UsageThreshold&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; UsageThresholdExceeded&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; UsageThresholdCount&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; UsageThresholdSupported&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; CollectionUsageThreshold&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; CollectionUsageThresholdExceeded&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; CollectionUsageThresholdCount&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; CollectionUsage&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; CollectionUsageThresholdSupported&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; ObjectName&lt;br /&gt;
&lt;br /&gt;
Attributes for object: java.lang:type=MemoryPool,name=PS Old Gen:&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; Name&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; Type&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; Valid&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; Usage&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; PeakUsage&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; MemoryManagerNames&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; UsageThreshold&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; UsageThresholdExceeded&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; UsageThresholdCount&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; UsageThresholdSupported&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; CollectionUsageThreshold&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; CollectionUsageThresholdExceeded&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; CollectionUsageThresholdCount&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; CollectionUsage&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; CollectionUsageThresholdSupported&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; ObjectName&lt;br /&gt;
&lt;br /&gt;
Attributes for object: java.lang:type=GarbageCollector,name=PS Scavenge:&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; LastGcInfo&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; CollectionCount&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; CollectionTime&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; Name&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; MemoryPoolNames&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; Valid&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; ObjectName&lt;br /&gt;
&lt;br /&gt;
Attributes for object: java.lang:type=MemoryPool,name=PS Eden Space:&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; Name&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; Type&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; Valid&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; Usage&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; PeakUsage&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; MemoryManagerNames&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; UsageThreshold&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; UsageThresholdExceeded&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; UsageThresholdCount&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; UsageThresholdSupported&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; CollectionUsageThreshold&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; CollectionUsageThresholdExceeded&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; CollectionUsageThresholdCount&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; CollectionUsage&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; CollectionUsageThresholdSupported&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; ObjectName&lt;br /&gt;
&lt;br /&gt;
Attributes for object: JMImplementation:type=MBeanServerDelegate:&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; MBeanServerId&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; SpecificationName&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; SpecificationVersion&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; SpecificationVendor&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; ImplementationName&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; ImplementationVersion&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; ImplementationVendor&lt;br /&gt;
&lt;br /&gt;
Attributes for object: java.lang:type=Runtime:&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; Name&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; ClassPath&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; BootClassPathSupported&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; VmName&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; VmVendor&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; VmVersion&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; LibraryPath&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; BootClassPath&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; Uptime&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; StartTime&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; SpecName&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; SpecVendor&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; SpecVersion&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; ManagementSpecVersion&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; InputArguments&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; SystemProperties&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; ObjectName&lt;br /&gt;
&lt;br /&gt;
Attributes for object: java.lang:type=Threading:&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; ThreadAllocatedMemorySupported&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; ThreadAllocatedMemoryEnabled&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; ThreadContentionMonitoringSupported&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; CurrentThreadCpuTimeSupported&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; ObjectMonitorUsageSupported&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; SynchronizerUsageSupported&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; ThreadContentionMonitoringEnabled&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; ThreadCpuTimeEnabled&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; PeakThreadCount&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; DaemonThreadCount&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; ThreadCount&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; TotalStartedThreadCount&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; AllThreadIds&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; CurrentThreadCpuTime&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; CurrentThreadUserTime&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; ThreadCpuTimeSupported&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; ObjectName&lt;br /&gt;
&lt;br /&gt;
Attributes for object: java.lang:type=OperatingSystem:&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; OpenFileDescriptorCount&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; MaxFileDescriptorCount&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; CommittedVirtualMemorySize&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; TotalSwapSpaceSize&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; FreeSwapSpaceSize&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; ProcessCpuTime&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; FreePhysicalMemorySize&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; TotalPhysicalMemorySize&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; SystemCpuLoad&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; ProcessCpuLoad&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; Name&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; AvailableProcessors&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; Arch&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; Version&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; SystemLoadAverage&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; ObjectName&lt;br /&gt;
&lt;br /&gt;
Attributes for object: java.lang:type=MemoryPool,name=Code Cache:&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; Name&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; Type&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; Valid&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; Usage&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; PeakUsage&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; MemoryManagerNames&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; UsageThreshold&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; UsageThresholdExceeded&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; UsageThresholdCount&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; UsageThresholdSupported&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; CollectionUsageThreshold&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; CollectionUsageThresholdExceeded&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; CollectionUsageThresholdCount&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; CollectionUsage&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; CollectionUsageThresholdSupported&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; ObjectName&lt;br /&gt;
&lt;br /&gt;
Attributes for object: java.nio:type=BufferPool,name=direct:&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; Name&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; Count&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; TotalCapacity&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; MemoryUsed&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; ObjectName&lt;br /&gt;
&lt;br /&gt;
Attributes for object: java.lang:type=Compilation:&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; Name&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; CompilationTimeMonitoringSupported&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; TotalCompilationTime&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; ObjectName&lt;br /&gt;
&lt;br /&gt;
Attributes for object: java.lang:type=MemoryManager,name=CodeCacheManager:&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; Name&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; MemoryPoolNames&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; Valid&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; ObjectName&lt;br /&gt;
&lt;br /&gt;
Attributes for object: java.lang:type=MemoryPool,name=Compressed Class Space:&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; Name&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; Type&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; Valid&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; Usage&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; PeakUsage&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; MemoryManagerNames&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; UsageThreshold&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; UsageThresholdExceeded&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; UsageThresholdCount&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; UsageThresholdSupported&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; CollectionUsageThreshold&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; CollectionUsageThresholdExceeded&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; CollectionUsageThresholdCount&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; CollectionUsage&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; CollectionUsageThresholdSupported&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; ObjectName&lt;br /&gt;
&lt;br /&gt;
Attributes for object: java.lang:type=Memory:&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; Verbose&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; ObjectPendingFinalizationCount&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; HeapMemoryUsage&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; NonHeapMemoryUsage&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; ObjectName&lt;br /&gt;
&lt;br /&gt;
Attributes for object: java.nio:type=BufferPool,name=mapped:&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; Name&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; Count&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; TotalCapacity&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; MemoryUsed&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; ObjectName&lt;br /&gt;
&lt;br /&gt;
Attributes for object: java.util.logging:type=Logging:&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; ObjectName&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; LoggerNames&lt;br /&gt;
&lt;br /&gt;
Attributes for object: java.lang:type=MemoryPool,name=PS Survivor Space:&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; Name&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; Type&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; Valid&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; Usage&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; PeakUsage&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; MemoryManagerNames&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; UsageThreshold&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; UsageThresholdExceeded&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; UsageThresholdCount&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; UsageThresholdSupported&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; CollectionUsageThreshold&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; CollectionUsageThresholdExceeded&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; CollectionUsageThresholdCount&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; CollectionUsage&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; CollectionUsageThresholdSupported&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; ObjectName&lt;br /&gt;
&lt;br /&gt;
Attributes for object: java.lang:type=ClassLoading:&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; TotalLoadedClassCount&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; LoadedClassCount&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; UnloadedClassCount&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; Verbose&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; ObjectName&lt;br /&gt;
&lt;br /&gt;
Attributes for object: java.lang:type=MemoryManager,name=Metaspace Manager:&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; Name&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; MemoryPoolNames&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; Valid&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; ObjectName&lt;br /&gt;
&lt;br /&gt;
Attributes for object: com.sun.management:type=DiagnosticCommand:&lt;br /&gt;
&lt;br /&gt;
Attributes for object: java.lang:type=GarbageCollector,name=PS MarkSweep:&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; LastGcInfo&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; CollectionCount&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; CollectionTime&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; Name&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; MemoryPoolNames&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; Valid&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; ObjectName&lt;br /&gt;
&lt;br /&gt;
Attributes for object: com.journaldev.jmx:type=SystemConfig:&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; ThreadCount&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; SchemaName&lt;br /&gt;
&lt;br /&gt;
Attributes for object: com.sun.management:type=HotSpotDiagnostic:&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; DiagnosticOptions&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; ObjectName&lt;br /&gt;
&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://anujyadavcse.blogspot.com/feeds/8071692981334439787/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://anujyadavcse.blogspot.com/2016/04/java-8-jmx-default-metrics.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1972826170038884797/posts/default/8071692981334439787'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1972826170038884797/posts/default/8071692981334439787'/><link rel='alternate' type='text/html' href='http://anujyadavcse.blogspot.com/2016/04/java-8-jmx-default-metrics.html' title='Java 8 JMX Default Metrics'/><author><name>Anuj Yadav</name><uri>http://www.blogger.com/profile/11344768057475167404</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3-ODntmQstTHRlTt1oA-YBvV6br318GA_rLr7G3-SM_X-xD27XUU07WojozfU-SDPyaIFEyOgi4zM5D-6G5P-cUfca2SDi5DEhYOiGE7cGBikp2zqmsG9Xp-0_boZJQ/s220/DSC_02080z-1.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1972826170038884797.post-4989174381778435353</id><published>2014-08-08T04:39:00.002-07:00</published><updated>2014-08-08T04:39:21.362-07:00</updated><title type='text'>How to set JAVA_HOME environment variable on Mac</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;b&gt;Note&lt;/b&gt;: This tip is for Mac OSX 10.5 or later&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Apple recommends to set the &lt;b&gt;$JAVA_HOME&lt;/b&gt; variable to &lt;b&gt;/usr/libexec/java_home&lt;/b&gt;, just &lt;b&gt;export&lt;/b&gt; &lt;b&gt;$JAVA_HOME&lt;/b&gt; in file &lt;b&gt;~/. bash_profile&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
You might not have .bash_profile present on your system already. No worries we will create/update the profile in next step.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Open Terminal:&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
$ vi ~/.bash_profile&lt;br /&gt;
&lt;br /&gt;
Initially the vi editor will not be in edit mode, press &#39;i&#39;.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Update file by exporting variable:&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;








&lt;br /&gt;
&lt;div class=&quot;p1&quot;&gt;
export JAVA_HOME=$(/usr/libexec/java_home)&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
to the file (in the vi editor which we opened using the previous command)&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;b&gt;Saving and Closing the .bash_profile file opened inside vim editor:&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
Press escape (while still inside the vi editor)&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
type &quot;:wq!&quot; or press &quot;Shift + zz&quot; to save and exit the file.&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://anujyadavcse.blogspot.com/feeds/4989174381778435353/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://anujyadavcse.blogspot.com/2014/08/how-to-set-javahome-environment.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1972826170038884797/posts/default/4989174381778435353'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1972826170038884797/posts/default/4989174381778435353'/><link rel='alternate' type='text/html' href='http://anujyadavcse.blogspot.com/2014/08/how-to-set-javahome-environment.html' title='How to set JAVA_HOME environment variable on Mac'/><author><name>Anuj Yadav</name><uri>http://www.blogger.com/profile/11344768057475167404</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3-ODntmQstTHRlTt1oA-YBvV6br318GA_rLr7G3-SM_X-xD27XUU07WojozfU-SDPyaIFEyOgi4zM5D-6G5P-cUfca2SDi5DEhYOiGE7cGBikp2zqmsG9Xp-0_boZJQ/s220/DSC_02080z-1.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1972826170038884797.post-4917589117759854810</id><published>2014-01-20T23:49:00.003-08:00</published><updated>2014-01-20T23:50:41.375-08:00</updated><title type='text'>Laravel XAMPP MySQL artisan migrate install error mysql.sock</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span style=&quot;font-family: Helvetica Neue, Arial, Helvetica, sans-serif;&quot;&gt;In my &lt;a href=&quot;http://anujyadavcse.blogspot.in/2014/01/setting-up-laravel-4x-on-mac-osx-108.html&quot; target=&quot;_blank&quot;&gt;previous post I wrote about setting up Laravel 4 on Mac with XAMPP&lt;/a&gt;. When I tried to use migrations (using artisan) I faced some issue. I will also post about Laravel migrations soon.&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Helvetica Neue&#39;, Arial, Helvetica, sans-serif;&quot;&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;&lt;span style=&quot;font-family: Helvetica Neue, Arial, Helvetica, sans-serif;&quot;&gt; php artisan migrate:install&lt;/span&gt;&lt;/pre&gt;
&lt;span style=&quot;font-family: Helvetica Neue, Arial, Helvetica, sans-serif;&quot;&gt;&lt;b&gt;Error&lt;/b&gt;:&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Helvetica Neue&#39;, Arial, Helvetica, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;&lt;span style=&quot;font-family: Helvetica Neue, Arial, Helvetica, sans-serif;&quot;&gt;&amp;nbsp; [PDOException] &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;

&lt;span style=&quot;font-family: Helvetica Neue, Arial, Helvetica, sans-serif;&quot;&gt;&amp;nbsp; SQLSTATE[HY000] [2002] No such file or directory &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Helvetica Neue&#39;, Arial, Helvetica, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/pre&gt;
&lt;span style=&quot;font-family: Helvetica Neue, Arial, Helvetica, sans-serif;&quot;&gt;&lt;b&gt;Solution&lt;/b&gt;:&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Helvetica Neue, Arial, Helvetica, sans-serif;&quot;&gt;We need to tell artisan which mysql we want it to use. For this to work we need to porivde it with mysql.sock which we want it to use.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Helvetica Neue, Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Helvetica Neue, Arial, Helvetica, sans-serif;&quot;&gt;So change your database settings like this:&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Helvetica Neue, Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;pre class=&quot;prettyprint&quot; style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-family: Helvetica Neue, Arial, Helvetica, sans-serif;&quot;&gt;&#39;mysql&#39; =&amp;gt; array(&lt;/span&gt;
&lt;span style=&quot;font-family: Helvetica Neue, Arial, Helvetica, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;&#39;driver&#39; &amp;nbsp; &amp;nbsp;=&amp;gt; &#39;mysql&#39;,&lt;/span&gt;
&lt;span style=&quot;font-family: Helvetica Neue, Arial, Helvetica, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;&#39;host&#39; &amp;nbsp; &amp;nbsp; &amp;nbsp;=&amp;gt; &#39;localhost&#39;,&lt;/span&gt;
&lt;span style=&quot;font-family: Helvetica Neue, Arial, Helvetica, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp;&lt;span style=&quot;color: #7f6000;&quot;&gt;&#39;unix_socket&#39; =&amp;gt; &#39;/Applications/xampp/xamppfiles/var/mysql/mysql.sock&#39;,&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Helvetica Neue, Arial, Helvetica, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;&#39;database&#39; &amp;nbsp;=&amp;gt; &#39;wedding&#39;,&lt;/span&gt;
&lt;span style=&quot;font-family: Helvetica Neue, Arial, Helvetica, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;&#39;username&#39; &amp;nbsp;=&amp;gt; &#39;root&#39;,&lt;/span&gt;
&lt;span style=&quot;font-family: Helvetica Neue, Arial, Helvetica, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;&#39;password&#39; &amp;nbsp;=&amp;gt; &#39;&#39;,&lt;/span&gt;
&lt;span style=&quot;font-family: Helvetica Neue, Arial, Helvetica, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;&#39;charset&#39; &amp;nbsp; =&amp;gt; &#39;utf8&#39;,&lt;/span&gt;
&lt;span style=&quot;font-family: Helvetica Neue, Arial, Helvetica, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;&#39;collation&#39; =&amp;gt; &#39;utf8_unicode_ci&#39;,&lt;/span&gt;
&lt;span style=&quot;font-family: Helvetica Neue, Arial, Helvetica, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;&#39;prefix&#39; &amp;nbsp; &amp;nbsp;=&amp;gt; &#39;&#39;,&lt;/span&gt;
&lt;span style=&quot;font-family: Helvetica Neue, Arial, Helvetica, sans-serif;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;),&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Helvetica Neue, Arial, Helvetica, sans-serif;&quot;&gt;We need to provide &quot;&lt;b&gt;unix_socket&lt;/b&gt;&quot;.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Helvetica Neue, Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Helvetica Neue, Arial, Helvetica, sans-serif;&quot;&gt;On mac it will be find at &quot;&lt;b&gt;/Applications/xampp/xamppfiles/var/mysql/mysql.sock&lt;/b&gt;&quot; assuming that you have your XAMPP installed correctly in Applications folder.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Helvetica Neue, Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Helvetica Neue, Arial, Helvetica, sans-serif;&quot;&gt;&lt;b&gt;References&lt;/b&gt;:&lt;/span&gt;&lt;br /&gt;
&lt;a href=&quot;http://stackoverflow.com/questions/14219692/laravel-setup-of-migrations-using-artisan-is-failing&quot;&gt;&lt;span style=&quot;font-family: Helvetica Neue, Arial, Helvetica, sans-serif;&quot;&gt;http://stackoverflow.com/questions/14219692/laravel-setup-of-migrations-using-artisan-is-failing&lt;/span&gt;&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;http://www.jroller.com/jnicho02/entry/setting_up_xampp_on_the&quot;&gt;&lt;span style=&quot;font-family: Helvetica Neue, Arial, Helvetica, sans-serif;&quot;&gt;http://www.jroller.com/jnicho02/entry/setting_up_xampp_on_the&lt;/span&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://anujyadavcse.blogspot.com/feeds/4917589117759854810/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://anujyadavcse.blogspot.com/2014/01/laravel-xampp-mysql-artisan-migrate.html#comment-form' title='6 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1972826170038884797/posts/default/4917589117759854810'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1972826170038884797/posts/default/4917589117759854810'/><link rel='alternate' type='text/html' href='http://anujyadavcse.blogspot.com/2014/01/laravel-xampp-mysql-artisan-migrate.html' title='Laravel XAMPP MySQL artisan migrate install error mysql.sock'/><author><name>Anuj Yadav</name><uri>http://www.blogger.com/profile/11344768057475167404</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3-ODntmQstTHRlTt1oA-YBvV6br318GA_rLr7G3-SM_X-xD27XUU07WojozfU-SDPyaIFEyOgi4zM5D-6G5P-cUfca2SDi5DEhYOiGE7cGBikp2zqmsG9Xp-0_boZJQ/s220/DSC_02080z-1.jpg'/></author><thr:total>6</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1972826170038884797.post-8017580369480224516</id><published>2014-01-18T10:46:00.003-08:00</published><updated>2014-01-18T10:47:44.176-08:00</updated><title type='text'>Working with MySQL on MAC. GUI Client, Web Based and Terminal</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span style=&quot;font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;&quot;&gt;MySQL is most popular open source relational database. I have been using it myself for my PHP, Python and Ruby projects. Obviously, we need some client(s) to access MySQL database. In this post I am going to list down few clients.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;span style=&quot;font-family: Helvetica Neue, Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Helvetica Neue, Arial, Helvetica, sans-serif;&quot;&gt;Environment:&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;span style=&quot;font-family: Helvetica Neue, Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Helvetica Neue, Arial, Helvetica, sans-serif;&quot;&gt;I am using XAMPP on Mac. You can install MySQL separately if you want to.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;span style=&quot;font-family: Helvetica Neue, Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Helvetica Neue, Arial, Helvetica, sans-serif;&quot;&gt;1. &lt;b&gt;Desktop GUI client&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;span style=&quot;font-family: Helvetica Neue, Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Helvetica Neue, Arial, Helvetica, sans-serif;&quot;&gt;Use &lt;a href=&quot;http://www.sequelpro.com/&quot; target=&quot;_blank&quot;&gt;SequelPro&lt;/a&gt; it is a nice tool and free.&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;span style=&quot;font-family: Helvetica Neue, Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhLG5OkYNScbYPl_1wna4TzuPD9CrIH91fcgcfVzJd_bwD8rFHrFe8vdgJ8SE0t5wPBwZoP88rw0NypBQl5W3BbyauIKIOOAZdLvnhLSrbRcAuOVWNqL-n0EkHwRV8UA_PksK4_CkvufisL/s1600/Screen+Shot+2014-01-18+at+10.36.31+PM.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-size: large;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhLG5OkYNScbYPl_1wna4TzuPD9CrIH91fcgcfVzJd_bwD8rFHrFe8vdgJ8SE0t5wPBwZoP88rw0NypBQl5W3BbyauIKIOOAZdLvnhLSrbRcAuOVWNqL-n0EkHwRV8UA_PksK4_CkvufisL/s1600/Screen+Shot+2014-01-18+at+10.36.31+PM.png&quot; height=&quot;284&quot; width=&quot;640&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;span style=&quot;font-family: Helvetica Neue, Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Helvetica Neue, Arial, Helvetica, sans-serif;&quot;&gt;Set it up and you are ready to go.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;span style=&quot;font-family: Helvetica Neue, Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Helvetica Neue, Arial, Helvetica, sans-serif;&quot;&gt;2. &lt;b&gt;PHPMyAdmin&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;span style=&quot;font-family: Helvetica Neue, Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiECoEPKn10KGoJADrY9Ga9HmQt0a2UTGEzgXK9jWbIYnGQo9Ih4BUcomlC8FLGRwaIYHzq4bdj_FdJhdpPYZa3HiB4bc5e6UjSZwEhX7ympOh29qBa3MsHc6EG6y42LmtB5dMjCqNtXgEJ/s1600/Screen+Shot+2014-01-18+at+11.40.45+PM.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-size: large;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiECoEPKn10KGoJADrY9Ga9HmQt0a2UTGEzgXK9jWbIYnGQo9Ih4BUcomlC8FLGRwaIYHzq4bdj_FdJhdpPYZa3HiB4bc5e6UjSZwEhX7ympOh29qBa3MsHc6EG6y42LmtB5dMjCqNtXgEJ/s1600/Screen+Shot+2014-01-18+at+11.40.45+PM.png&quot; height=&quot;286&quot; width=&quot;640&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;span style=&quot;font-family: Helvetica Neue, Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;background-color: white; font-family: sans-serif;&quot;&gt;phpMyAdmin is a free software tool written in&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;http://php.net/&quot; style=&quot;background-color: white; font-family: sans-serif; text-decoration: none;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;b&gt;PHP&lt;/b&gt;&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;background-color: white; font-family: sans-serif;&quot;&gt;, intended to handle the administration of&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;http://mysql.com/&quot; style=&quot;background-color: white; font-family: sans-serif; text-decoration: none;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;b&gt;MySQL&lt;/b&gt;&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;background-color: white; font-family: sans-serif;&quot;&gt;&amp;nbsp;over the Web. It gets setup with XAMPP.&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;span style=&quot;background-color: white; font-family: sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;background-color: white; font-family: sans-serif;&quot;&gt;3. &lt;b&gt;Terminal&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;span style=&quot;background-color: white; font-family: sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;background-color: white; font-family: sans-serif;&quot;&gt;Open up terminal and execute following commands -&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;span style=&quot;background-color: white; font-family: sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;background-color: white; font-family: sans-serif;&quot;&gt;Go to the directory with mysql binaries&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;span style=&quot;background-color: white; font-family: sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;span style=&quot;font-family: sans-serif;&quot;&gt;&lt;b&gt;cd /Applications/XAMPP/xamppfiles/bin;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&lt;span style=&quot;font-family: sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;span style=&quot;font-family: sans-serif;&quot;&gt;Access mysql command line tool using&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&lt;span style=&quot;font-family: sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;span style=&quot;font-family: sans-serif;&quot;&gt;&lt;b&gt;./mysql --user=root --password=&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://anujyadavcse.blogspot.com/feeds/8017580369480224516/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://anujyadavcse.blogspot.com/2014/01/working-with-mysql-on-mac-gui-client.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1972826170038884797/posts/default/8017580369480224516'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1972826170038884797/posts/default/8017580369480224516'/><link rel='alternate' type='text/html' href='http://anujyadavcse.blogspot.com/2014/01/working-with-mysql-on-mac-gui-client.html' title='Working with MySQL on MAC. GUI Client, Web Based and Terminal'/><author><name>Anuj Yadav</name><uri>http://www.blogger.com/profile/11344768057475167404</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3-ODntmQstTHRlTt1oA-YBvV6br318GA_rLr7G3-SM_X-xD27XUU07WojozfU-SDPyaIFEyOgi4zM5D-6G5P-cUfca2SDi5DEhYOiGE7cGBikp2zqmsG9Xp-0_boZJQ/s220/DSC_02080z-1.jpg'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhLG5OkYNScbYPl_1wna4TzuPD9CrIH91fcgcfVzJd_bwD8rFHrFe8vdgJ8SE0t5wPBwZoP88rw0NypBQl5W3BbyauIKIOOAZdLvnhLSrbRcAuOVWNqL-n0EkHwRV8UA_PksK4_CkvufisL/s72-c/Screen+Shot+2014-01-18+at+10.36.31+PM.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1972826170038884797.post-5994105681972877766</id><published>2014-01-16T13:06:00.000-08:00</published><updated>2014-01-16T13:15:23.226-08:00</updated><title type='text'>Setting Up Laravel 4.x on Mac OSX 10.8+ with XAMPP installed</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif; font-size: large;&quot;&gt;I am new to PHP and have coded earlier with CodeIgniter. It is really easy to get started with CodeIgniter as it is light but powerful and has less features. As CodeIgniter is slowly phasing out I thought of moving to Laravel. Yes, it is powerful and AWESOME!!!&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;Lets get down to business.&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;1. &lt;a href=&quot;http://getcomposer.org/download/&quot; target=&quot;_blank&quot;&gt;Install composer&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;I was doing it for the first time and faced issues:&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;&lt;span style=&quot;font-size: large;&quot;&gt;&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;Some settings on your machine make Composer unable to work properly.&lt;/span&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;Make sure that you fix the issues listed below and run this script again:&lt;/span&gt;

&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;The detect_unicode setting must be disabled.&lt;/span&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;Add the following to the end of your `php.ini`:&lt;/span&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;detect_unicode = Off&lt;/span&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;A php.ini file does not exist. You will have to create one.&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: Trebuchet MS, sans-serif; font-size: large;&quot;&gt;I was clueless at this moment and started to search. After some search I found an &lt;a href=&quot;http://jason.pureconcepts.net/2012/10/install-apache-php-mysql-mac-os-x/&quot; target=&quot;_blank&quot;&gt;article which tells about setting up AMP (Apache, My SQL and PHP) environment&lt;/a&gt;. &lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: Trebuchet MS, sans-serif; font-size: large;&quot;&gt;While going through it I realized that I have Apache already installed on my system (I am new to Mac too). I followed the steps to configure it (took related path accidentally :D).&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: Trebuchet MS, sans-serif; font-size: large;&quot;&gt;While doing this I found out that I am working in a system folder &lt;b&gt;/etc. &lt;/b&gt;To check it out I jumped into it and to my surprise I found my missing &lt;b&gt;php.ini.default&lt;/b&gt;.I created a copy of it, renamed it and opened it up in &lt;b&gt;vim&lt;/b&gt; editor.&lt;/span&gt;&lt;/pre&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;&lt;span style=&quot;font-family: Trebuchet MS, sans-serif; font-size: large;&quot;&gt;sudo vi php.ini&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: Trebuchet MS, sans-serif; font-size: large;&quot;&gt;I added the line&amp;nbsp;&lt;/span&gt;&lt;/pre&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif; font-size: large;&quot;&gt;detect_unicode = Off &lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif; font-size: large;&quot;&gt;at the end.&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif; font-size: large;&quot;&gt;I tried to setup composer again and it worked.&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif; font-size: large;&quot;&gt;2. &lt;a href=&quot;http://laravel.com/docs/installation&quot; target=&quot;_blank&quot;&gt;Install Laravel&lt;/a&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif; font-size: large;&quot;&gt;composer create-project laravel/laravel --prefer-dist&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif; font-size: large;&quot;&gt;No surprises, I got another issue :D&lt;/span&gt;&lt;/pre&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif; font-size: large;&quot;&gt;Script php artisan optimize handling the post-update-cmd event returned with an error:


  [InvalidArgumentException]
  Command &quot;optimize&quot; is not defined.&lt;/span&gt;&lt;/pre&gt;
&lt;pre class=&quot;&quot;&gt;&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif; font-size: large;&quot;&gt;I found out that &lt;b&gt;mcrypt&lt;/b&gt; is not available. I searched again and realized that PHP version which I am using is old. I check it using &quot;&lt;b&gt;php -v&lt;/b&gt;&quot; and checked the path of PHP which is being used using &quot;&lt;b&gt;which php&lt;/b&gt;&quot;. PHP version was 5.3.x.&lt;/span&gt;&lt;/pre&gt;
&lt;pre class=&quot;&quot;&gt;&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif; font-size: large;&quot;&gt;3. Update PHP (Laravel needs a recent version)&lt;/span&gt;&lt;/pre&gt;
&lt;pre class=&quot;&quot;&gt;&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif; font-size: large;&quot;&gt;&lt;a href=&quot;http://php-osx.liip.ch/&quot; target=&quot;_blank&quot;&gt;I used this link&lt;/a&gt; (It is awesome, thanks to author).&lt;/span&gt;&lt;/pre&gt;
&lt;pre class=&quot;&quot;&gt;&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif; font-size: large;&quot;&gt;#2. Go back to step 2.&lt;/span&gt;&lt;/pre&gt;
&lt;pre class=&quot;&quot;&gt;&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif; font-size: large;&quot;&gt;Try again. I thought of using my XAMPP&#39;s Apache and tried creating project there. I faced the same issue. Why now :(. I thought it is something to do with PHP version that I am using. I checked the version again and found out that I am still using wrong version and php binaries from wrong path were being used.&lt;/span&gt;&lt;/pre&gt;
&lt;pre class=&quot;&quot;&gt;&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif; font-size: large;&quot;&gt;I searched to find out how to use the right PHP version and found &lt;a href=&quot;https://www.blogger.com/You%20are%20using%20the%20built%20in%20version%20of%20PHP,%20did%20you%20install%20PHP-OSX%20for%205.4%20installation?%20If%20so%20you%20need%20to%20overwrite%20it%27s%20path%20from%20terminal:%20%20sudo%20vi%20~/.bash_profile%20enter%20password%20when%20file%20loads%20press%20A%20to%20access%20writing%20%20paste%20this%20line:%20%20export%20PATH=/usr/local/php5/bin:${PATH}%20%20press%20ESC%20key%20%20hold%20SHIFT%20and%20Press%20ZZ%20(z%20twice)%20%20now%20do%20which%20php%20again%20it%20should%20say:%20%20/usr/local/php5/bin/php%20%20now%20install%20home%20brew%20and%20you%20can%20do%20stuff%20like%20like%20%20brew%20install%20php54-mcrypt%20%20restart%20apache%20in%20between%20steps%20%20you%20may%20also%20be%20able%20to%20do%20other%20stuff%20like%20%22brew%20search%20php54-module%22%20or%20php54-*%20to%20see%20whats%20available..%20always%20install%20with%20php54%20to%20avoid%20conflicts.&quot; target=&quot;_blank&quot;&gt;this Laravel forum link&lt;/a&gt;.&lt;/span&gt;&lt;/pre&gt;
&lt;pre class=&quot;&quot;&gt;&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif; font-size: large;&quot;&gt;I am pasting the suggestion here for ready reference but all the credit goes to the contributor in forum.&lt;/span&gt;&lt;/pre&gt;
&lt;pre style=&quot;-moz-border-radius: 1em 1em 1em 1em; background-color: #D8D8D8; border-radius: 1em 1em 1em 1em; color: black; margin: 10px; padding: 10px;&quot;&gt;&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif; font-size: large;&quot;&gt;You are using the built in version of PHP, did you install PHP-OSX for 5.4 installation? If so you need to overwrite it&#39;s path
from terminal:

sudo vi ~/.bash_profile
enter password
when file loads press A to access writing

paste this line:

export PATH=/usr/local/php5/bin:${PATH}

press ESC key

hold SHIFT and Press ZZ (z twice)

now do which php again it should say:

/usr/local/php5/bin/php

now install home brew and you can do stuff like like 
brew install php54-mcrypt

restart apache in between steps

you may also be able to do other stuff like &quot;brew search php54-module&quot; or php54-* to see whats available.. always install with php54 to avoid conflicts.&lt;/span&gt;&lt;/pre&gt;
&lt;pre class=&quot;&quot;&gt;&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif; font-size: large;&quot;&gt;My setup just worked. I did not need to install homebrew and perform rest of the steps.&lt;/span&gt;&lt;/pre&gt;
&lt;pre class=&quot;&quot;&gt;&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif; font-size: large;&quot;&gt;&lt;a href=&quot;http://coolestguidesontheplanet.com/how-to-install-mcrypt-for-php-on-mac-osx-lion-10-7-development-server/&quot; target=&quot;_blank&quot;&gt;For setting up mcrypt you can also refer this link&lt;/a&gt; I did not tried it though.&lt;/span&gt;&lt;/pre&gt;
&lt;pre class=&quot;&quot;&gt;&lt;span style=&quot;font-size: large;&quot;&gt;&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif;&quot;&gt;4. Tried &lt;/span&gt;&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;a href=&quot;http://localhost/laravel/public/&quot;&gt;http://localhost/laravel/public/&lt;/a&gt; - did not work.&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre class=&quot;&quot;&gt;&lt;span style=&quot;font-family: Trebuchet MS, sans-serif; font-size: large;&quot;&gt;I got &lt;b&gt;Laravel 4 blank screen&lt;/b&gt; &lt;b&gt;issue&lt;/b&gt; (as people call it famously). I recalled that I need to set &lt;b&gt;storage&lt;/b&gt; directory present in &lt;b&gt;app&lt;/b&gt; directory of &lt;b&gt;laravel&lt;/b&gt; setup as &lt;b&gt;writable&lt;/b&gt;. &lt;/span&gt;&lt;/pre&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;&lt;span style=&quot;font-family: Trebuchet MS, sans-serif; font-size: large;&quot;&gt;$ sudo chmod -R 7777 app/storage&lt;/span&gt;&lt;/pre&gt;
&lt;pre class=&quot;&quot;&gt;&lt;span style=&quot;font-family: Trebuchet MS, sans-serif; font-size: large;&quot;&gt;As, I am the only user of my machine and this is my home machine I gave all permissions. &lt;span style=&quot;color: #e06666;&quot;&gt;Please provide appropriate permissions in your case&lt;/span&gt;.&lt;/span&gt;&lt;/pre&gt;
&lt;pre class=&quot;&quot;&gt;&lt;span style=&quot;font-family: Trebuchet MS, sans-serif; font-size: large;&quot;&gt;5. Happy Ending!!! It worked. :D&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;/pre&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://anujyadavcse.blogspot.com/feeds/5994105681972877766/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://anujyadavcse.blogspot.com/2014/01/setting-up-laravel-4x-on-mac-osx-108.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1972826170038884797/posts/default/5994105681972877766'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1972826170038884797/posts/default/5994105681972877766'/><link rel='alternate' type='text/html' href='http://anujyadavcse.blogspot.com/2014/01/setting-up-laravel-4x-on-mac-osx-108.html' title='Setting Up Laravel 4.x on Mac OSX 10.8+ with XAMPP installed'/><author><name>Anuj Yadav</name><uri>http://www.blogger.com/profile/11344768057475167404</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3-ODntmQstTHRlTt1oA-YBvV6br318GA_rLr7G3-SM_X-xD27XUU07WojozfU-SDPyaIFEyOgi4zM5D-6G5P-cUfca2SDi5DEhYOiGE7cGBikp2zqmsG9Xp-0_boZJQ/s220/DSC_02080z-1.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1972826170038884797.post-8498701713446498061</id><published>2013-07-07T21:48:00.003-07:00</published><updated>2013-07-07T21:48:45.252-07:00</updated><title type='text'>Create custom UITextFields and UITextViews with underline</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;a class=&quot;downloadCode&quot; href=&quot;https://github.com/ShareIT/customUI&quot;&gt;Download&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;In a recent iOS project I needed to create custom UITextView and UITextField. The look and feel had to be same as the Notes app, i.e. the text view and text field both should have horizontal lines as are present in a note.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiEzytxtwdGkWcWsZtzSaMcl3XcuHNSaQ8u_8f0Mq9T70aVGBqabCsXr6XtHdoqTpy42Idl3HL-lh7tKzNJ2_ScPdS7OLHd68xTjoeC__8fb3fvFkBKzV1gel1jHAjzfpj08gOa8TOut_2W/s1600/Screen+Shot+2013-01-08+at+4.04.29+PM.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiEzytxtwdGkWcWsZtzSaMcl3XcuHNSaQ8u_8f0Mq9T70aVGBqabCsXr6XtHdoqTpy42Idl3HL-lh7tKzNJ2_ScPdS7OLHd68xTjoeC__8fb3fvFkBKzV1gel1jHAjzfpj08gOa8TOut_2W/s320/Screen+Shot+2013-01-08+at+4.04.29+PM.png&quot; width=&quot;305&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;How to create a custom UIView&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;To create a custom UIView we need to inherit from UIView class. We then need to override drawRect method. Override only if you need to change the way view is drawn as this is a performance&amp;nbsp;intensive&amp;nbsp;operation.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;Custom UITextField&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;In order to create custom UITextField I inherited my class from UITextField. I need to draw a bottom border for this I need override drawRect method.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;
    //Get the current drawing context
    CGContextRef context = UIGraphicsGetCurrentContext();
    //Set the line color and width
    CGContextSetStrokeColorWithColor(context, [UIColor blackColor].CGColor);
    CGContextSetLineWidth(context, 0.5f);
    //Start a new Path
    CGContextBeginPath(context);
    
    // offset lines up - we are adding offset to font.leading so that line is drawn right below the characters and still characters are visible.
    CGContextMoveToPoint(context, self.bounds.origin.x, self.font.lineHeight + 6.0f);
    CGContextAddLineToPoint(context, self.bounds.size.width, self.font.lineHeight + 6.0f);
    
    //Close our Path and Stroke (draw) it
    CGContextClosePath(context);
    CGContextStrokePath(context);&lt;/span&gt;&lt;/pre&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;We need to grab a graphic context us we are going to draw a custom UI. Then we need to set color to the context and the line width. Line width, because we need a line under our control. Now, the tricky part:&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;We need to set the start and end coordinates for line. For this we need the line height so that we can set the Y coordinate correctly. Fortunately iOS provides a simple to get this. self.font.lineHeight. Using this we are asking the view to tell us about the lineHeight based on the font.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;Thats it.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;Custom UITextView&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;Approach remains same here. But, we need multiple lines and we need lines to appear even if we scroll.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;
- (void)drawRect:(CGRect)rect {
    
    //Get the current drawing context
    CGContextRef context = UIGraphicsGetCurrentContext();
    //Set the line color and width
    CGContextSetStrokeColorWithColor(context, [UIColor lightGrayColor].CGColor);
    CGContextSetLineWidth(context, 1.0f);
    //Start a new Path
    CGContextBeginPath(context);
    
    //Find the number of lines in our textView + add a bit more height to draw lines in the empty part of the view
    NSUInteger numberOfLines = (self.contentSize.height + self.bounds.size.height) / self.font.leading;
    
    //Set the line offset from the baseline. (I&#39;m sure there&#39;s a concrete way to calculate this.)
    CGFloat baselineOffset = 6.0f;
    
    //iterate over numberOfLines and draw each line
    for (int x = 1; x &amp;lt; numberOfLines; x++) {
        //0.5f offset lines up line with pixel boundary
        CGContextMoveToPoint(context, self.bounds.origin.x + 10, self.font.leading*x + 0.5f + baselineOffset);
        CGContextAddLineToPoint(context, self.bounds.size.width - 10, self.font.leading*x + 0.5f + baselineOffset);
    }
    
    //Close our Path and Stroke (draw) it
    CGContextClosePath(context);
    CGContextStrokePath(context);
}
&lt;/span&gt;&lt;/pre&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;Here we need to calculate the number of lines before drawing. So, why are we adding contentsize.height and bounds.height. If we will use just the contentsize.height then:&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;1. We do not have any content initially and thus we will not have any line.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;2. There won&#39;t be any lines at the bottom (after the content)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;Thus, for a consistent and better view we will add textview&#39;s bounds.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://anujyadavcse.blogspot.com/feeds/8498701713446498061/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://anujyadavcse.blogspot.com/2013/07/create-custom-uitextfields-and.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1972826170038884797/posts/default/8498701713446498061'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1972826170038884797/posts/default/8498701713446498061'/><link rel='alternate' type='text/html' href='http://anujyadavcse.blogspot.com/2013/07/create-custom-uitextfields-and.html' title='Create custom UITextFields and UITextViews with underline'/><author><name>Anuj Yadav</name><uri>http://www.blogger.com/profile/11344768057475167404</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3-ODntmQstTHRlTt1oA-YBvV6br318GA_rLr7G3-SM_X-xD27XUU07WojozfU-SDPyaIFEyOgi4zM5D-6G5P-cUfca2SDi5DEhYOiGE7cGBikp2zqmsG9Xp-0_boZJQ/s220/DSC_02080z-1.jpg'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiEzytxtwdGkWcWsZtzSaMcl3XcuHNSaQ8u_8f0Mq9T70aVGBqabCsXr6XtHdoqTpy42Idl3HL-lh7tKzNJ2_ScPdS7OLHd68xTjoeC__8fb3fvFkBKzV1gel1jHAjzfpj08gOa8TOut_2W/s72-c/Screen+Shot+2013-01-08+at+4.04.29+PM.png" height="72" width="72"/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1972826170038884797.post-5490446471637824434</id><published>2013-03-15T12:33:00.000-07:00</published><updated>2013-03-15T12:33:13.897-07:00</updated><title type='text'>UITableView basic tutorial</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;In this tutorial we will create a table view with some dummy data, we will use&amp;nbsp;disclosure&amp;nbsp;indicator, change background color of cell, handle user selection, change separator color etc. There many tutorials which provides in depth information on UITableViews thus I will not touched that and instead targeted the practical How Tos.&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgVCi3thU0-vAOuzFD9UN52Rs3ox-QK656AzH0hzUWkFsSJAmWH9xLQvYgIFfzRMIBets90XXoSJ2oRSOfvRy2kClkQ0B3Rmw4aRQNkVbL-fhuCeka7jBd5G1VVzahEhlWPKDm-8v9tuBOK/s1600/Screen+Shot+2013-03-15+at+8.56.22+PM.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgVCi3thU0-vAOuzFD9UN52Rs3ox-QK656AzH0hzUWkFsSJAmWH9xLQvYgIFfzRMIBets90XXoSJ2oRSOfvRy2kClkQ0B3Rmw4aRQNkVbL-fhuCeka7jBd5G1VVzahEhlWPKDm-8v9tuBOK/s320/Screen+Shot+2013-03-15+at+8.56.22+PM.png&quot; width=&quot;269&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;Create a new single view project and add a UITableView to the initial view controller which has been added to the storyboard automatically.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;In order to use UITableView in your viewcontroller you need to adapt to UITableViewDataSource and UITableViewDelegate.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;UITableViewDelegate provides us with methods which let us handle user selection events, define row height, modifying view and much more.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;UITableViewDataSource provides data to UITableView to construct the view (to render content). Create table view cells, define the number of sections, number of rows in sections and much more.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;Adapt to required protocols&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;@interface AYViewController : UIViewController&amp;lt;UITableViewDataSource,UITableViewDelegate&amp;gt;

@end
&lt;/span&gt;&lt;/pre&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;Create dummy data&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;self.items = [[NSArray alloc] initWithObjects:@&quot;First&quot;,@&quot;Second&quot;,@&quot;Third&quot;, nil];
&lt;/span&gt;&lt;/pre&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;Implement basic methods of the protocols we have adapted to&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;/div&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return ((self.items &amp;amp;&amp;amp; [self.items count] &amp;gt; 0) ? [self.items count]: 1);
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString *CellIdentifier = @&quot;AYBasicSampleCellIdentifier&quot;;
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }
    
    cell.textLabel.text = [self.items objectAtIndex:indexPath.row];
    
    return cell;
}
&lt;/span&gt;&lt;/pre&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;Lets us run the application. BOOM!!!. I am not able to see anything in the table view. This is because we have not yet assigned a data source and delegate.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;Assign DataSource and Delegate for UITableView&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;In order to perform this let us create an IBOutlet for our UITableView first. Now, let us assign data source and delegate.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;self.sampleTableView.dataSource = self;
self.sampleTableView.delegate = self;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;I have assigned them in viewDidLoad. Now, run your project again and now you will see dummy data on screen. WOW!!!&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEikYTNgQ3OkxP3VT3DYpzr0spGHidYX4duoVq7RzT3c4rqaoaJCycCZn4_OrD4kn8Vpzm3BO5iZAdFFur-i680r9SEZDM8poDUaj9zN1OkpN2rF4bLnj2RGebeqVWLFjlpB56Y8J1kCOyjt/s1600/Screen+Shot+2013-03-16+at+12.03.34+AM.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEikYTNgQ3OkxP3VT3DYpzr0spGHidYX4duoVq7RzT3c4rqaoaJCycCZn4_OrD4kn8Vpzm3BO5iZAdFFur-i680r9SEZDM8poDUaj9zN1OkpN2rF4bLnj2RGebeqVWLFjlpB56Y8J1kCOyjt/s320/Screen+Shot+2013-03-16+at+12.03.34+AM.png&quot; width=&quot;231&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;Its is working but we need to beautify it.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;Add background color&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;In order to add background color add below mentioned code snippet in viewDidLoad.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;self.sampleTableView.backgroundColor = [UIColor lightGrayColor];
&lt;/span&gt;&lt;/pre&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;b&gt;Add round corner&amp;nbsp;&lt;/b&gt;&lt;span style=&quot;color: #b45f06;&quot;&gt;[Note: QuartzCore is needed for this]&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
Add QuarttzCore framework and then add QuartCore.h to the viewcontroller.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;#import &amp;lt;QuartzCore/QuartzCore.h&amp;gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;Now in viewDidLoad add following snippet.
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;self.sampleTableView.layer.cornerRadius = 10.0f;
&lt;/span&gt;&lt;/pre&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;Change separator color&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
In order to change separator color we need to use separatorColor property of UITableView.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;self.sampleTableView.separatorColor = [UIColor grayColor];
&lt;/span&gt;&lt;/pre&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;b&gt;Add a border to UITableView &lt;/b&gt;&lt;span style=&quot;color: #b45f06;&quot;&gt;[Note: QuartzCore is needed for this]&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;self.sampleTableView.layer.borderColor = [UIColor grayColor].CGColor;
self.sampleTableView.layer.borderWidth = 1.0;
&lt;/span&gt;&lt;/pre&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;Change cell&#39;s text color&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;In order to change text color you need to update the cell creation code. We have created the cell in cellForRowAtIndex method. Use following snippet to change text color of cell.
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;cell.textLabel.textColor = [UIColor whiteColor];
&lt;/span&gt;&lt;/pre&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;Show Accessory Disclosure (Arrow at right)&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;In order to show accessory disclosure you need to set cell&#39;s accessoryType during cell creation in cellForRowAtIndex method.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
&lt;/span&gt;&lt;/pre&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;Change accessory disclosure color&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;By default accessory disclosure will have black color. In order to change the color of accessory disclosure you need to initialize accessory view with an image.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;cell.accessoryView = [[UIImageView alloc]
                           initWithImage:[UIImage imageNamed:@&quot;ArrowWhite.png&quot;]];
&lt;/span&gt;&lt;/pre&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;Let us see how does our table view look now:&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjk7uT3ZI4ltzLeMj_t8nmzdPQBYLinCOdXrtz2pG2PabqMnxc8-4K0jM_fj6I2HPemhLyFxpRzudo5IJCvPwN4NcDKGLD6Y0mdgN9XT2d_nXlCJDY2V19DNOdvDC3f6T8O2LfqVaxcgrYs/s1600/Screen+Shot+2013-03-16+at+12.58.43+AM.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjk7uT3ZI4ltzLeMj_t8nmzdPQBYLinCOdXrtz2pG2PabqMnxc8-4K0jM_fj6I2HPemhLyFxpRzudo5IJCvPwN4NcDKGLD6Y0mdgN9XT2d_nXlCJDY2V19DNOdvDC3f6T8O2LfqVaxcgrYs/s1600/Screen+Shot+2013-03-16+at+12.58.43+AM.png&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&amp;nbsp;There is lot more to UITableView and in the next article in this series we will look into selection and navigating to different view controllers and more. Hope this post was of some help. Please share and provide your feedback.&lt;/span&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://anujyadavcse.blogspot.com/feeds/5490446471637824434/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://anujyadavcse.blogspot.com/2013/03/uitableview-basic-tutorial.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1972826170038884797/posts/default/5490446471637824434'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1972826170038884797/posts/default/5490446471637824434'/><link rel='alternate' type='text/html' href='http://anujyadavcse.blogspot.com/2013/03/uitableview-basic-tutorial.html' title='UITableView basic tutorial'/><author><name>Anuj Yadav</name><uri>http://www.blogger.com/profile/11344768057475167404</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3-ODntmQstTHRlTt1oA-YBvV6br318GA_rLr7G3-SM_X-xD27XUU07WojozfU-SDPyaIFEyOgi4zM5D-6G5P-cUfca2SDi5DEhYOiGE7cGBikp2zqmsG9Xp-0_boZJQ/s220/DSC_02080z-1.jpg'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgVCi3thU0-vAOuzFD9UN52Rs3ox-QK656AzH0hzUWkFsSJAmWH9xLQvYgIFfzRMIBets90XXoSJ2oRSOfvRy2kClkQ0B3Rmw4aRQNkVbL-fhuCeka7jBd5G1VVzahEhlWPKDm-8v9tuBOK/s72-c/Screen+Shot+2013-03-15+at+8.56.22+PM.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1972826170038884797.post-8276738922353913746</id><published>2012-12-15T21:23:00.002-08:00</published><updated>2012-12-15T21:23:54.954-08:00</updated><title type='text'>Send Mail .NET</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;Allowing user to send mail (feedback, contact etc) is a very common feature in current web applications. In this series of post we will talk about some basic mail features and how to implement them in c#.&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;Basics&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;In order to send mail we need SMTP server configured as mails work over SMTP. You can configure SMTP server yourself or if you are using web hosting services you can get an account setup for you. In order to receive mails we need POP. For this tutorial series we will use gmail SMTP server.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;.NET APIs&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;.Net provides us with lots of classes present in System.Net.Mail to send an email. We will be using MailMessage, MailAddress and SmtpClient classes.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;We will create a MailHelper and will use it in Winforms, Asp.Net, Console etc.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;Mail Helper&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;using System.Collections.Generic;
using System.Net.Mail;

namespace MailConsole
{
    public class MailHelper
    {
        public static void SendMail(string subject,string message,List&lt;/span&gt;&lt;string&gt;&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt; to)
        {
            var mailMessage = new MailMessage()
            {
                From = new MailAddress(&quot;YOUR-MAILID@gmail.com&quot;),
                Subject = subject,
                Body = message
            };

            foreach (var id in to)
            {
                mailMessage.To.Add(id);
            }
            
            var smtp = new SmtpClient();
            smtp.Host = &quot;smtp.gmail.com&quot;;
            smtp.Port = 587;
            smtp.Credentials = new System.Net.NetworkCredential(&quot;YOUR-USERNAME&quot;, &quot;YOUR-PASSWORD&quot;);
            smtp.EnableSsl = true;
            smtp.Send(mailMessage);
        }
    }
}&lt;/span&gt;
&lt;/string&gt;&lt;/pre&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://anujyadavcse.blogspot.com/feeds/8276738922353913746/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://anujyadavcse.blogspot.com/2012/12/send-mail-net.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1972826170038884797/posts/default/8276738922353913746'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1972826170038884797/posts/default/8276738922353913746'/><link rel='alternate' type='text/html' href='http://anujyadavcse.blogspot.com/2012/12/send-mail-net.html' title='Send Mail .NET'/><author><name>Anuj Yadav</name><uri>http://www.blogger.com/profile/11344768057475167404</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3-ODntmQstTHRlTt1oA-YBvV6br318GA_rLr7G3-SM_X-xD27XUU07WojozfU-SDPyaIFEyOgi4zM5D-6G5P-cUfca2SDi5DEhYOiGE7cGBikp2zqmsG9Xp-0_boZJQ/s220/DSC_02080z-1.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1972826170038884797.post-1144453485672838701</id><published>2012-11-29T01:43:00.002-08:00</published><updated>2012-11-29T08:20:07.065-08:00</updated><title type='text'>Knowing Singelton </title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;Singelton pattern in one of the most commonly used and talked about &lt;a href=&quot;http://anujyadavcse.blogspot.in/2012/01/introduction-to-design-patterns.html&quot; target=&quot;_blank&quot;&gt;design pattern&lt;/a&gt;. Many appreciates it usefulness and many advocate against it. In this post we are not going to discuss all that but will concentrate on its implementation in c#.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;Type:&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;It is a creational &lt;a href=&quot;http://anujyadavcse.blogspot.in/2012/01/introduction-to-design-patterns.html&quot; target=&quot;_blank&quot;&gt;design pattern&lt;/a&gt;.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;Intent:&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;It ensures that only one instance of the class exists.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;Usage:&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;It is generally used when only one instance of a class is required. Thus, it can be seen to be used in logging frameworks, configuration objects etc.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;The ownership of instance creation lies with the class itself. This is because we can not ensure that only one instance will ever exists for the class if the responsibility lies with someone else.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;The class will instantiate the object when it will be used for the first time. This also ensures lazy initialization.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;Point to consider:&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;Singelton object is mostly made accessible globally and thus being abused by being used as global variable. We must keep in mind that not only the singelton object but the whole object graph associated to it (which can be traversed&amp;nbsp;through&amp;nbsp;it) becomes global. Though most of us will say no to using global variables but will readily say yes to singeltons.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;Simple Implementation:&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PlayingWithSingelton
{
    public class SimpleSingelton
    {
        private static SimpleSingelton _instance;

        private SimpleSingelton()
        {
            
        }

        public static SimpleSingelton CurrentInstance
        {
            get
            {
                if(_instance == null)
                {
                    _instance = new SimpleSingelton();
                }
                return _instance;
            }
        }

        public void Print()
        {
            Console.WriteLine(this.GetHashCode());
        }
    }
}
&lt;/span&gt;&lt;/pre&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;In our&amp;nbsp;SimpleSingelton class we have created a private constructor. This will ensure that no one else can instantiate&amp;nbsp;SimpleSingelton by calling its constructor.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;We have also create a private data&amp;nbsp;member&amp;nbsp;of type&amp;nbsp;SimpleSingelton. This will hold the lone instance of&amp;nbsp;SimpleSingelton. We have marked it static because we will access it from static members (property or method).&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;We have created a static property which will check if _instance is null or not. If it is null it will instantiate it and then return the _instance.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;This implementation looks promising but it is not thread safe. In a multi-threaded scenario two threads can check for the nullability of _instance almost at the same time and thus can create two instances of&amp;nbsp;SimpleSingelton as both will find _instance null.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;Partially Thread Safe Implementation&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace PlayingWithSingelton
{
    public class PartiallyThreadSafeSingelton
    {
        private static volatile PartiallyThreadSafeSingelton _instance;
        private static readonly Object Locker = new object();

        private PartiallyThreadSafeSingelton()
        {
            
        }

        public static PartiallyThreadSafeSingelton CurrentInstance
        {
            get
            {
                if(_instance == null)
                {
                    lock (Locker)
                    {
                        _instance = new PartiallyThreadSafeSingelton();
                    }
                }

                return _instance;

            }
        }
    }
}
&lt;/span&gt;&lt;/pre&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;In our&amp;nbsp;PartiallyThreadSafeSingelton class we have marked the _instance as volatile this means that the most up-to date &amp;nbsp;value of _instance will be used and the value will be requested every time we will use _instance although in the previous statements _instance value would have been retrieved.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;In our getter for CurrentInstance we have use a lock. This will ensure that only one thread will create an instance at a time. Wait!!! But, multiple threads can check for nullability simulatneously and then one thread can wait for the other to create instance and release lock. Then it will also create an instance.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;What if we check for nullability just before instantiating? Yes, we should.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;Process intensive Thread Safe Implementation&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PlayingWithSingelton
{
    public class ProcessIntensiveThreadSafeSingelton
    {
        private static volatile ProcessIntensiveThreadSafeSingelton _instance;
        private static readonly Object Locker = new object();

        private ProcessIntensiveThreadSafeSingelton()
        {
            
        }

        public static ProcessIntensiveThreadSafeSingelton CurrentInstance
        {
            get
            {
                lock (Locker)
                {
                    if (_instance == null)
                        _instance = new ProcessIntensiveThreadSafeSingelton();
                }
                return _instance;
                
            }
        }
    }
}
&lt;/span&gt;&lt;/pre&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;It is process intensive to acquire a lock every time. As the instantiation will happen only once. Thus we can change our implementation a bit and can check for nullability one more time but before acquiring lock.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;Thread Safe Implementation&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PlayingWithSingelton
{
    public class ThreadSafeSingelton
    {
        private static volatile ThreadSafeSingelton _instance;
        private static readonly Object Locker = new object();

        private ThreadSafeSingelton()
        {
            
        }

        public static ThreadSafeSingelton CurrentInstance
        {
            get
            {
                if (_instance == null)
                {
                    lock (Locker)
                    {
                        if (_instance == null)
                            _instance = new ThreadSafeSingelton();
                    }
                }
                return _instance;
                
            }
        }
    }
}
&lt;/span&gt;&lt;/pre&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;In future posts we will discuss more about singelton and its usage.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://anujyadavcse.blogspot.com/feeds/1144453485672838701/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://anujyadavcse.blogspot.com/2012/11/knowing-singelton.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1972826170038884797/posts/default/1144453485672838701'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1972826170038884797/posts/default/1144453485672838701'/><link rel='alternate' type='text/html' href='http://anujyadavcse.blogspot.com/2012/11/knowing-singelton.html' title='Knowing Singelton '/><author><name>Anuj Yadav</name><uri>http://www.blogger.com/profile/11344768057475167404</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3-ODntmQstTHRlTt1oA-YBvV6br318GA_rLr7G3-SM_X-xD27XUU07WojozfU-SDPyaIFEyOgi4zM5D-6G5P-cUfca2SDi5DEhYOiGE7cGBikp2zqmsG9Xp-0_boZJQ/s220/DSC_02080z-1.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1972826170038884797.post-3075272811742303588</id><published>2012-11-04T00:17:00.002-07:00</published><updated>2012-11-04T00:21:56.912-07:00</updated><title type='text'>C# Polymorphism - handle with care </title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;a href=&quot;https://github.com/ShareIT/AbstractClasses&quot; class=&quot;downloadCode&quot;&gt;Download&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;Overriding is the base for most of the design patterns which exists. It provides us with an essential tool called&amp;nbsp;&lt;span style=&quot;color: #333333; text-align: justify;&quot;&gt;Polymorphism&amp;nbsp;&lt;/span&gt;.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;b&gt;What is&amp;nbsp;&lt;span style=&quot;color: #333333; text-align: justify;&quot;&gt;Polymorphism&amp;nbsp;&lt;/span&gt;?&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #333333; font-family: Trebuchet MS, sans-serif; text-align: justify;&quot;&gt;Polymorphism means one interface and many forms. It is a characteristics of being able to assign a different meaning or usage to something in different contexts specifically to allow an entity such as a variable, a function or an object to have more than one form.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br style=&quot;color: #333333; text-align: justify;&quot; /&gt;&lt;/span&gt;
&lt;span style=&quot;color: #333333; font-family: Trebuchet MS, sans-serif; text-align: justify;&quot;&gt;There are two types of Polymorphism.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;b style=&quot;color: #333333; text-align: justify;&quot;&gt;Compile time:&lt;/b&gt;&lt;span style=&quot;color: #333333; text-align: justify;&quot;&gt;&amp;nbsp;function or operator overloading&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;b style=&quot;color: #333333; text-align: justify;&quot;&gt;Runtime:&lt;/b&gt;&lt;span style=&quot;color: #333333; text-align: justify;&quot;&gt;&amp;nbsp;Inheritence &amp;amp; virtual functions&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;span style=&quot;color: #333333; text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: #333333; text-align: justify;&quot;&gt;Here, we are going to talk about the Runtime Polymorphism.&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;span style=&quot;color: #333333; text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: #333333; text-align: justify;&quot;&gt;If you read the definition carefully you will see that there is going to be some type casting and compiler is going to made some assumptions. These assumptions may fail on execution. Let me explain this further.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;span style=&quot;color: #333333; text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: #333333; font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;b&gt;Type casting:&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: #333333; font-family: Trebuchet MS, sans-serif;&quot;&gt;There will be a parent interface (Interface, abstract class, class) and may be many child classes. These child classes will implement the polymorphic behavior in different ways. The consumer will use Parent class&#39; variable and the reference can be changed at runtime.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: #333333; font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: #333333; font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;b&gt;Assumptions:&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: #333333; font-family: Trebuchet MS, sans-serif;&quot;&gt;If we are using an interface and we cast an variable to that interface, compiler will assume that some child class of this variable&#39;s type will implement the methods specified by the interface. If this will not come out to be true it will throw exception at runtime.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;using System;

namespace AbstractClasses
{
    class Program
    {
        static void Main(string[] args)
        {
            Apple fruit = new Apple();
            fruit.Print();
            &lt;span style=&quot;color: red;&quot;&gt;IContract contract = (IContract) fruit;&lt;/span&gt;
            Console.ReadLine();
        }
    }

    internal interface IContract
    {
        void Display();
    }
    #region
    internal abstract class Fruit
    {
        public abstract string Name { get; set; }

        public virtual void Print()
        {
            Console.WriteLine(&quot;from abstract class&quot;);
        }
    }

    internal class Apple: Fruit
    {
        public override string Name { get; set; }

        public void Print()
        {
            Console.WriteLine(&quot;from child&quot;);
        }
    }
    #endregion
}&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: #333333; font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: #333333; font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;b&gt;Handle With Care:&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: #333333; font-family: Trebuchet MS, sans-serif;&quot;&gt;There are ways using which we can improve our code. Let us talk about them.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: #333333; font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;span style=&quot;color: #333333;&quot;&gt;1. We can use &#39;as&#39; keyword while casting a variable to an interface. This is because u&lt;/span&gt;&lt;span style=&quot;background-color: white; text-align: start;&quot;&gt;sing the&amp;nbsp;&lt;/span&gt;&lt;b style=&quot;background-color: white; text-align: start;&quot;&gt;as&lt;/b&gt;&lt;span style=&quot;background-color: white; text-align: start;&quot;&gt;&amp;nbsp;operator is a better coding strategy than a straight cast because it yields a null on a conversion failure rather than raising an exception.&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;using System;

namespace AbstractClasses
{
    class Program
    {
        static void Main(string[] args)
        {
            Apple fruit = new Apple();
            fruit.Print();
            //IContract contract = (IContract) fruit; //Invalid cast exception

            IContract contract =  fruit as IContract;
            if(contract != null)
                contract.Display();
            Console.ReadLine();
        }
    }

    internal interface IContract
    {
        void Display();
    }
    #region
    internal abstract class Fruit
    {
        public abstract string Name { get; set; }

        public virtual void Print()
        {
            Console.WriteLine(&quot;from abstract class&quot;);
        }
    }

    internal class Apple: Fruit
    {
        public override string Name { get; set; }

        public void Print()
        {
            Console.WriteLine(&quot;from child&quot;);
        }
    }
    #endregion
}
&lt;/span&gt;&lt;/pre&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;2. We can use sealed keyword on classes which we do not want to be inherited. Then the compiler will not assume that the object being cast is going to exhibit polymorphic behavior and will check its cast to the interface at compile time.
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;using System;

namespace AbstractClasses
{
    class Program
    {
        static void Main(string[] args)
        {
            Apple fruit = new Apple();
            fruit.Print();
            
            IContract contract =  fruit as &lt;span style=&quot;color: red;&quot;&gt;IContract&lt;/span&gt;;
            if(contract != null)
                contract.Display();
            Console.ReadLine();
        }
    }

    internal interface IContract
    {
        void Display();
    }
    #region
    internal abstract class Fruit
    {
        public abstract string Name { get; set; }

        public virtual void Print()
        {
            Console.WriteLine(&quot;from abstract class&quot;);
        }
    }

    internal &lt;span style=&quot;background-color: #b6d7a8;&quot;&gt;sealed &lt;/span&gt;class Apple: Fruit
    {
        public override string Name { get; set; }

        public void Print()
        {
            Console.WriteLine(&quot;from child&quot;);
        }
    }
    #endregion
}
&lt;/span&gt;&lt;/pre&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;b&gt;Compile Time Error:
&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;Cannot convert type &#39;AbstractClasses.Apple&#39; to &#39;AbstractClasses.IContract&#39; via a reference conversion, boxing conversion, unboxing conversion, wrapping conversion, or null type conversion.
&lt;/span&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://anujyadavcse.blogspot.com/feeds/3075272811742303588/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://anujyadavcse.blogspot.com/2012/11/c-polymorphism-handle-with-care.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1972826170038884797/posts/default/3075272811742303588'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1972826170038884797/posts/default/3075272811742303588'/><link rel='alternate' type='text/html' href='http://anujyadavcse.blogspot.com/2012/11/c-polymorphism-handle-with-care.html' title='C# Polymorphism - handle with care '/><author><name>Anuj Yadav</name><uri>http://www.blogger.com/profile/11344768057475167404</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3-ODntmQstTHRlTt1oA-YBvV6br318GA_rLr7G3-SM_X-xD27XUU07WojozfU-SDPyaIFEyOgi4zM5D-6G5P-cUfca2SDi5DEhYOiGE7cGBikp2zqmsG9Xp-0_boZJQ/s220/DSC_02080z-1.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1972826170038884797.post-7777627747609320128</id><published>2012-11-03T22:43:00.000-07:00</published><updated>2012-11-03T22:43:24.732-07:00</updated><title type='text'>c# reference types passed by value or reference</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;a class=&quot;downloadCode&quot; href=&quot;https://github.com/ShareIT/ArgumentsPassByValue&quot;&gt;&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;Download&lt;/span&gt;&lt;/a&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;Time and again I have heard that in C#, method arguments are passed based upon there type. i.e. Value types are passed by value and reference types are passed by reference. This is so untrue. Reference types have nothing to do with pass by value.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;Let us talk some basic. Consider the&amp;nbsp;assignment&amp;nbsp;first. When you assign a value type to another its value is copied. This is because value type variable contains its data directly. When you assign a reference type variable to another only the reference gets copied. This is because a reference type variable does not contains its data directly. It only holds reference to data.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;Thus, when we pass a value type, its value gets copied and when we pass a reference type its reference gets copied. That is why if we change the value of a value type variable in the block (method), the change is not seen outside of it. On the other hand if we change the value of member of reference passed to the block from within the block the change persists outside the block.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;Ok ! OK!&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;Some of you may say that, that is why reference types are passed by reference.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;Wait! Wait!&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;Try changing the reference itself. You won&#39;t be able to do that. So actually you changed the value on the heap which was being pointed by the reference variable but you were not able to change the variable. Now, try using out or ref keywords and create a new reference type variable from within the block. You will succeed.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;Actually when we are passing reference type without using out or ref we are passing just a pointer and that is why if we are trying to use new (to create a new object) we were not able to do that. On the other hand when we passed them using out or ref we passed pointer to pointer and that is why we were able to change the pointer being pointed using the new keyword.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;Thus, we can safely say that in each case we changed the value being pointed by the reference and were not able to change the argument.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;using System;
using System.Threading;

namespace ArgumentsPassByValue
{
    class Program
    {
        static void Main(string[] args)
        {
            Worker worker = new Worker();
            Request request = new Request();
            request.Id = 4;

            Console.WriteLine(request.Id + &quot; : &quot; + request.GetHashCode());

            worker.PassByReference(ref request);
            Console.WriteLine(request.Id + &quot; : &quot; + request.GetHashCode());

            //first request object will be collected as it is not being used
            GC.Collect();

            //forced thred to sleep so that you can see that first object has been 
            //collected and still we are using the variable request because it is pointing to some other location now.
            Thread.Sleep(1000);

            Console.WriteLine(request.Id + &quot; : &quot; + request.GetHashCode());
            Console.ReadLine();
        }
    }

    internal class Request
    {   
        public int Id { get; set; }

        ~Request()
        {
            Console.WriteLine(this.GetHashCode() + &quot; : I am dying&quot;);
        }
    }

    internal class Worker
    {
        public void PassByReference(ref Request request)
        {
            request = new Request();
            request.Id = 6;
        }
        public void ValueChanger(Request request)
        {
            Console.WriteLine(request.Id + &quot; : &quot; + request.GetHashCode());
            request = new Request();
            request.Id = 6;
        }
    }
}

&lt;/span&gt;&lt;/pre&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;Some more references :

http://msdn.microsoft.com/en-us/library/s6938f28.aspx
&lt;/span&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://anujyadavcse.blogspot.com/feeds/7777627747609320128/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://anujyadavcse.blogspot.com/2012/11/c-reference-types-passed-by-value-or.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1972826170038884797/posts/default/7777627747609320128'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1972826170038884797/posts/default/7777627747609320128'/><link rel='alternate' type='text/html' href='http://anujyadavcse.blogspot.com/2012/11/c-reference-types-passed-by-value-or.html' title='c# reference types passed by value or reference'/><author><name>Anuj Yadav</name><uri>http://www.blogger.com/profile/11344768057475167404</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3-ODntmQstTHRlTt1oA-YBvV6br318GA_rLr7G3-SM_X-xD27XUU07WojozfU-SDPyaIFEyOgi4zM5D-6G5P-cUfca2SDi5DEhYOiGE7cGBikp2zqmsG9Xp-0_boZJQ/s220/DSC_02080z-1.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1972826170038884797.post-8913680743246538842</id><published>2012-11-02T13:17:00.000-07:00</published><updated>2012-11-03T22:30:12.302-07:00</updated><title type='text'>Callback in c#</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br/&gt;&lt;a href=&quot;https://github.com/ShareIT/callbacksincsharp&quot; class=&quot;downloadCode&quot;&gt;Download&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;Running tasks in background is the need of the hour when working on real world applications. There are few tasks which we can fire and forget but for few of them we will like to receive the feedback. This is when callbacks comes into the picture and provides a channel for these objects to communicate with each other.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;These tasks are very common in desktop and mobile applications. In this post we will talk about callback mechanism in c#. In future post we will build upon this and do lot more.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;Using interfaces for callbacks in c#&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;using System;
using System.Threading;

namespace Callbacks
{
    
    class Program
    {
        static void Main(string[] args)
        {
            var consumer = new Consumer();
            consumer.DoWork();
            Console.ReadLine();
        }
    }

    interface IOnProcessCompleteListener
    {
        void OnProcessComplete(string message);
    }

    internal class Consumer: IOnProcessCompleteListener
    {
        private Worker _worker;
        public Consumer()
        {
            _worker = new Worker();
            _worker.OnProcessCompleteListener = this;
        }

        public void DoWork()
        {
            Thread backgroundThread = new Thread(_worker.DoBackgroundWork);
            backgroundThread.Start();
            Console.WriteLine(&quot;Control is with main thread&quot;);
        }

        public void OnProcessComplete(string message)
        {
            Console.WriteLine(message);
        }
    }
    internal class Worker
    {
        public IOnProcessCompleteListener OnProcessCompleteListener;

        public void DoBackgroundWork()
        {
            Console.WriteLine(&quot;In worker&quot;);
            Thread.Sleep(1000);

            if(OnProcessCompleteListener != null)
                OnProcessCompleteListener.OnProcessComplete(&quot;Consumer has been called back&quot;);
        }

    }
}


&lt;/span&gt;&lt;/pre&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;Code is self explanatory and thus I will provide just a brief on it. We created an interface IOnProcessCompleteListener it has just one method. In the Worker class we have an data member which accepts an object of class which implements IOnProcessCompleteListener. This ensures that we can call OnProcessComplete method on this member once we are ready to call it back. The Consumer class will implement IOnPropertyChangeListener. Once Worker is done with stuff it will notify Consumer using the callback object. Just to simulate some background process I have made the worker thread to sleep before giving the call back.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;Using Delegates to callback in c#

&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;using System;
using System.Threading;

namespace CallBacksUsingDelegate
{
    class Program
    {
        static void Main(string[] args)
        {

            Listener listener = new Listener();
            listener.DoWork();
            Console.WriteLine(&quot;Now in main thread&quot;);
            Console.ReadLine();
        }
    }

    internal delegate void OnProcessComplete(string message);

    internal class Worker
    {
        public OnProcessComplete ProcessComplete;

        public void Process()
        {
            Console.WriteLine(&quot;Process: Running on &quot; + Thread.CurrentThread.Name);
            Thread.Sleep(1000);
            if (ProcessComplete != null)
                ProcessComplete.Invoke(&quot;Process has completed&quot;);
        }
    }

    internal class Listener
    {
        private Worker _worker;
        public Listener()
        {
            _worker = new Worker();
            _worker.ProcessComplete = this.ProcessCompleteListener;
        }

        public void DoWork()
        {
            Thread backgroundThread = new Thread(_worker.Process);
            backgroundThread.Name = &quot;Background Thread&quot;;
            backgroundThread.Start();
        }

        private void ProcessCompleteListener(string message)
        {
            Console.WriteLine(message);
        }
    }

}

&lt;/span&gt;&lt;/pre&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;In this case we have a delegate - OnProcessComplete. Class worker has an object of type OnProcessComplete and class Listener passes the callback function to the Worker wrapped in this delegate. Once the Worker is done with its stuff it invokes the delegate and passes the control back.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;In the coming posts we will explore this power a bit more and try to do something more meaningful.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;Your inputs are really important for me so please do provide them. Share it if you care :)&lt;/span&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://anujyadavcse.blogspot.com/feeds/8913680743246538842/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://anujyadavcse.blogspot.com/2012/11/callback-in-c.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1972826170038884797/posts/default/8913680743246538842'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1972826170038884797/posts/default/8913680743246538842'/><link rel='alternate' type='text/html' href='http://anujyadavcse.blogspot.com/2012/11/callback-in-c.html' title='Callback in c#'/><author><name>Anuj Yadav</name><uri>http://www.blogger.com/profile/11344768057475167404</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3-ODntmQstTHRlTt1oA-YBvV6br318GA_rLr7G3-SM_X-xD27XUU07WojozfU-SDPyaIFEyOgi4zM5D-6G5P-cUfca2SDi5DEhYOiGE7cGBikp2zqmsG9Xp-0_boZJQ/s220/DSC_02080z-1.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1972826170038884797.post-8698787300296823951</id><published>2012-10-24T10:15:00.000-07:00</published><updated>2012-10-24T10:26:00.085-07:00</updated><title type='text'>Android - Disable Text Selection</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div class=&quot;MsoNoSpacing&quot;&gt;
&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: &amp;quot;Tahoma&amp;quot;,&amp;quot;sans-serif&amp;quot;; mso-ansi-language: EN-US;&quot;&gt;In order to disable text selection in a WebView we can
use following approaches:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNoSpacing&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNoSpacing&quot;&gt;
&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: &amp;quot;Tahoma&amp;quot;,&amp;quot;sans-serif&amp;quot;; mso-ansi-language: EN-US;&quot;&gt;&lt;b&gt;CSS&lt;o:p&gt;&lt;/o:p&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;-moz-border-radius: 1em 1em 1em 1em; background-color: #1a0202; border-radius: 1em 1em 1em 1em; color: silver; margin: 10px; padding: 10px;&quot;&gt;
&lt;div class=&quot;MsoNoSpacing&quot;&gt;
&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: &amp;quot;Tahoma&amp;quot;,&amp;quot;sans-serif&amp;quot;; mso-ansi-language: EN-US;&quot;&gt;* { &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNoSpacing&quot;&gt;
&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: &amp;quot;Tahoma&amp;quot;,&amp;quot;sans-serif&amp;quot;; mso-ansi-language: EN-US;&quot;&gt;&amp;nbsp; user-select:
none;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNoSpacing&quot;&gt;
&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: &amp;quot;Tahoma&amp;quot;,&amp;quot;sans-serif&amp;quot;; mso-ansi-language: EN-US;&quot;&gt;-moz-user-select: -moz-none;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNoSpacing&quot;&gt;
&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: &amp;quot;Tahoma&amp;quot;,&amp;quot;sans-serif&amp;quot;; mso-ansi-language: EN-US;&quot;&gt;-khtml-user-select: none;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNoSpacing&quot;&gt;
&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: &amp;quot;Tahoma&amp;quot;,&amp;quot;sans-serif&amp;quot;; mso-ansi-language: EN-US;&quot;&gt;-webkit-user-select: none;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNoSpacing&quot;&gt;
&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: &amp;quot;Tahoma&amp;quot;,&amp;quot;sans-serif&amp;quot;; mso-ansi-language: EN-US;&quot;&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNoSpacing&quot;&gt;
&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: &amp;quot;Tahoma&amp;quot;,&amp;quot;sans-serif&amp;quot;; mso-ansi-language: EN-US;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;MsoNoSpacing&quot;&gt;
&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: &amp;quot;Tahoma&amp;quot;,&amp;quot;sans-serif&amp;quot;; mso-ansi-language: EN-US;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNoSpacing&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNoSpacing&quot;&gt;
&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: &amp;quot;Tahoma&amp;quot;,&amp;quot;sans-serif&amp;quot;; mso-ansi-language: EN-US;&quot;&gt;This approach will not work on all the versions of
Android as the support was not there till late.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNoSpacing&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNoSpacing&quot;&gt;
&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: &amp;quot;Tahoma&amp;quot;,&amp;quot;sans-serif&amp;quot;; mso-ansi-language: EN-US;&quot;&gt;&lt;b&gt;Handling LongClick&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: &amp;quot;Tahoma&amp;quot;,&amp;quot;sans-serif&amp;quot;; mso-ansi-language: EN-US;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;div style=&quot;background-color: #1a0202; border-bottom-left-radius: 1em; border-bottom-right-radius: 1em; border-top-left-radius: 1em; border-top-right-radius: 1em; margin: 10px; padding: 10px;&quot;&gt;
&lt;div class=&quot;MsoNoSpacing&quot;&gt;
&lt;br /&gt;
&lt;span style=&quot;color: silver; font-family: Tahoma, sans-serif;&quot;&gt;public void onCreate(Bundle savedInstanceState) {&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: silver; font-family: Tahoma, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; super.onCreate(savedInstanceState);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: silver; font-family: Tahoma, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; setContentView(R.layout.activity_main);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: silver; font-family: Tahoma, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; WebView webView = (WebView) this.findViewById(R.id.webView1);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: silver; font-family: Tahoma, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; webView.loadData(&quot;&amp;lt;html&amp;gt;&amp;lt;head&amp;gt;&amp;lt;style&amp;gt;head&amp;gt;&amp;lt;body&amp;gt;You scored &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;b&amp;gt;192&amp;lt;/b&amp;gt; &amp;nbsp; &amp;nbsp; points.&amp;lt;/body&amp;gt;&amp;lt;/html&amp;gt;&quot;, &quot;text/html&quot;, null);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: silver; font-family: Tahoma, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: silver; font-family: Tahoma, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; webView.setOnLongClickListener(new View.OnLongClickListener() {&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: silver; font-family: Tahoma, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: silver; font-family: Tahoma, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; public boolean onLongClick(View v) {&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: silver; font-family: Tahoma, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;return true;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: silver; font-family: Tahoma, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: silver; font-family: Tahoma, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; });&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: silver; font-family: Tahoma, sans-serif;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;color: silver; font-family: verdana;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;MsoNoSpacing&quot;&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: &amp;quot;Tahoma&amp;quot;,&amp;quot;sans-serif&amp;quot;; mso-ansi-language: EN-US;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;MsoNoSpacing&quot; style=&quot;color: silver; font-family: verdana;&quot;&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://anujyadavcse.blogspot.com/feeds/8698787300296823951/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://anujyadavcse.blogspot.com/2012/10/android-disable-text-selection.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1972826170038884797/posts/default/8698787300296823951'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1972826170038884797/posts/default/8698787300296823951'/><link rel='alternate' type='text/html' href='http://anujyadavcse.blogspot.com/2012/10/android-disable-text-selection.html' title='Android - Disable Text Selection'/><author><name>Anuj Yadav</name><uri>http://www.blogger.com/profile/11344768057475167404</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3-ODntmQstTHRlTt1oA-YBvV6br318GA_rLr7G3-SM_X-xD27XUU07WojozfU-SDPyaIFEyOgi4zM5D-6G5P-cUfca2SDi5DEhYOiGE7cGBikp2zqmsG9Xp-0_boZJQ/s220/DSC_02080z-1.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1972826170038884797.post-1188464351876679726</id><published>2012-10-21T21:00:00.001-07:00</published><updated>2012-10-21T21:12:32.663-07:00</updated><title type='text'>Split String in C++ with delimiters</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
&lt;div class=&quot;MsoNoSpacing&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Tahoma&amp;quot;,&amp;quot;sans-serif&amp;quot;;&quot;&gt;In order
to split string in c++ we can use strtok().&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNoSpacing&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNoSpacing&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Tahoma&amp;quot;,&amp;quot;sans-serif&amp;quot;;&quot;&gt;A
sequence of calls to this function split&amp;nbsp;str&amp;nbsp;into tokens, which are
sequences of contiguous characters separated by any of the characters that are
part of&amp;nbsp;delimiters.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNoSpacing&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNoSpacing&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Tahoma&amp;quot;,&amp;quot;sans-serif&amp;quot;;&quot;&gt;On a
first call, the function expects a C string as argument for&amp;nbsp;str, whose
first character is used as the starting location to scan for tokens. In
subsequent calls, the function expects a null pointer and uses the position
right after the end of last token as the new starting location for
scanning.&amp;nbsp;&lt;a href=&quot;http://www.cplusplus.com/reference/clibrary/cstring/strtok/&quot;&gt;&lt;span style=&quot;font-size: 13.5pt;&quot;&gt;Read More Here&lt;/span&gt;&lt;/a&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNoSpacing&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNoSpacing&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Tahoma&amp;quot;,&amp;quot;sans-serif&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;#include &amp;lt;iostream.h&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNoSpacing&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Tahoma&amp;quot;,&amp;quot;sans-serif&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;#include &amp;lt;string.h&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNoSpacing&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNoSpacing&quot;&gt;
&lt;span style=&quot;color: #445588; font-family: &amp;quot;Tahoma&amp;quot;,&amp;quot;sans-serif&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;Tahoma&amp;quot;,&amp;quot;sans-serif&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt; main(&lt;span style=&quot;color: #445588;&quot;&gt;int&lt;/span&gt; argc, &lt;span style=&quot;color: #445588;&quot;&gt;char&lt;/span&gt;** argv)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNoSpacing&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Tahoma&amp;quot;,&amp;quot;sans-serif&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNoSpacing&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Tahoma&amp;quot;,&amp;quot;sans-serif&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;i&gt;&lt;span style=&quot;color: #999988;&quot;&gt;//
multiple delimiters can be provided&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNoSpacing&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Tahoma&amp;quot;,&amp;quot;sans-serif&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #445588;&quot;&gt;char&lt;/span&gt;
const delimiters[] = &lt;span style=&quot;color: #dd1144;&quot;&gt;&quot;/:&quot;&lt;/span&gt;;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNoSpacing&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNoSpacing&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Tahoma&amp;quot;,&amp;quot;sans-serif&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;i&gt;&lt;span style=&quot;color: #999988;&quot;&gt;//
initial string to split&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/i&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNoSpacing&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Tahoma&amp;quot;,&amp;quot;sans-serif&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;std::string sCFIString = &lt;span style=&quot;color: #dd1144;&quot;&gt;&quot;/6/2702!/4/6/6/122/1:3&quot;&lt;/span&gt;;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNoSpacing&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNoSpacing&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Tahoma&amp;quot;,&amp;quot;sans-serif&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;i&gt;&lt;span style=&quot;color: #999988;&quot;&gt;//
this pointer will point to the next word after every &#39;strtok&#39; call&lt;/span&gt;&lt;/i&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNoSpacing&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Tahoma&amp;quot;,&amp;quot;sans-serif&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: #445588;&quot;&gt;char&lt;/span&gt;
*token = strtok(const_cast&amp;lt;&lt;span style=&quot;color: #445588;&quot;&gt;char&lt;/span&gt;*&amp;gt;(sCFIString.c_str()),
delimiters);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNoSpacing&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNoSpacing&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Tahoma&amp;quot;,&amp;quot;sans-serif&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;i&gt;&lt;span style=&quot;color: #999988;&quot;&gt;//
if returned pointer is NULL, then there is no more words&lt;/span&gt;&lt;/i&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNoSpacing&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Tahoma&amp;quot;,&amp;quot;sans-serif&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;while (&lt;span style=&quot;color: #009999;&quot;&gt;0&lt;/span&gt; != token)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNoSpacing&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Tahoma&amp;quot;,&amp;quot;sans-serif&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNoSpacing&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Tahoma&amp;quot;,&amp;quot;sans-serif&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;puts(token);
&lt;i&gt;&lt;span style=&quot;color: #999988;&quot;&gt;// print the word&lt;/span&gt;&lt;/i&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNoSpacing&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Tahoma&amp;quot;,&amp;quot;sans-serif&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;token
= strtok(&lt;span style=&quot;color: #0086b3;&quot;&gt;NULL&lt;/span&gt;, delimiters); &lt;i&gt;&lt;span style=&quot;color: #999988;&quot;&gt;// move to the next one&lt;/span&gt;&lt;/i&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNoSpacing&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Tahoma&amp;quot;,&amp;quot;sans-serif&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNoSpacing&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNoSpacing&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Tahoma&amp;quot;,&amp;quot;sans-serif&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return &lt;span style=&quot;color: #009999;&quot;&gt;0&lt;/span&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNoSpacing&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Tahoma&amp;quot;,&amp;quot;sans-serif&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNoSpacing&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNoSpacing&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Tahoma&amp;quot;,&amp;quot;sans-serif&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;Output&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNoSpacing&quot;&gt;
&lt;span style=&quot;color: #009999; font-family: &amp;quot;Tahoma&amp;quot;,&amp;quot;sans-serif&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;6&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;Tahoma&amp;quot;,&amp;quot;sans-serif&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNoSpacing&quot;&gt;
&lt;span style=&quot;color: #009999; font-family: &amp;quot;Tahoma&amp;quot;,&amp;quot;sans-serif&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;2702&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;Tahoma&amp;quot;,&amp;quot;sans-serif&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;!&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNoSpacing&quot;&gt;
&lt;span style=&quot;color: #009999; font-family: &amp;quot;Tahoma&amp;quot;,&amp;quot;sans-serif&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;Tahoma&amp;quot;,&amp;quot;sans-serif&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNoSpacing&quot;&gt;
&lt;span style=&quot;color: #009999; font-family: &amp;quot;Tahoma&amp;quot;,&amp;quot;sans-serif&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;6&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;Tahoma&amp;quot;,&amp;quot;sans-serif&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNoSpacing&quot;&gt;
&lt;span style=&quot;color: #009999; font-family: &amp;quot;Tahoma&amp;quot;,&amp;quot;sans-serif&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;6&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;Tahoma&amp;quot;,&amp;quot;sans-serif&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNoSpacing&quot;&gt;
&lt;span style=&quot;color: #009999; font-family: &amp;quot;Tahoma&amp;quot;,&amp;quot;sans-serif&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;122&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;Tahoma&amp;quot;,&amp;quot;sans-serif&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNoSpacing&quot;&gt;
&lt;span style=&quot;color: #009999; font-family: &amp;quot;Tahoma&amp;quot;,&amp;quot;sans-serif&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;Tahoma&amp;quot;,&amp;quot;sans-serif&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNoSpacing&quot;&gt;
&lt;span style=&quot;color: #009999; font-family: &amp;quot;Tahoma&amp;quot;,&amp;quot;sans-serif&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;Tahoma&amp;quot;,&amp;quot;sans-serif&amp;quot;; mso-fareast-language: EN-IN;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNoSpacing&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://anujyadavcse.blogspot.com/feeds/1188464351876679726/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://anujyadavcse.blogspot.com/2012/10/split-string-in-c-with-delimiters.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1972826170038884797/posts/default/1188464351876679726'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1972826170038884797/posts/default/1188464351876679726'/><link rel='alternate' type='text/html' href='http://anujyadavcse.blogspot.com/2012/10/split-string-in-c-with-delimiters.html' title='Split String in C++ with delimiters'/><author><name>Anuj Yadav</name><uri>http://www.blogger.com/profile/11344768057475167404</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3-ODntmQstTHRlTt1oA-YBvV6br318GA_rLr7G3-SM_X-xD27XUU07WojozfU-SDPyaIFEyOgi4zM5D-6G5P-cUfca2SDi5DEhYOiGE7cGBikp2zqmsG9Xp-0_boZJQ/s220/DSC_02080z-1.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1972826170038884797.post-7250145338973962648</id><published>2012-10-20T22:16:00.000-07:00</published><updated>2012-10-20T22:28:44.649-07:00</updated><title type='text'>Convert std::string to char* and const char* - c++</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div class=&quot;MsoNoSpacing&quot;&gt;
&lt;br /&gt;
&lt;div class=&quot;MsoNoSpacing&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Tahoma&amp;quot;,&amp;quot;sans-serif&amp;quot;; mso-fareast-language: EN-GB;&quot;&gt;&lt;b&gt;Convert std::string to const char*&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;Tahoma&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 9.0pt; mso-fareast-language: EN-GB;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNoSpacing&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNoSpacing&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Tahoma&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 9.0pt; mso-fareast-language: EN-GB;&quot;&gt;std&lt;b&gt;::&lt;/b&gt;string name &lt;b&gt;=&lt;/b&gt; &lt;span style=&quot;color: #dd1144;&quot;&gt;&quot;Anuj&quot;&lt;/span&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNoSpacing&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;Tahoma&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 9.0pt; mso-fareast-language: EN-GB;&quot;&gt;const&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: &amp;quot;Tahoma&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 9.0pt; mso-fareast-language: EN-GB;&quot;&gt; &lt;b&gt;&lt;span style=&quot;color: #445588;&quot;&gt;char&lt;/span&gt;*&lt;/b&gt; constName &lt;b&gt;=&lt;/b&gt; name.c_str();&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNoSpacing&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNoSpacing&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Tahoma&amp;quot;,&amp;quot;sans-serif&amp;quot;; mso-fareast-language: EN-GB;&quot;&gt;&lt;b&gt;Convert std::string to char*&lt;/b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNoSpacing&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNoSpacing&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Tahoma&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 9.0pt; mso-fareast-language: EN-GB;&quot;&gt;std&lt;b&gt;::&lt;/b&gt;string name &lt;b&gt;=&lt;/b&gt; &lt;span style=&quot;color: #dd1144;&quot;&gt;&quot;Anuj&quot;&lt;/span&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNoSpacing&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;Tahoma&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 9.0pt; mso-fareast-language: EN-GB;&quot;&gt;const&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: &amp;quot;Tahoma&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 9.0pt; mso-fareast-language: EN-GB;&quot;&gt; &lt;b&gt;&lt;span style=&quot;color: #445588;&quot;&gt;char&lt;/span&gt;*&lt;/b&gt; constName &lt;b&gt;=&lt;/b&gt; name.c_str();&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNoSpacing&quot;&gt;
&lt;b&gt;&lt;span style=&quot;color: #445588; font-family: &amp;quot;Tahoma&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 9.0pt; mso-fareast-language: EN-GB;&quot;&gt;char&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: &amp;quot;Tahoma&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 9.0pt; mso-fareast-language: EN-GB;&quot;&gt; &lt;b&gt;*&lt;/b&gt;ptrToName &lt;b&gt;=&lt;/b&gt; &lt;b&gt;const_cast&amp;lt;&lt;span style=&quot;color: #445588;&quot;&gt;char&lt;/span&gt;*&amp;gt;&lt;/b&gt;(name.c_str());&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNoSpacing&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNoSpacing&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Tahoma&amp;quot;,&amp;quot;sans-serif&amp;quot;; mso-fareast-language: EN-GB;&quot;&gt;&lt;b&gt;A simple progam&amp;nbsp;&lt;/b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNoSpacing&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNoSpacing&quot;&gt;
&lt;b&gt;&lt;span style=&quot;color: #999999; font-family: &amp;quot;Tahoma&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 9.0pt; mso-fareast-language: EN-GB;&quot;&gt;#include &amp;lt;iostream&amp;gt;&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: &amp;quot;Tahoma&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 9.0pt; mso-fareast-language: EN-GB;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNoSpacing&quot;&gt;
&lt;b&gt;&lt;span style=&quot;color: #999999; font-family: &amp;quot;Tahoma&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 9.0pt; mso-fareast-language: EN-GB;&quot;&gt;#include &amp;lt;stdio.h&amp;gt;&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: &amp;quot;Tahoma&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 9.0pt; mso-fareast-language: EN-GB;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNoSpacing&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;Tahoma&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 9.0pt; mso-fareast-language: EN-GB;&quot;&gt;using&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: &amp;quot;Tahoma&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 9.0pt; mso-fareast-language: EN-GB;&quot;&gt; &lt;b&gt;namespace&lt;/b&gt;
std;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNoSpacing&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNoSpacing&quot;&gt;
&lt;b&gt;&lt;span style=&quot;color: #445588; font-family: &amp;quot;Tahoma&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 9.0pt; mso-fareast-language: EN-GB;&quot;&gt;int&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: &amp;quot;Tahoma&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 9.0pt; mso-fareast-language: EN-GB;&quot;&gt; main()&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNoSpacing&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Tahoma&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 9.0pt; mso-fareast-language: EN-GB;&quot;&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNoSpacing&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Tahoma&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 9.0pt; mso-fareast-language: EN-GB;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;std&lt;b&gt;::&lt;/b&gt;string name &lt;b&gt;=&lt;/b&gt;
&lt;span style=&quot;color: #dd1144;&quot;&gt;&quot;Anuj&quot;&lt;/span&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNoSpacing&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Tahoma&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 9.0pt; mso-fareast-language: EN-GB;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;b&gt;const&lt;/b&gt; &lt;b&gt;&lt;span style=&quot;color: #445588;&quot;&gt;char&lt;/span&gt;*&lt;/b&gt; constName &lt;b&gt;=&lt;/b&gt; name.c_str();&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNoSpacing&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Tahoma&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 9.0pt; mso-fareast-language: EN-GB;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;b&gt;&lt;span style=&quot;color: #445588;&quot;&gt;char&lt;/span&gt;&lt;/b&gt;
&lt;b&gt;*&lt;/b&gt;ptrToName &lt;b&gt;=&lt;/b&gt; &lt;b&gt;const_cast&amp;lt;&lt;span style=&quot;color: #445588;&quot;&gt;char&lt;/span&gt;*&amp;gt;&lt;/b&gt;(name.c_str());&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNoSpacing&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Tahoma&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 9.0pt; mso-fareast-language: EN-GB;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;printf(&lt;span style=&quot;color: #dd1144;&quot;&gt;&quot;%s&quot;&lt;/span&gt;,constName);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNoSpacing&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Tahoma&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 9.0pt; mso-fareast-language: EN-GB;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;printf(&lt;span style=&quot;color: #dd1144;&quot;&gt;&quot;%s&quot;&lt;/span&gt;,ptrToName);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNoSpacing&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Tahoma&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 9.0pt; mso-fareast-language: EN-GB;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;cout &lt;b&gt;&amp;lt;&amp;lt;&lt;/b&gt; name &lt;b&gt;&amp;lt;&amp;lt;&lt;/b&gt;
endl;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNoSpacing&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Tahoma&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 9.0pt; mso-fareast-language: EN-GB;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;b&gt;return&lt;/b&gt; &lt;span style=&quot;color: #009999;&quot;&gt;0&lt;/span&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNoSpacing&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Tahoma&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 9.0pt; mso-fareast-language: EN-GB;&quot;&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNoSpacing&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://anujyadavcse.blogspot.com/feeds/7250145338973962648/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://anujyadavcse.blogspot.com/2012/10/convert-stdstring-to-const-char-std.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1972826170038884797/posts/default/7250145338973962648'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1972826170038884797/posts/default/7250145338973962648'/><link rel='alternate' type='text/html' href='http://anujyadavcse.blogspot.com/2012/10/convert-stdstring-to-const-char-std.html' title='Convert std::string to char* and const char* - c++'/><author><name>Anuj Yadav</name><uri>http://www.blogger.com/profile/11344768057475167404</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3-ODntmQstTHRlTt1oA-YBvV6br318GA_rLr7G3-SM_X-xD27XUU07WojozfU-SDPyaIFEyOgi4zM5D-6G5P-cUfca2SDi5DEhYOiGE7cGBikp2zqmsG9Xp-0_boZJQ/s220/DSC_02080z-1.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1972826170038884797.post-1120009193670206703</id><published>2012-08-19T23:53:00.000-07:00</published><updated>2012-10-01T23:44:39.845-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="iOS"/><title type='text'>Convert NSNumber to NSString</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
In order to convert NSNumber to NSString you can use following method:&lt;br /&gt;
&lt;br /&gt;
NSNumber *myNSNumber = [NSNumber numberWithInt:1];&lt;br /&gt;
NSString *myString = [myNSNumber stringValue];&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://anujyadavcse.blogspot.com/feeds/1120009193670206703/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://anujyadavcse.blogspot.com/2012/08/convert-nsnumber-to-nsstring.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1972826170038884797/posts/default/1120009193670206703'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1972826170038884797/posts/default/1120009193670206703'/><link rel='alternate' type='text/html' href='http://anujyadavcse.blogspot.com/2012/08/convert-nsnumber-to-nsstring.html' title='Convert NSNumber to NSString'/><author><name>Anuj Yadav</name><uri>http://www.blogger.com/profile/11344768057475167404</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3-ODntmQstTHRlTt1oA-YBvV6br318GA_rLr7G3-SM_X-xD27XUU07WojozfU-SDPyaIFEyOgi4zM5D-6G5P-cUfca2SDi5DEhYOiGE7cGBikp2zqmsG9Xp-0_boZJQ/s220/DSC_02080z-1.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1972826170038884797.post-3476150519981469951</id><published>2012-08-08T08:12:00.003-07:00</published><updated>2012-10-01T23:55:01.924-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="jQuery"/><title type='text'>Disable a hyperlink using javascript - jquery</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;I was working on an iOS application where we were displaying HTML content. We did not have control over these HTMLs and because of these we were facing lots of issues. One of the issue was handling of hyperlinks, we needed to handle the navigation ourselves. You can disable the hyperlink using the preventDefault() javascript function. Below is the sample using which you can disable the default behavior of a hyperlink.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;background-color: #1a0202; border-bottom-left-radius: 1em; border-bottom-right-radius: 1em; border-top-left-radius: 1em; border-top-right-radius: 1em; margin: 10px; padding: 10px;&quot;&gt;
&lt;div style=&quot;color: silver;&quot;&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&amp;lt;html&amp;gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;color: silver; font-family: Trebuchet MS, sans-serif;&quot;&gt;&amp;lt;head&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: silver; font-family: Trebuchet MS, sans-serif;&quot;&gt;&amp;lt;script src=&quot;jquery-1.5.1.min.js&quot; type=&quot;text/javascript&quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: silver; font-family: Trebuchet MS, sans-serif;&quot;&gt;&amp;lt;style&amp;gt;&amp;lt;/style&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: silver; font-family: Trebuchet MS, sans-serif;&quot;&gt;&amp;lt;script&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: silver; font-family: Trebuchet MS, sans-serif;&quot;&gt;&amp;nbsp; $(document).ready(function () {&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: silver; font-family: Trebuchet MS, sans-serif;&quot;&gt;&amp;nbsp; $(&#39;a&#39;).click(function(e) {&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;&lt;br /&gt;
&lt;/span&gt; &lt;span style=&quot;color: silver;&quot;&gt;&amp;nbsp; &amp;nbsp; e.preventDefault();&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //do other stuff when a click happens&lt;/span&gt; &lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: silver; font-family: Trebuchet MS, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; return false; &amp;nbsp;//In few browsers you will need to return false at the end&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: silver; font-family: Trebuchet MS, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: silver; font-family: Trebuchet MS, sans-serif;&quot;&gt;});&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;span style=&quot;color: silver;&quot;&gt;&lt;br /&gt;
&lt;/span&gt; &lt;span style=&quot;color: silver;&quot;&gt;});&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: silver; font-family: Trebuchet MS, sans-serif;&quot;&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: silver; font-family: Trebuchet MS, sans-serif;&quot;&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: silver; font-family: Trebuchet MS, sans-serif;&quot;&gt;&amp;lt;body&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: silver; font-family: Trebuchet MS, sans-serif;&quot;&gt;&amp;lt;a href=&quot;www.google.com&quot;&amp;gt; Google!!!&amp;lt;/a&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: silver; font-family: Trebuchet MS, sans-serif;&quot;&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: silver; font-family: Trebuchet MS, sans-serif;&quot;&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;b&gt;Note&lt;/b&gt;: In few browsers you might have to return false at the end of the function.&lt;/span&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://anujyadavcse.blogspot.com/feeds/3476150519981469951/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://anujyadavcse.blogspot.com/2012/08/disable-hyperlink-using-javascript.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1972826170038884797/posts/default/3476150519981469951'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1972826170038884797/posts/default/3476150519981469951'/><link rel='alternate' type='text/html' href='http://anujyadavcse.blogspot.com/2012/08/disable-hyperlink-using-javascript.html' title='Disable a hyperlink using javascript - jquery'/><author><name>Anuj Yadav</name><uri>http://www.blogger.com/profile/11344768057475167404</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3-ODntmQstTHRlTt1oA-YBvV6br318GA_rLr7G3-SM_X-xD27XUU07WojozfU-SDPyaIFEyOgi4zM5D-6G5P-cUfca2SDi5DEhYOiGE7cGBikp2zqmsG9Xp-0_boZJQ/s220/DSC_02080z-1.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1972826170038884797.post-2733403982177312874</id><published>2012-08-07T11:43:00.003-07:00</published><updated>2012-10-01T23:55:16.984-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="CSS"/><title type='text'>Change selection background and color using css</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;It is always nice to have a cool UI for our website. Changing the background and foreground color of selection can do wonders sometimes. In this post I will show you how you can achieve that. We can do this easily using CSS3. It provides us with ::selection selector. Safari supports ::selection and firefox supports&lt;span style=&quot;font-size: 12px;&quot;&gt;&amp;nbsp;&lt;/span&gt;::-moz-selection.&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Webkit browsers supports ::-webkit-selection. With time many browsers have started supporting ::selection itself.&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: 12px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: 12px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: #ebe5e5; border-bottom-left-radius: 1em; border-bottom-right-radius: 1em; border-top-left-radius: 1em; border-top-right-radius: 1em; color: black; margin: 10px; padding: 10px;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;.content::selection&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; background: #E01624;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; color:White;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;.content::-moz-selection&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;background: #E01624; &lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;color:White;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt; &lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;.content::-webkit-selection &lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;background: #E01624;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;color:White;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;.content&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; overflow:hidden;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt; &lt;br /&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;In HTML I have div with class as content.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://anujyadavcse.blogspot.com/feeds/2733403982177312874/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://anujyadavcse.blogspot.com/2012/08/change-selection-background-and-color.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1972826170038884797/posts/default/2733403982177312874'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1972826170038884797/posts/default/2733403982177312874'/><link rel='alternate' type='text/html' href='http://anujyadavcse.blogspot.com/2012/08/change-selection-background-and-color.html' title='Change selection background and color using css'/><author><name>Anuj Yadav</name><uri>http://www.blogger.com/profile/11344768057475167404</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3-ODntmQstTHRlTt1oA-YBvV6br318GA_rLr7G3-SM_X-xD27XUU07WojozfU-SDPyaIFEyOgi4zM5D-6G5P-cUfca2SDi5DEhYOiGE7cGBikp2zqmsG9Xp-0_boZJQ/s220/DSC_02080z-1.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1972826170038884797.post-7132736535576870837</id><published>2012-08-03T12:22:00.001-07:00</published><updated>2012-10-01T23:55:47.478-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="jQuery"/><title type='text'>How to get html tag name of an html element using jQuery</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Some times it is needed to get the tag name of an element. You can use below mentioned script to get that.&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;-moz-border-radius: 1em 1em 1em 1em; background-color: #f7fffe; border-radius: 1em 1em 1em 1em; color: #435050; font-family: verdana; line-height: 20px; margin: 10px; padding: 10px;&quot;&gt;
&amp;lt;html&amp;gt;&lt;br /&gt;
&lt;div&gt;
&amp;lt;head&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;lt;script src=&quot;jquery-1.5.1.min.js&quot; type=&quot;text/javascript&quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;lt;script&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; $(document).ready(function () {&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; alert(&lt;b&gt;$(&#39;#someElement&#39;).attr(&#39;tagName&#39;)&lt;/b&gt;);&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; )};&lt;/div&gt;
&lt;div&gt;
&amp;lt;/script&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;lt;body&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;lt;a &amp;nbsp;href=&quot;#&quot;&amp;gt;click to get tag name &amp;lt;/a&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;lt;div id= &#39;someElement&#39;&amp;gt;&lt;/div&gt;
&lt;div&gt;
You want tag name of this element.&lt;/div&gt;
&lt;div&gt;
&amp;lt;/div&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;lt;/body&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;lt;/html&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://anujyadavcse.blogspot.com/feeds/7132736535576870837/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://anujyadavcse.blogspot.com/2012/08/how-to-get-html-tag-name-of-and-html.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1972826170038884797/posts/default/7132736535576870837'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1972826170038884797/posts/default/7132736535576870837'/><link rel='alternate' type='text/html' href='http://anujyadavcse.blogspot.com/2012/08/how-to-get-html-tag-name-of-and-html.html' title='How to get html tag name of an html element using jQuery'/><author><name>Anuj Yadav</name><uri>http://www.blogger.com/profile/11344768057475167404</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3-ODntmQstTHRlTt1oA-YBvV6br318GA_rLr7G3-SM_X-xD27XUU07WojozfU-SDPyaIFEyOgi4zM5D-6G5P-cUfca2SDi5DEhYOiGE7cGBikp2zqmsG9Xp-0_boZJQ/s220/DSC_02080z-1.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1972826170038884797.post-4242016108000986697</id><published>2012-07-14T00:02:00.001-07:00</published><updated>2012-10-01T23:56:26.892-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C#"/><title type='text'>Difference between typeof() and GetType in c#</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif;&quot;&gt;typeof() is used to get the type information from a type. Here type can be class, delegate, interface etc.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif;&quot;&gt;e.g. Type t = typeof(Employee);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif;&quot;&gt;GetType() is used to get the type information from the object.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif;&quot;&gt;e.g. var obj = new Employee();&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Type t = obj.GetType();&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Trebuchet MS&#39;, sans-serif;&quot;&gt;Thus, when you have an object you should use GetType function to extract Type information and when you have only a type with you then you should use typeof() operator to extract type information.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://anujyadavcse.blogspot.com/feeds/4242016108000986697/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://anujyadavcse.blogspot.com/2012/07/difference-between-typeof-and-gettype.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1972826170038884797/posts/default/4242016108000986697'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1972826170038884797/posts/default/4242016108000986697'/><link rel='alternate' type='text/html' href='http://anujyadavcse.blogspot.com/2012/07/difference-between-typeof-and-gettype.html' title='Difference between typeof() and GetType in c#'/><author><name>Anuj Yadav</name><uri>http://www.blogger.com/profile/11344768057475167404</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3-ODntmQstTHRlTt1oA-YBvV6br318GA_rLr7G3-SM_X-xD27XUU07WojozfU-SDPyaIFEyOgi4zM5D-6G5P-cUfca2SDi5DEhYOiGE7cGBikp2zqmsG9Xp-0_boZJQ/s220/DSC_02080z-1.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1972826170038884797.post-3385352234787145164</id><published>2012-06-12T20:05:00.002-07:00</published><updated>2012-10-01T23:56:43.657-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="iOS"/><title type='text'>Using Objective C files in C++ files (mm)</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
If you&#39;re using .mm files (C++) in your project, when you include the header files in .mm files header you may get below mentioned error (Even though you have all the right linker flags set):&lt;br /&gt;
&lt;br /&gt;
1. linker failed with exit code 1&lt;br /&gt;
2. directory not found&lt;br /&gt;
&lt;br /&gt;
Solution:&lt;br /&gt;
&lt;br /&gt;
1. Try adding the file to .mm file directly (not to .h file for .mm)&lt;br /&gt;
2. Try adding the file as extern&lt;br /&gt;
extern &quot;C&quot; {&lt;br /&gt;
#import &quot;DetectDevice.h&quot; &lt;br /&gt;
}&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://anujyadavcse.blogspot.com/feeds/3385352234787145164/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://anujyadavcse.blogspot.com/2012/06/using-objective-c-files-in-c-files-mm.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1972826170038884797/posts/default/3385352234787145164'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1972826170038884797/posts/default/3385352234787145164'/><link rel='alternate' type='text/html' href='http://anujyadavcse.blogspot.com/2012/06/using-objective-c-files-in-c-files-mm.html' title='Using Objective C files in C++ files (mm)'/><author><name>Anuj Yadav</name><uri>http://www.blogger.com/profile/11344768057475167404</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3-ODntmQstTHRlTt1oA-YBvV6br318GA_rLr7G3-SM_X-xD27XUU07WojozfU-SDPyaIFEyOgi4zM5D-6G5P-cUfca2SDi5DEhYOiGE7cGBikp2zqmsG9Xp-0_boZJQ/s220/DSC_02080z-1.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1972826170038884797.post-8336036309975120344</id><published>2012-06-05T11:08:00.003-07:00</published><updated>2012-10-02T00:15:07.805-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="DI/ IOC"/><title type='text'>Inversion of control - Part 1</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;When an object of a type depends on an object of another type we say that the types are coupled. This is because change in one can lead to a change in second. This will hamper the&amp;nbsp;extensibility&amp;nbsp;and modification in design. In a more complex system lot of classes interact with each other and this will lead to a very brittle design. Let&#39;s take an example:&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&amp;nbsp; &amp;nbsp;class Program&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&amp;nbsp; &amp;nbsp; {&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; static void Main(string[] args)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; List&amp;lt;Employee&amp;gt; employees = new List&amp;lt;Employee&amp;gt;();&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; EmployeeController employeeController = new EmployeeController();&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; employees = employeeController.GetAllEmployees();&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;Program depends on EmployeeController to fetch Employee(s).&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;u&gt;&lt;b&gt;Inversion of control&lt;/b&gt;&lt;/u&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;Logically Inversion means&amp;nbsp;rearrangement. As we have seen in the previous example that Program is controlling EmployeeController and this control is actually coupling them. Inversion of control is object-oriented practice via which we can decouple the classes by providing the implementation (EmployeeController) at runtime (instead of compile time) via abstraction.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;This helps in following ways:-&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;1. Reduces the coupling in the system.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;2. Makes sure that we &quot;Program to an interface and not to the implementation&quot;.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;3. Allows the implementation to be changed without impacting the consumer.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;4. Every module can be developed independent of each other.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;5. Allows a module to be a cohesive unit and concentrate on the responsibilities assigned to it.&lt;br /&gt;
6. Modules do not assume about the functioning of other modules but rely on the contract (Interface).&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;and many more.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;u&gt;&lt;b&gt;Simpler explanation&lt;/b&gt;&lt;/u&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;u&gt;&lt;b&gt;&lt;br /&gt;
&lt;/b&gt;&lt;/u&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;Previous example assigns EmployeeController object statically to Program. In place of this IoC (inversion of control) uses an assembler to instantiate the object and assign it to the consumer. Even if we use an assembler Program still need to be aware of EmployeeController. Instead of this if we can make EmployeeController&#39;s contract&amp;nbsp;available&amp;nbsp;to Program it can delegate the task to the implementation (EmployeeCotroller) via it. In general Interfaces and (sometimes) abstract classes are used as the contract. Now the assembler assigns the EmployeeController object wrapped in the abstraction to Program and thus the implementation can change without impacting the consumer.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;u&gt;&lt;b&gt;Dependency Injection&lt;/b&gt;&lt;/u&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;u&gt;&lt;b&gt;&lt;br /&gt;
&lt;/b&gt;&lt;/u&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;Dependency Injection is the mechanism using which we can assign the object to the consumer or we can achieve IoC by binding the objects at run time. We can also use Service Locator to provide IoC. We will discuss Service Locator in a future post.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;u&gt;&lt;b&gt;Types of Dependency Injection&lt;/b&gt;&lt;/u&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;There are three common forms of dependency injection:&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;1. Constructor Injection&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;2. Setter Injection&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;3. Interface-based injection&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;We will discuss the implementation of DI in future posts.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://anujyadavcse.blogspot.com/feeds/8336036309975120344/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://anujyadavcse.blogspot.com/2012/06/inversion-of-control-part-1.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1972826170038884797/posts/default/8336036309975120344'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1972826170038884797/posts/default/8336036309975120344'/><link rel='alternate' type='text/html' href='http://anujyadavcse.blogspot.com/2012/06/inversion-of-control-part-1.html' title='Inversion of control - Part 1'/><author><name>Anuj Yadav</name><uri>http://www.blogger.com/profile/11344768057475167404</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3-ODntmQstTHRlTt1oA-YBvV6br318GA_rLr7G3-SM_X-xD27XUU07WojozfU-SDPyaIFEyOgi4zM5D-6G5P-cUfca2SDi5DEhYOiGE7cGBikp2zqmsG9Xp-0_boZJQ/s220/DSC_02080z-1.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1972826170038884797.post-4280903868413799860</id><published>2012-05-06T00:10:00.002-07:00</published><updated>2012-10-01T23:57:40.827-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Misc"/><title type='text'>We newbies and the application design and architecture</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;After being around for some time in this world of IT I have started to realize why these experienced guys are so furious with the newbies. I use to read a lot of newbie bashing on web and use to think WTF. Now, I must say &quot;Old is Gold&quot;.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;There are three types of newbies I have come across. One who really do not want to design and just wants to get the job done in a procedural way. Second who know a thing or two about design and want to design there application the best possible way (constraint being there knowledge). Third who thinks they know everything about design and that is how things should be designed.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;The real problem arises when they are working on an application from scratch. The first type may come up with a class or two and finish the code in a monolithic manner. The third type will create a design either too good or to brittle. These two types will surely get the work done even though extensibility and maintainability may not be there and thus the cost of every change will be just too high.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;I have found the second type getting stuck more often then not. They are always circumspect about there design and some times they just think too much about it. They google for some hints and solutions (more often then not they find something). The problem is knowing whether the solution is right for there case or not.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;I am not against any one type and neither I&amp;nbsp;favor&amp;nbsp;one. I put them down just so that one can realize where they fall.&amp;nbsp;I have been lucky to get chance to work on an application or module design from scratch and some time on existing applications as well. Initially I found really difficult to move even an inch as I was two confuse about my design. I have been the second type and I have been the third.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Here are few of my&amp;nbsp;learning&#39;s:&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;ol style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Never be the first type. You never know you might be the one working on the change tomorrow.&amp;nbsp;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Design evolves. There is know best design. You can always better it gradually.&amp;nbsp;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Follow the basic principles. Separation of concerns, Coupling,&amp;nbsp;Cohesiveness are the few principles which I think if followed will always allow you to refactor your code latter.&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Work in layers when needed.&amp;nbsp;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;You might be the best around (for the Third type) but may be you can learn from others mistake or can make them understand their mistake. Keep looking for the better solution or for the mistake you should not do yourself.&amp;nbsp;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;You might be technically very strong but you need to understand the needs of your customer then only you can design something good for the customer. You are not designing for yourself. You are designing for the customer. There is cost associated with whatever you do (do not spend too much at design) and&amp;nbsp;obviously&amp;nbsp;there will be cost associated with any change (do spend time on design).&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;There are simple&amp;nbsp;techniques&amp;nbsp;which when followed always allows you to improve latter. e.g. interface based programming, DI etc. Do the small things right and the rest will follow.&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Do not hesitate in doing pair&amp;nbsp;programming. You will always learn.&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;i&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Most importantly do not just remain stuck. Start with something and realize the shortcomings and fix them. I am still learning and believe that we learn from our mistakes. I still believe I have spent too much time&amp;nbsp;analyzing&amp;nbsp;and trying to get the things right the first time (Being stuck). That said, please do invest lot of time at architectural design as module design can change comparatively easily and with less cost.&lt;/span&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://anujyadavcse.blogspot.com/feeds/4280903868413799860/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://anujyadavcse.blogspot.com/2012/05/we-newbies-and-application-design-and.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1972826170038884797/posts/default/4280903868413799860'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1972826170038884797/posts/default/4280903868413799860'/><link rel='alternate' type='text/html' href='http://anujyadavcse.blogspot.com/2012/05/we-newbies-and-application-design-and.html' title='We newbies and the application design and architecture'/><author><name>Anuj Yadav</name><uri>http://www.blogger.com/profile/11344768057475167404</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3-ODntmQstTHRlTt1oA-YBvV6br318GA_rLr7G3-SM_X-xD27XUU07WojozfU-SDPyaIFEyOgi4zM5D-6G5P-cUfca2SDi5DEhYOiGE7cGBikp2zqmsG9Xp-0_boZJQ/s220/DSC_02080z-1.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1972826170038884797.post-8385613420530504432</id><published>2012-04-21T08:59:00.002-07:00</published><updated>2012-10-01T23:58:12.366-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C"/><category scheme="http://www.blogger.com/atom/ns#" term="C++"/><title type='text'>Learning C and or C++ on windows</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
If you want to start learning C/C++ and still want to use windows, you can either use Microsofts Managed C++ with a great IDE (Visual Studio) or GNU C/C++ compilers.&lt;br /&gt;
&lt;br /&gt;
Microsoft has invested a lot in C++ and Visual Studio. The powerful IDE really enhance the productivity. There is lot online documentation using which one can learn Microsoft&#39;s Managed C++ thick and fast. You can download Visual Studio Express for free and can start learning.&lt;br /&gt;
&lt;br /&gt;
Download Visual Studio 2010 express from &lt;a href=&quot;http://www.microsoft.com/visualstudio/en-us/products/2010-editions/visual-cpp-express&quot;&gt;here&lt;/a&gt;. &lt;a href=&quot;http://msdn.microsoft.com/en-us/vstudio/hh386302&quot;&gt;Learning resources&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
If you want to learn GNU C / C++ you can start with downloading CodeBlocks. It is an IDE for GNU C / C++ &amp;nbsp;and it comes bundled with the compiler which makes it really easy to install the compiler and avoid the complexities of getting the things in place pieces by pieces.&lt;br /&gt;
&lt;br /&gt;
You can download CodeBlocks from &lt;a href=&quot;http://www.codeblocks.org/&quot;&gt;here&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://anujyadavcse.blogspot.com/feeds/8385613420530504432/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://anujyadavcse.blogspot.com/2012/04/learning-c-and-or-c-on-windows.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1972826170038884797/posts/default/8385613420530504432'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1972826170038884797/posts/default/8385613420530504432'/><link rel='alternate' type='text/html' href='http://anujyadavcse.blogspot.com/2012/04/learning-c-and-or-c-on-windows.html' title='Learning C and or C++ on windows'/><author><name>Anuj Yadav</name><uri>http://www.blogger.com/profile/11344768057475167404</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3-ODntmQstTHRlTt1oA-YBvV6br318GA_rLr7G3-SM_X-xD27XUU07WojozfU-SDPyaIFEyOgi4zM5D-6G5P-cUfca2SDi5DEhYOiGE7cGBikp2zqmsG9Xp-0_boZJQ/s220/DSC_02080z-1.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1972826170038884797.post-8572973234964981772</id><published>2012-04-07T20:24:00.000-07:00</published><updated>2012-10-01T23:58:55.703-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Entity Framework"/><title type='text'>The specified named connection is either not found in the configuration, not intended to be used with the EntityClient provider, or not valid</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: x-small;&quot;&gt;It was 2 o&#39;clock at night when I was creating a model (MVC) using Entity Framework. I thought of creating a UnitTest project to follow some TDD. When I tried to run my first TestMethod I got this vague exception. After investigating further with half closed eyes I found out, how dumb I was to not to include App.config in the test project.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: x-small;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: x-small;&quot;&gt;&lt;b&gt;Basic concept&lt;/b&gt; is pretty&amp;nbsp;straight forward and logical. We generally add entity framework to a class library project in order to be able to reuse the library. The library project is not an executable in its own. Thus we need to add this project in some executable say a console App, windows App, ASP.NET or UnitTest. The runtime will then expect the executable to have a config associated with itself which will have the connection string, which entity framework library is looking for.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: x-small;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: x-small;&quot;&gt;&lt;b&gt;Thus, the solution&lt;/b&gt; is pretty simple. Add the app.config to the project you are trying to run or add connection string to the config if the project you are trying to run already have a config.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: x-small;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: x-small;&quot;&gt;&lt;b&gt;Also &lt;/b&gt;- It has been observed that in few cases &amp;amp;quot present in the connection string can cause similar problem. Try changing it to a single quote (&#39;).&lt;/span&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://anujyadavcse.blogspot.com/feeds/8572973234964981772/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://anujyadavcse.blogspot.com/2012/04/specified-named-connection-is-either.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1972826170038884797/posts/default/8572973234964981772'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1972826170038884797/posts/default/8572973234964981772'/><link rel='alternate' type='text/html' href='http://anujyadavcse.blogspot.com/2012/04/specified-named-connection-is-either.html' title='The specified named connection is either not found in the configuration, not intended to be used with the EntityClient provider, or not valid'/><author><name>Anuj Yadav</name><uri>http://www.blogger.com/profile/11344768057475167404</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3-ODntmQstTHRlTt1oA-YBvV6br318GA_rLr7G3-SM_X-xD27XUU07WojozfU-SDPyaIFEyOgi4zM5D-6G5P-cUfca2SDi5DEhYOiGE7cGBikp2zqmsG9Xp-0_boZJQ/s220/DSC_02080z-1.jpg'/></author><thr:total>0</thr:total></entry></feed>