Skip to content

Instantly share code, notes, and snippets.

// I guess this happens to be the first file which gets included
// so I might as well use this to write a message here for whoever
// ends up reading this
// you're probably gonna be seeing it as one file, but rest assured
// (or afraid), that this is actually a compiled file, and I don't
// generally scroll through four thousand lines of code in order to
// find the valid_img() function.
@naganowl
naganowl / README.md
Last active August 29, 2015 14:00
Simple line to generate random integers
  • Taken from here.
  • Bitwise OR with 0 floors the number it's paired with.
    • Performance is similar to Math.floor().
  • The post highlights it's higher performance to pre-generate random numbers and then loop through them.
@naganowl
naganowl / README.md
Last active August 29, 2015 14:01
Solution to Chaplin route params with redirectTo.
  • It's still pretty confusing if you ask me and I haven't tested it with routes with params, but as long as it's passed in effectively in the two places, it should be fine.
  • See the previous revision for some extended notes on the method flow
    • tl;dr utils.redirectTo() -> Router.route() -> Route.handler()
  • Route.handler() will only call Route.reverse() if it receives an object (needed for URL query params) which happens if you leave out the url property in the object (first argument) passed into redirectTo().
@naganowl
naganowl / parseNumber.coffee
Created May 23, 2014 21:32
Simple way to ensure an argument is a valid integer
# Convert `num` into a Number type.
parseNumber: (num) ->
parseNum = parseInt num, 10
# Throw out strings and floats.
if parseNum is +num then parseNum else 0
@naganowl
naganowl / README.md
Created June 20, 2014 00:24
Compare and contrast the different strategies of mixing in objects

Forgive the sloppy code and structure, I just needed some scaffolding to explain the issue at hand. Assume RequireJS is used for modules.

The way this is implemented now, mixin will have it's internal variables set to 'privateStuff' rather than 'private', so when the user navigates to the single action, it won't alert private.

This is because of how the items are retrieved in the order they are specified and because the closure scope in the mixin is shared between all instances that use it, but preserve essentially the last variable that it was called with.

The problem can be mitigated if the mixins are mixed on initialize of the models or if the exports of mixin curries the methods which use the private properties, so that the variable is bound to the specified option.

@naganowl
naganowl / Gruntfile.coffee
Created July 3, 2014 02:17
Notes on using grunt-cssshrink
module.exports = (grunt) ->
grunt.initConfig
pkg: grunt.file.readJSON 'package.json'
concat:
# Stylus doesn't concat well with Bootstrap.
css:
src: [
'vendor/bower/bootstrap/dist/css/bootstrap.css'
@naganowl
naganowl / Gruntfile.coffee
Created July 24, 2014 18:41
Example of how to use Grunt template strings.
module.exports = (grunt) ->
grunt.initConfig
pkg: grunt.file.readJSON 'package.json'
docco:
local:
src: ['src/**/*.coffee', '*.md']
dest: 'public/docs/'
public:
@naganowl
naganowl / README.md
Last active August 29, 2015 14:04
Approves all requests on Facebook's Activity Log. Assumes 'Approve' button is in display for all posts.
  • Here's a [bookmarklet](javascript:(function(){}(a = document.querySelectorAll('[name=approve_button]');([]).forEach.call(a, function(e){e.click();});));) of the script for convenience.
@naganowl
naganowl / Gruntfile.coffee
Created August 5, 2014 21:50
Move files into a new location, discarding it's previous file hierarchy
module.exports = (grunt) ->
# Requires a `renameBase` property in task config options.
flattenPath = (dest, src) ->
path = grunt.task.current.data.renameBase
# Make files sibling to those in `renameBase`.
if src.indexOf(path) is 0
dest + src.slice path.length
else
dest + src
@naganowl
naganowl / README.md
Last active August 29, 2015 14:07
Adding LCOV generation to `grunt-mocha-blanket` to enhance `chaplin-mocha-grunt`