George Opritescu

Developer from somewhere

linx #3

  • [paranoia] (http://rubygems.org/gems/paranoia) if you wished that when you called destroy on an Active Record object that it didn’t actually destroy it, but just “hid” the record
Read More

linx #2

  • [active-rest-client] (https://github.com/whichdigital/active-rest-client)
Read More

bash pipe exit code

If you pipe a command to another, and want to keep the exit code, you can use one of these 2 ways:

# now you can et the error code in $?
set -o pipefail

Or

echo ${PIPESTATUS[0]}
Read More

adding a custom angular validator

  • Fun validator, check if an exercise is one of the big 3:
app.directive "compoundExercise", ->
  restrict: "A"
  require: "ngModel"
  link: (scope, element, attrs, ctrl) ->
    exercises = ["Squat", "Deadlift", "Bench Press"]
    ctrl.$formatters.push (value) ->
      haveX = value in exercises
      ctrl.$setValidity("compoundExercise", haveX)
      return value

    ctrl.$parsers.push (value) ->
      haveX = value in exercises
      ctrl.$setValidity("compoundExercise", haveX)
      return if haveX then value else null
  • If the field is not valid, then myForm.myFieldName.$error.compoundExercise will be true

  • Checking if the field is valid:

myForm.myFieldName.$valid
Read More

git pull with rebase

To configure git to do a pull with rebase everytime:

git config --global branch.autosetuprebase always

And to setup an existing branch in the same way:

git config branch.ACTUAL_BRANCH_NAME.rebase true
Read More

know if you're running under zeus

The presence of “ZEUS_MASTER_FD” variable, tells you if you’re running under zeus.

Read More

directive with controller in angular

Been trying to get a directive to use a controller method. I had this:

app.directive "myDirective", ->
  restrict: "A"
  controller: ($scope) ->
    sayHello: ->
      alert "Hello"
  template: '<div><a ng-click="sayHello()">Say hello</a></div>'

And it wouldn’t react. The problem was that the method had to be dined on the scope:

app.directive "myDirective", ->
  restrict: "A"
  controller: ($scope) ->
    $scope.sayHello = ->
      alert "Hello"
  template: '<div><a ng-click="sayHello()">Say hello</a></div>'
Read More

accessing the target of a click in angularjs

Here’s how to access the target of a click event:

<a ng-click="doSomething($event)">Click me</a>

And in your method, you can access the target via $event.target

Read More

calling a builtin filter from another angular filter

I needed to call dateFilter from one of my filters. This is how I’ve done it:

app.filter "myCustomFilter", ["dateFilter", (dateFilter) ->
  (input) ->
    # call dateFilter with whatever args
]
Read More

accessing an angular service from the browser console

This works in 1.2.10:

angular.injector(["yourAppName"]).get("serviceName")
Read More