Use LinkedHashMap to implement LRU cache

As pointed out by Jeffrey, you are using accessOrder. When you created the LinkedHashMap, the third parameter specify how the order is changed. “true for access-order, false for insertion-order” For more detailed implementation of LRU, you can look at this http://www.programcreek.com/2013/03/leetcode-lru-cache-java/

Adding a range of values to an ObservableCollection efficiently

The ObservableCollection exposes an protected Items property which is the underlying collection without the notification semantics. This means you can build a collection that does what you want by inheriting ObservableCollection: class RangeEnabledObservableCollection<T> : ObservableCollection<T> { public void InsertRange(IEnumerable<T> items) { this.CheckReentrancy(); foreach(var item in items) this.Items.Add(item); this.OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset)); } } Usage: void Main() { … Read more

How to insert multiple rows in SQLite?

update As BrianCampbell points out here, SQLite 3.7.11 and above now supports the simpler syntax of the original post. However, the approach shown is still appropriate if you want maximum compatibility across legacy databases. original answer If I had privileges, I would bump river’s reply: You can insert multiple rows in SQLite, you just need … Read more

Inserting Line at Specified Position of a Text File

The best way to make “pseudo-inplace” changes to a file in Python is with the fileinput module from the standard library: import fileinput processing_foo1s = False for line in fileinput.input(‘1.txt’, inplace=1): if line.startswith(‘foo1’): processing_foo1s = True else: if processing_foo1s: print ‘foo bar’ processing_foo1s = False print line, You can also specify a backup extension if … Read more

Return ID on INSERT?

You just need to add @ID to the params collection and then retrieve it like this, cmd.Parameters.Add(“@ID”, SqlDbType.Int, 4).Direction = ParameterDirection.Output; cmd.ExecuteNonQuery(); //Now just read the value of: cmd.Parameters[“@ID”].value Or, if you prefer this syntax: SqlParameter param = new SqlParameter(“@ID”, SqlDbType.Int, 4); param.Direction = ParameterDirection.Output; cmd.Parameters.Add(param);

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)