working on it ...

Filters

Explore Public Snippets

Sort by

Found 3,581 snippets

    public by davis  1302  1  3  0

    Atom autocomplete suggestions on tab

    Atom autocomplete suggestions on tab: tab-completion.coffee
    {Point} = require 'atom'
    
    atom.commands.add 'atom-text-editor', 'custom:tabcomplete', (e) ->
      editor = atom.workspace.getActiveTextEditor()
      cursor = editor.getLastCursor()
    
      {row, column} = cursor.getBufferPosition()
      precedingCharacter = editor.getTextInBufferRange([[row, column - 1], [row, column]])
    
      if /\S/.test(precedingCharacter)
        autocomplete = atom.packages.getActivePackage('autocomplete-plus')
        return unless autocomplete?
    
        manager = autocomplete.mainModule.activate()
        manager.shouldDisplaySuggestions = true
        manager.findSuggestions(true)
      else
        e.abortKeyBinding()
    
    
    

    public by Piers Mainwaring  1160  0  4  0

    Atom autocomplete suggestions on tab

    Atom autocomplete suggestions on tab: tab-completion.coffee
    {Point} = require 'atom'
    
    atom.commands.add 'atom-text-editor', 'custom:tabcomplete', (e) ->
      editor = atom.workspace.getActiveTextEditor()
      cursor = editor.getLastCursor()
    
      {row, column} = cursor.getBufferPosition()
      precedingCharacter = editor.getTextInBufferRange([[row, column - 1], [row, column]])
    
      if /\S/.test(precedingCharacter)
        autocomplete = atom.packages.getActivePackage('autocomplete-plus')
        return unless autocomplete?
    
        manager = autocomplete.mainModule.activate()
        manager.shouldDisplaySuggestions = true
        manager.findSuggestions(true)
      else
        e.abortKeyBinding()
    
    
    

    public by missbossy  1954  1  4  0

    Edit Page Bookmarklet

    javascript:document.body.contentEditable='true'; document.designMode='on'; void 0      

    public by marksimon232  2742  1  5  3

    solution needed

    What will be the output of the following snippet of code? public class Test { public static void main(String[] args) { TreeMap map = new TreeMap(); map.put(1, "one"); map.put(2, "two"); map.put(3, "three"); map.put(4, "four"); System.out.print(map.higherKey(2)); System.out.print(map.ceilingKey(2)); System.out.print(map.floorKey(1));
    Please include headers, import java.util.TreeMap;
    
    //Returns: 321null
    
    Explaination;
    1) higherKey: returns the least key strictly greater than the given key, or null if there is no such key.
    2) ceilingKey: returns the least key greater than or equal to the given key, or null if there is no such key.
    3) floorKey: returns the greatest key less than or equal to the given key, or null if there is no such key.
    4) lowerKey: returns the greatest key strictly less than the given key, or null if there is no such key.

    public by Gabrielyan  2048  0  6  1

    Quick link checker with CasperJS

    casper = require("casper").create()
    errors = []
    
    errorHandler = (url, status, msg)->
        errors.push {url: url, status: status, msg: msg}; 
    
    
    if casper.cli.has(0)
        url = casper.cli.get(0)
    else 
        casper.echo "Missing url argument", "ERROR"
        casper.exit()
    
    #----------------------------------------------------
    
    casper.start url, (res)->  
        if not res.status or res.status isnt 200 
            errorHandler(url, res.status, res.statusText or 'Something Wrong')
            
        links = @getElementsAttribute('a', 'href')
        
        links = links.filter (link)-> # if need...
            link isnt '#'
            
        @each links, (self, link) ->
            self.thenOpen link, (res) ->
                if res.status and res.status is 200
                    @echo "#{link} - #{res.status} #{res.statusText}", 'INFO'
                else
                    errors.push {url: link, status: res.status, msg: res.statusText}
        
    .run ->
        if errors.length > 0
            @echo "Errors: #{errors.length}"
            for error in errors 
                @echo "url: #{error.url},  status: #{error.status},  msg: #{error.msg}", 'ERROR'
        else 
            @echo "All Done!", "INFO"
                
        @exit()

    public by manolenso  191696  0  4  0

    verification loading jquery

    verification loading jquery: app.coffee
    $ -> alert "jQuery est chargée!"
    
    
    

    public by merqlove  207891  2  4  2

    AngularJS / NodeWebkit logger service.

    AngularJS / NodeWebkit logger service.: logger.coffee
    'use strict';
    
    angular.module('vc.messages')
    .factory "logger", ['$log', 'NwService', ($log, NwService) ->
      log4js = require('log4js')
    
      log4js.configure {
        appenders: [
          {
            type: 'console'
            layout: {
              type: 'pattern'
              pattern: "%m%n"
            }
            category: 'console'
          },
          {
            type: 'file'
            absolute: true
            filename: NwService.dataPath() + '/app.log'
            category: 'file'
            maxLogSize: 1024*1024
            numBackups: 3
            layout: {
              type: 'pattern'
              pattern: "[%d %r] [%p] - %m%n"
            }
          },
        ]
        levels: {
          "[all]": "INFO",
          "console": NwService.isProduction() ? "OFF" : "DEBUG",
          "file": "ERROR"
        }
      }
    
      consoleLogger = log4js.getLogger('console')
    
      ['Trace','Debug','Info','Warn','Error','Fatal'].forEach (levelString) ->
        level = log4js.levels.toLevel(levelString)
    
        consoleLogger[levelString.toLowerCase()] = () ->
          return false unless consoleLogger.isLevelEnabled(level)
          args = Array.prototype.slice.call(arguments)
          switch levelString
            when 'Info', 'Warn'
              $log[levelString.toLowerCase()](args)
            else
              args.unshift(level)
              consoleLogger.log.apply(consoleLogger, args)
    
      return {
        file: log4js.getLogger('file')
        console: consoleLogger
      }
    ]
    
    

    public by merqlove  2334  1  4  0

    NgAnimate Mock in CoffeeScript

    NgAnimate Mock in CoffeeScript: angular-animate-mock.coffee
    # Converted JS from http://mgcrea.github.io/angular-strap
    
    angular.module('ngAnimate', [])
    
    .factory('$$animateReflow', ['$window', '$timeout', ($window, $timeout) ->
      requestAnimationFrame = $window.requestAnimationFrame ||
                              $window.webkitRequestAnimationFrame ||
                              (fn) ->
                                $timeout(fn, 10, false)
    
    
      cancelAnimationFrame = $window.cancelAnimationFrame       ||
                             $window.webkitCancelAnimationFrame ||
                             (timer) ->
                               $timeout.cancel(timer)
    
      (fn) ->
        id = requestAnimationFrame(fn)
        () ->
          cancelAnimationFrame(id)
    ])
    
    

    public by Alexander Merkulov  2734  0  4  0

    AngularJS service to work with Chef DataBags via Knife CLI.

    AngularJS service to work with Chef DataBags via Knife CLI.: DataBagService.coffee
    'use strict';
    
    class DataBagService
      _exec = {}
      _tmp = {}
      _fs = {}
      _knife = ''
    
      constructor: (@$q) ->
        console.log 'DataBagService: constructor called'
        _exec = require('child_process').exec
        _tmp = require('tmp')
        _fs = require('fs')
        this.setKnifePath()
    
      setKnifePath:(path) ->
        _knife = path || 'RBENV_VERSION=2.0.0-p353 knife'
    
      getDataBagItem: (client, data_bag, item) ->
        return {} unless client && data_bag && item
    
        deferred = @$q.defer()
    
        _exec "#{_knife} data bag show #{data_bag} #{item} "+
              authString(client), (err, stdout, stderr) ->
                if err
                  deferred.resolve(false)
                  throw err
                else
                  deferred.resolve(JSON.parse(stdout))
    
        return deferred.promise
    
      putDataBagItem: (client, data_bag, item) ->
        return {} unless client && data_bag && item
    
        deferred = @$q.defer()
    
        _tmp.file {postfix: '.json'}, (err, path, fd) ->
          if (err)
            _tmp.setGracefulCleanup()
            deferred.resolve(false)
            throw err
    
          _fs.writeFileSync path, JSON.stringify(item)
    
          _exec "#{_knife} data bag from file #{data_bag} #{path} "+
                authString(client), (err, stdout, stderr) ->
                  if err
                    deferred.resolve(false)
                    throw err
                  else
                    deferred.resolve(true)
    
        return deferred.promise
    
      userName = (user) ->
        user.replace('-validator','')
    
      authString = (client) ->
        "-u #{client.user} "+
        "-k #{process.env.HOME}/.chef/#{client.user}.pem "+
        "--server-url #{client.base} "+
        "--secret-file #{secretFile(client.user)} "+
        "-F json"
    
      secretFile = (name) ->
        "#{process.env.HOME}/.chef/#{userName(name)}_secret "
    
    angular.module('app.services')
    .service 'DataBagService', [ '$q', DataBagService ]
    
    

    public by merqlove  6627  13  4  3

    Global Resolve for Angular ngRoute

    Global Resolve for Angular ngRoute: routes.coffee
    'use strict';
    
    angular.module('app.routes')
    .config(['$routeProvider', ($routeProvider) ->
    
        angular.extend({}, $routeProvider, {
          orgWhen: (path, route) ->
            route.resolve ||= {}
            route.resolve = _.merge(route.resolve, {
              chef: 'OrganizationCheckerProvider'
            })
            $routeProvider.when.call(this, path, route)
        })
    
        # Organizations
    
        .when('/organizations', {
            templateUrl: '/templates/organizations/index.html',
            controller: 'OrganizationsCtrl',
            controllerAs: 'orgs',
          })
    
        .when('/organizations/new', {
            templateUrl: '/templates/organizations/new.html',
            controller: 'OrganizationsNewCtrl',
            controllerAs: 'org',
          })
        .orgWhen('/organizations/:organizationId', {
            templateUrl: '/templates/organizations/show.html',
            controller: 'OrganizationsShowCtrl',
            controllerAs: 'org',
          })
        .orgWhen('/organizations/:organizationId/edit', {
            templateUrl: '/templates/organizations/edit.html',
            controller: 'OrganizationsEditCtrl',
            controllerAs: 'org',
          })
      ])
    
    
    • Public Snippets
    • Channels Snippets