Skip to content

Instantly share code, notes, and snippets.

@wolf-mtwo
Last active August 29, 2015 14:10
Show Gist options
  • Save wolf-mtwo/5da3219c66e3072a089f to your computer and use it in GitHub Desktop.
Save wolf-mtwo/5da3219c66e3072a089f to your computer and use it in GitHub Desktop.
Coffeescript
deferred = Q.defer()
 func (error, value) ->
  if error
   deferred.reject error
   return
 deferred.resolve value
deferred.promise
if 0 is 0 then true else false

if true and not false

 [].reduce ->


arr = ['1', '2', '3']
if '1' in arr
  true
false

create = (ip) ->
  cl ip

create ip for ip in ips

coffee herencia example

class Animal

  # _name = null

  constructor: (name) ->
    @name = name

  hi: ->
    console.log @name

class Perro extends Animal

  constructor: (name, edad) ->
    super name
    @edad = edad

  hi: ->
    console.log @edad
    super()

class Gato extends Animal

  constructor: (name, patas) ->
    super name
    @patas = patas

  hi: ->
    console.log  @patas
    super

gato = {
  sssss: 'sssss'
}

perro = new Perro gato, 20
perro.hi()

gato2 = {
  sssss: 'sssssss'
}
perro2 = new Perro gato2, 20

perro2.hi()
perro.hi()

console.log perro
console.log perro2

do while

while true
  # actions here
  break unless # conditions here

while true
  func @auxNode.element
  @auxNode = @auxNode.next
  break unless @auxNode
eat food for food in ['toast', 'cheese', 'wine']
class Cat
  constructor: (@name) ->

class Dog
  constructor: (@name) ->

cat = new Cat "Kitty"
dog = new Dog "Doggy"

if (cat == Cat)  <- I want to do something like this
# resp
if(cat instanceof Cat)

stylus linter

'.source.js':

  'Console log as cl':
    'prefix': 'cl'
    'body': """
    console.log($1)
    """
'.source.coffee':

  'Console log as cl':
    'prefix': 'cl'
    'body': """
    console.log $1
    """
  'Console log as cl>>>':
    'prefix': 'cl>'
    'body': """
    console.log '>>>>>>>>>>>>>>>>>>>>>>'
    """
  'Console log as cl<<<':
    'prefix': 'cl<'
    'body': """
    console.log '<<<<<<<<<<<<<<<<<<<<<<'
    """
  'for in':
    'prefix': 'for'
    'body': """
    for $1 in $2
      $3
    """
  'class':
    'prefix': 'class'
    'body': """
    class $1
      constructor: ($2) ->
        $3

    module.exports = $1
    """
  'method':
    'prefix': 'method'
    'body': """
    $1: ($2) ->
      $3
    """
  'var varable':
    'prefix': 'var'
    'body': """
    $1 = $2
    """
  'comment param':
    'prefix': '@param'
    'body': """
    @param $1 [$2] $3
    """
  'comment return':
    'prefix': '@return'
    'body': """
    @return $1 [$2] $3
    """
  'Comments':
    'prefix': '##'
    'body': """
    ###
    $1
    ${3:@param $5 [$6] $7
    }${4:@return [$8] $9
    }###
    $10
    """
  'code comment':
    'prefix': '/**'
    'body': """
    ###
    $1
    ###
    """
  'words length':
    'prefix': 'len'
    'body': "length"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment