Setting up Redis on Windows with Chocolatey

by Victor 22. January 2016 20:25
Step 1
Install chocolately (https://chocolatey.org/)
Open cmd prompt as Administrator
Run the following:
@powershell -NoProfile -ExecutionPolicy Bypass -Command "iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))" && SET PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin

Step 2
Install redis using chocolatey
Open cmd prompt as Administrator
Run the following:
choco install redis-64

Step 3
Set up redis to run as a service (if it didn't set it up automatically, check local services if "Redis" exists)
Open cmd prompt as Administrator
Run the following:
cd C:\ProgramData\chocolatey\lib\redis-64
redis-server --service-install "redis.windows-service.conf"

If the service won't start, open redis.window-service.conf and make sure the path in the logfile setting uses forward slash (/) not back slash (\). Also make sure the "logs" folder exists at C:\ProgramData\chocolatey\lib\redis-64\logs.
If you need to uninstall, run:
redis-server --service-uninstall
 
Here's a link to a free Redis explorer:
http://redisdesktop.com

Tags: , ,

.NET | Software Development | Web Development

AngularJS - Browser autocomplete not updating model

by Victor 18. December 2015 00:15

This doesn't apply just to AngularJS but to any js framework that uses models. Some browsers (Safari, Chrome) have been known not to emit the change event when a user fills in a field using the autocomplete feature of the browser. Use this polyfill to have the change event fired

https://github.com/tbosch/autofill-event

This still won't be enough to get the view value back into the model. But, now that you have an event to hook into you, you can use a directive like this to transfer the value from the view to the model.

// http://stackoverflow.com/a/23919364/867891
app.directive('autoFillSync', ['$log', function ($log) {
return {
require: 'ngModel',
link: function (scope, elem, attrs, model) {
elem.change(function (event) {
$log.debug('autoFillSync.link.change');
model.$setViewValue(elem.val());
})
}
};
}]);
 
Then use the directive on your input element
 
<input type='text' ng-model='city' auto-fill-sync />
 
This solution was inspired by this StackOverflow answer:
http://stackoverflow.com/a/23919364/867891

Tags: , ,

AngularJS | javascript | jQuery | Web Development

Useful extensions for Visual Studio

by Victor 21. October 2015 01:37

Web Compiler:
The easiest and most powerful way to compile LESS, Scss, JSX and CoffeeScript files directly within Visual Studio or through MSBuild.
https://visualstudiogallery.msdn.microsoft.com/3b329021-cd7a-4a01-86fc-714c2d05bb6c

Image Optimizer:
Lossless optimization of JPEG, PNG and Gifs - including animated Gifs
https://visualstudiogallery.msdn.microsoft.com/a56eddd3-d79b-48ac-8c8f-2db06ade77c3

Bundler & Minifier:
Adds support for bundling and minifying JavaScript, CSS and HTML files in any project.
https://visualstudiogallery.msdn.microsoft.com/9ec27da7-e24b-4d56-8064-fd7e88ac1c40

Web Analyzer:
Provides static analysis directly in Visual Studio for JavaScript, TypeScript, JSX, CSS and more
https://visualstudiogallery.msdn.microsoft.com/6edc26d4-47d8-4987-82ee-7c820d79be1d

Querying BsonIgnore fields in MongoDB using LINQ

by Victor 8. October 2015 22:27

If you have a BsonIgnoreIfDefault attribute on a property, that property will not get serialized and persisted to your MongoDB database if its value is the default for its type. The default for reference types is null. The default for primitives are: int/double/long/decimal = 0, bool = false.

 

Now, let's take a look at a use case. Here, we want MiddleName to never be null, and to be an empty string if it's never set.

 

public class Person
{
    public string FirstName { get;set; }

    [BsonIgnoreIfDefault]
    [BsonDefaultValue("")]
    public string MiddleName
    {
        get { return _middleName; }
        set { _middleName = value == null ? "" : value; }
    }
    private string _middleName = "";
}

var john = new Person { FirstName = "John" };
PersonRepository.Add(john);

PersonRepository.Where(p => p.FirstName == "John", p.MiddleName == "");

 

In this case, the query will not return anything because an empty string is the default for middle name and we told the serializer to ignore MiddleName if it's the default. So, in the database, this Person object is saved without a MiddleName field. In order to query for any Person that does not have a MiddleName, you have to use null, like so:

 

PersonRepository.Where(p => p.FirstName == "John", p.MiddleName == null);

Tags:

.NET | C# | MongoDB

Formatting a phone number in .NET

by Victor 8. October 2015 22:24

If you save your phone numbers as only numbers, eg., 5615551234then you can use this code to format it for display:

 

string.Format("{0:###-###-####}",long.Parse("5615551234"));

 

which will output 561-555-1234. Neat huh?

Tags: , ,

.NET | ASP.NET | C# | Software Development

ASP.NET Bundling of AngularJS templates

by Victor 7. October 2015 23:47

Saving this link here for future reference. Great post on how to add your AngularJS templates to ASP.NETs bundling and minification process.

 

http://blog.scottlogic.com/2014/08/18/asp-angular-optimisation.html

Tags: , , ,

AngularJS

Rename database in MongoDB

by Victor 27. September 2014 00:42

db.copyDatabase('OldDatabaseName, 'NewDatabaseName');

use OldDatabaseName

db.dropDatabase();

Tags:

MongoDB

Visual Studio javascript extensions

by Victor 23. July 2014 20:39

This one adds AngularJS intelisense:

http://madskristensen.net/post/angularjs-intellisense-in-visual-studio-2012

 


This one adds outlining for regions, brackets, braces, and comments:

 

http://visualstudiogallery.msdn.microsoft.com/4be701d8-af03-40a4-8cdc-d2add5cde46c?SRC=VSIDE

 

Tags: , ,

Getting full path in Windows Service

by Victor 14. July 2014 18:53
AppDomain.CurrentDomain.BaseDirectory

If you need the application path inside of a Windows Service you can use this property to get it. Something I always forget so here it is for easy reference.

Tags: , ,

.NET | C# | Software Development

Excel - Trim all cells

by Victor 31. May 2013 07:52

Here's a macro to trim all selected cells:

 

Sub TrimCells()
    Dim R As Range
    Application.EnableEvents = False
    On Error GoTo ErrH:
    If TypeOf Selection Is Excel.Range Then
        For Each R In Selection.Cells
            If R.HasFormula = False Then
                R.Value = Trim(R.Value)
            End If
        Next R
    End If
ErrH:
    Application.EnableEvents = True
End Sub

Tags: ,

Powered by BlogEngine.NET 2.5.0.6

About Us

Wuji Touch is a software consulting firm based in Delray Beach, Florida. We specialize in Microsoft technologies, but we also have experience with Progress OpenEdge, iOS, and Android development. This is our blog. These are the tales of the pains and pleasures we experience daily in our journey through 1s and 0s.

Month List