Baran Topal

Categories


baran
Author

baran

auto increment value to original in MSSQL

Long ago, I wanted to revert auto increment value to its original value which starts as 1 in MSSQL 2008. This is possible by either dropping and recreating the column or do a RESEED through DBCC CHECKIDENT. DBCC CHECKIDENT ("{myTable}", RESEED, 1); Another way is provided that there are no foreign keys you can also do TRUNCATE TABLE [...]

baranbaran

using {…} in C#

How to use: You simply include a declaration of an object you want to use within that block. For example, you can put your SqlConnection objects in a using: using (SqlConnection con = new SqlConnection(some_con_str)) { // Use "con" within this block. It will cease to exist once the block exits } You can only use using blocks with types [...]

baranbaran

singleton use cases

Very briefly a singleton is something you can only have one of. An example – think of a class that wraps writing to a log file.  You could pass an object around from class to class or you could have a singleton which you just use. Another example, say, you are implementing a cache object which can be used by other classes. In this [...]

baranbaran

Minimal password recovery in debian

Only 3 steps 🙂 1. You can then use your installation media and boot into recovery mode. 2. Look for mountpoint where for your hard disk e.g. /mnt/sysimages/img1 3. Then run the following command chroot /mnt/sysimages/img1 passwd root Where /mnt/sysimages/img1 is the path you identified earlier. This would prompt you to enter new password.

baranbaran

bad code to good one – Java – Part 1

Well, here is an interesting case. I found this code in one of my old machines. The code is waiting for input from the user and fills a hashmap. Yet, while extracting, simply it throws an exception. Our first question is how to fix it, then second is how to really improve it? import java.util.HashMap; import java.util.Iterator; import [...]

baranbaran

silly fibonacci

Good old fibonacci and this post will be updated later on but bear with this Java one: public class FibonacciExt { public static void main(String[] args) { // System.out.println(fibonacci(10, 4)); for (int j = 1; j < 15; j++) System.out.print(" " + fibonacci(j, 3)); System.out.println(""); } public static int fibonacci(int n, int k) { [...]

baranbaran

replace occurrence in Java with JUnit

I will write a more detailed post about JUnit later on. But this is a good start to find out testing replacing occurrence in Java 🙂 Assuming the utility method is as follows: public class Strings { public static String replaceOccurence(String str, String search, String replace) { StringBuffer buffer = new StringBuffer(str); for (int i = [...]

baranbaran

const and readonly in .NET

I never thought that I would use readonly identifier in C#. But here is a valid reason to use it. public const string SQL_CONNECTION_STRING = ConfigurationManager.ConnectionStrings["MyWebConnectionString"].ConnectionString; When I store SQL_CONNECTION_STRING as a constant (due to design issue) and want to pass the connection string in [...]

baranbaran

extract a hexadecimal string

I had been fiddling with php and needed to extract a string literal. Note that there are many many ways to solve this but I’d like to go with this: <?php $str = 'Found PID 0x1011, stream id 0xE0 = Video Stream 0'; preg_match('/id (0x[0-9a-f]+) = Video/i', $str, $m); print_r($m[1]); ?>

baranbaran