This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var k = (function(){ | |
"use strict" | |
var what, is; | |
what = { | |
type: { | |
is: function (obj) { | |
var type = Object.prototype.toString.call(obj); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"html/template" | |
"net/http" | |
) | |
var layout = template.Must(template.ParseGlob("layouts/base.html")) | |
func init() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# elements = [{name: "story"}, {name: "social"}, {name: "article"}, {name: "article"}, {name: "story"}, {name: "story"}, {name: "article"}] | |
# group_consecutive_elements("article", elements) | |
def group_consecutive_elements(name, elements) | |
grouped_elements = [] | |
elements.chunk{ |e| e.name == name }.each{ |name, ary| grouped_elements.push((name and ary.length > 1) ? [ary] : ary) } | |
grouped_elements.flatten!(1) | |
grouped_elements | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## JSON to nested form data, reset `form` before using | |
## Formats to `fields` requirement from `ng-file-upload` | |
## https://github.com/danialfarid/ng-file-upload/wiki/Rails-Example#rails-4-and-angular-file-upload-3- | |
form = {} | |
## {"test": { "sup": "bro" }} => { "test[sup]": "bro" } | |
json2form = (obj, root) -> | |
angular.forEach obj, (v, k) -> | |
key = if root then "#{root}[#{k}]" else k | |
if angular.isObject(v) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[{ | |
"name": "Alabama", | |
"code": "AL" | |
}, { | |
"name": "Alaska", | |
"code": "AK" | |
}, { | |
"name": "American Samoa", | |
"code": "AS" | |
}, { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[{ | |
"name": "Afghanistan", | |
"code": "AF" | |
}, { | |
"name": "Åland Islands", | |
"code": "AX" | |
}, { | |
"name": "Albania", | |
"code": "AL" | |
}, { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def set_item_options | |
date = Time.now.utc | |
date_credential = date.strftime('%Y%m%d') | |
## S3 | |
@item_options = { | |
key: "#{Rails.env}/uploads/#{@item.id}", | |
acl: 'public-read', | |
algorithm: 'AWS4-HMAC-SHA256', | |
credential: [ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// http://wiki.c2.com/?FizzBuzzTest | |
// Write a program that prints the numbers from 1 to 100. | |
// But for multiples of three print “Fizz” instead of the | |
// number and for the multiples of five print “Buzz”. For | |
// numbers which are multiples of both three and five | |
// print “FizzBuzz”. | |
var fizzBuzz = (function() { | |
var FIZZ = 'Fizz'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function flatten() { | |
var result = []; | |
var currArg; | |
for(var i = 0; i < arguments.length; i++) { | |
currArg = arguments[i]; | |
if (currArg.constructor === Array) { | |
result.push.apply(result, flatten.apply(this, currArg)) | |
} else { | |
result.push(currArg); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// O(n^2) | |
function unique(arr) { | |
var result = []; | |
for(var i = 0; i < arr.length; i++) { | |
if (result.indexOf(arr[i]) === -1) { | |
result.push(arr[i]); | |
} | |
} | |
return result; | |
} |
OlderNewer