Skip to content

Instantly share code, notes, and snippets.

@crwang
crwang / node_oauth_token_request
Last active February 11, 2020 16:41
Node JS request to get an oauth token with grant_type of password (to our doorkeeper endpoint)
var default_headers, site_root = 'http://localhost:3000';
default_headers = {
'User-Agent': 'Mozilla/5.0 (X11; Linux i686; rv:7.0.1) Gecko/20100101 Firefox/7.0.1',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Language': 'en-us,en;q=0.5',
'Accept-Encoding': 'gzip, deflate',
'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.7',
// 'Connection': 'keep-alive',
'Cache-Control': 'max-age=0'
@crwang
crwang / js-class-example.js
Last active August 29, 2015 14:00
JS Class example
// Class definition / constructor
var Vehicle = (function() {
/** @const */ var SPEED_LIMIT = 5;
/**
* A vehicle.
*
* @constructor
* @this {Vehicle}
function average (arr)
{
return _.reduce(arr, function(memo, num)
{
return memo + num;
}, 0) / arr.length;
}
@crwang
crwang / post_complex_json_to_rails.md
Last active August 29, 2015 14:03
Post Complex JSON to Rails

Post from command line

curl -H "Content-Type:application/json" -H "Accept:application/json" -d "{\"commute\":{\"minutes\":0, 
\"startTime\":\"Wed May 06 22:14:12 EDT 2009\", 
\"locations\":[{\"latitude\":\"40.4220061\",
\"longitude\":\"40.4220061\"}, {\"latitude\": \"30\", \"longitude\":\"40\"}]}}"  http://localhost:3000/test

In Rails

@crwang
crwang / ul-css-csv.md
Last active August 29, 2015 14:03
Unordered list css to csv

Html

<ul class="list-csv">
  <li>one</li>
  <li>two</li>
  <li>three</li>
</ul>

LESS

@crwang
crwang / tab-through-css.less
Last active August 29, 2015 14:04
Set tab active somewhat dynamically through css
@import "vendor/mixins/for.less";
/*
// https://github.com/seven-phases-max/less.curious/blob/master/src/for.less
// ............................................................
// .for
.for(@i, @n) {.-each(@i)}
.for(@n) when (isnumber(@n)) {.for(1, @n)}
.for(@i, @n) when not (@i = @n) {
.for((@i + (@n - @i) / abs(@n - @i)), @n);
@crwang
crwang / bootstrap_alert_fade_in_out.md
Created October 7, 2014 01:16
Bootstrap alert fade in and out

None of the current answers worked for me. I'm using Bootstrap 3.

I liked what Rob Vermeer was doing and started from his response.

For a fade in and then fade out effect, I just used wrote the following function and used jQuery:

Html on my page to add the alert(s) to:

@crwang
crwang / rails_rescue_output
Created October 10, 2014 01:35
Rails Rescue output
begin
some_operation_here_that_may_throw_an_exception
rescue
puts $!.message
end
@crwang
crwang / app_collections_base.js
Last active August 29, 2015 14:09
Link Headers in Rendr
var RendrBase = require('rendr/shared/base/collection'),
_ = require('underscore'),
syncer = require('../shared/syncer');
_.extend(RendrBase.prototype, syncer);
module.exports = RendrBase.extend({});
@crwang
crwang / simple-node-server.md
Last active October 14, 2015 14:39
Setting up simple node server