Skip to content

Instantly share code, notes, and snippets.

@khoand0000
khoand0000 / cleanDiacritics.md
Last active January 1, 2016 06:25
notice when using .cleanDiacritics
@khoand0000
khoand0000 / should-integrate-underscore-string-into-underscore.md
Created January 1, 2016 05:58
Should integrate underscore string into underscore?

When you need using functions from _.string for _.js chaining

_.mixin(s.exports());

But I think you should do if using both because chaining with _.string will soon occur. Unless you want keep _.string independently and no chaining with _.string.

@khoand0000
khoand0000 / map-object-with-keys.js
Last active January 1, 2016 05:31
tap vs. mapObject
_.mixin({
mapObjectWithKeys: mapObjectWithKeys
});
/////////////////////
/**
* is similar to `.mapObject` but just apply `iteratee` for properties have key in `keys`
* Eg:
@khoand0000
khoand0000 / groupby-vs-partition.md
Last active January 1, 2016 04:14
groupBy vs. partition
.groupBy .partition
Same split array follow given condition same
Difference return >= 1 set return <= 2 sets
Return object with each item is key: Array Array with 2 items [Array, Array]
@khoand0000
khoand0000 / groupby-vs-indexby.md
Created December 30, 2015 18:27
groupBy vs.indexBy
.groupBy .indexBy
return type object object
each key:value, value type is array (contains values from original list) value from original list
if value has same key group override; keep last value

Example: .indexBy

var stooges = [{name: 'moe', age: 40}, {name: 'larry', age: 50}, {name: 'curly', age: 50}];
_.indexBy(stooges, 'age');
@khoand0000
khoand0000 / array-objects-to-object.md
Last active December 30, 2015 21:07
Convert array of objects to object

I have array of objects like that

var arr = [
  { id: 4, name: 'John'},
  { id: 7, name: 'Mary'}
];

I want to convert it to object like that

{
@khoand0000
khoand0000 / which-library-format-number.md
Last active December 30, 2015 15:58
Which library format number?

There are 2 libraries I am using, depend on your situation

[accounting.js] [_.string]
number formatting yes yes
currency support yes no
string manipulating no yes
size smaller larger
suit to need currency support and don't need to string manipulating (rarely) almost cases, should use it
@khoand0000
khoand0000 / invoke-vs-each-vs-map.md
Last active December 30, 2015 12:46
_.invoke() vs. _.each() vs. _.map()

_.invoke() vs. _.each() vs. _.map(): read http://stackoverflow.com/questions/13193959/difference-between-underscore-js-each-method-and-invoke-method

  • _.invoke(list, methodName, *arguments) methodName is string, is function belongs to object object.methodName(...). return result as _.map()
  • _.each(list, iteratee, [context]) iteratee is not string (a function name). iteratee is called for each object/item as its parameter iteratee(object). return no result
  • _.map(list, iteratee, [context]) like _.each(), apply iteratee for each item iteratee(object), but difference is that return result
@khoand0000
khoand0000 / filter-object-preserve-keys.md
Last active December 30, 2015 12:17
filter object with preserve keys

I have a object

var obj = {
  1: [5, 7, 8],
  7: [4, 2],
  10: [],
  19: [4]
}; // each key:value is id: array
@khoand0000
khoand0000 / why-do-i-write-posts.md
Last active December 31, 2015 14:08
Why do I write posts?

Why do I need to write posts/notes? How do I increase my code speed?

Because they help me write code faster. You will wonder that why is faster? They take me more time to do another thing instead of focus writing code. I though it is as you are thinking. Let me sharing my experience about it.

I have many experience years about programming, almost problems I can solve them by using my knowledge, experience and google, ofcourse. But my solving issues speed is not fast as I expected even I solved them before. One year ago, I realized my problem from recent projects and find down why. There are points I found:

1. Don't keep any solution somewhere.

What action do I face a problem/issue? Check the issue I have met or not

  • If I haven't met it before, depend on its complex