Skip to content

Instantly share code, notes, and snippets.

@rodrimaia
rodrimaia / gist:9647775
Last active August 29, 2015 13:57
CustomBindings for Knockout
/* Bindings */
ko.bindingHandlers.selectPicker = {
init: function(element, valueAccessor, allBindingsAccessor) {
if ($(element).is('select')) {
if (ko.isObservable(valueAccessor())) {
if ($(element).prop('multiple') && $.isArray(ko.utils.unwrapObservable(valueAccessor()))) {
// in the case of a multiple select where the valueAccessor() is an observableArray, call the default Knockout selectedOptions binding
ko.bindingHandlers.selectedOptions.init(element, valueAccessor, allBindingsAccessor);
} else {
// regular select and observable so call the default value binding
@rodrimaia
rodrimaia / gist:9690710
Created March 21, 2014 17:00
convert Model to js #mvc #js
var model = @Html.Raw(Newtonsoft.Json.JsonConvert.SerializeObject(Model));
@rodrimaia
rodrimaia / gist:9740602
Created March 24, 2014 13:58
PreventNulls
public abstract class AbstractViewModel<T>
{
public AbstractViewModel<T> PreventNulls()
{
// Verifica se alguma propriedade eh nula e insere um valor valido
var properties = GetType().GetProperties();
foreach (var property in properties )
{
var value = property.GetValue(this, null);
@rodrimaia
rodrimaia / gist:11135046
Created April 21, 2014 07:29
Wrapper for SaveChanges adding the Validation Messages to the generated exception
/// <summary>
/// Wrapper for SaveChanges adding the Validation Messages to the generated exception
/// </summary>
/// <param name="context">The context.</param>
private void SaveChanges(DbContext context)
{
try
{
context.SaveChanges();
}
@rodrimaia
rodrimaia / gist:11136419
Created April 21, 2014 08:39
Save changes with IAuditable
public override int SaveChanges()
{
// var auditUser = HttpContext.Current.User.Identity.Name;
DateTime auditDate = DateTime.UtcNow;
foreach (DbEntityEntry<IAuditable> entry in ChangeTracker.Entries<IAuditable>())
{
if (entry.State == EntityState.Added)
{
entry.Entity.CreatedOn = auditDate;
entry.Entity.ModifiedOn = auditDate;
@rodrimaia
rodrimaia / gist:6353dad5947deef36305
Created June 30, 2014 20:50
Color for GIT prompt
[color]
diff = auto
status = auto
[color "diff"]
meta = yellow bold
frag = magenta bold
old = red bold
new = green bold
[color "status"]
added = cyan bold
@rodrimaia
rodrimaia / gist:0dfe7e95c4c7ec8de1e7
Created July 23, 2014 16:08
GIT - Armazenar Credenciais
Para armazenar credenciais:
git config credential.helper store
Para remover credenciais:
git config --unset credential.helper
@rodrimaia
rodrimaia / gist:8e038c6c42c7afe50424
Created August 8, 2014 22:03
MsBuild To WebDeploy
msbuild Web.csproj /P:DeployIisAppPath="Default Web Site" /P:Configuration=Release /P:Platform="AnyCPU" /P:DeployOnBuild=True /P:DeployTarget=MSDeployPublish /P:MsDeployServiceUrl=https://xxxx/MsDeploy.axd /P:AllowUntrustedCertificate=True /P:MSDeployPublishMethod=WMSvc /P:CreatePackageOnPublish=True /P:UserName=xx\xxxx /P:Password=xxxxx
# USE IF YOU HAVE
#export JAVA15_HOME="/System/Library/Java/JavaVirtualMachines/1.5.0/Contents/Home/"
#export PATH=${JAVA15_HOME}/bin:$PATH
#export JAVA_HOME=$(/usr/libexec/java_home)
#export PATH=${JAVA_HOME}/bin:$PATH
#export MAVEN_OPTS="-Xmx1024m -Xms1024m -XX:MaxPermSize=1162m"
#export M2_HOME=/usr/local/apache-maven-2.2.1
#export M2=$M2_HOME/bin
#export PATH=$M2:$PATH
@rodrimaia
rodrimaia / gist:ea2e6a4ffef3b4f3a51f
Created November 24, 2014 17:45
Git Feature Branch Workflow
# Git Feature Branch Workflow
This .md was created in order to set a flow when commiting codes. As the team is growing everyday I found it useful to everyone that we had some steps to follow and don't let the code break into a thousand of conflicts that could fade away some parts of code and something else. It is also a complementing to [CONTRIBUTING.md](CONTRIBUTING.md)
So here we have the suggested steps, but feel free to suggest somthing different you didn't agree or thing we could improve.
##When developing a new feature
When a new feature starts to be implemented, you should create a new branch with your name (optional) followed by the feature name you think should be good. But before that, you should keep your ```master``` up-to-date.
So, go to your ```master```branch and synchronize with the remote repository as follow: