Skip to content

Instantly share code, notes, and snippets.

View quangnd's full-sized avatar
💭
Obsidian hooker :")

Nguyen Dang Quang quangnd

💭
Obsidian hooker :")
View GitHub Profile
@quangnd
quangnd / gist:a8f3b48ea596718ca4f3fbb89eef85b5
Last active August 5, 2016 07:53
Get random number in Javascript
function getRandomArbitrary(min, max) {
return Math.random() * (max - min) + min;
}
function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min + 1) + min);
}
function getRandomBetweenZeroAndOne() {
return Math.round(Math.random());
@quangnd
quangnd / resize_image.js
Created July 18, 2016 09:07
Resize image with gm module
var fs = require('fs'),
gm = require('gm').subClass({imageMagick: true});;
var IMAGE_DIR = __dirname +'/images/',
SAVE_DIR = __dirname +'/imagesResize/';
var imageList = ['1.jpg', '2.jpg', '3.jpg'];
var resize_keep_ratio = function(name) {
console.log(IMAGE_DIR+ name);
@quangnd
quangnd / simplePrototype.js
Last active July 19, 2016 10:43
Explaining Prototype of function as well as Prototype of Object
'use strict';
function Cat(name, color) {
this.name = name
this.color = color
//An empty object is created. After this, JS updates the function's PROTOTYPE property to point to this object (Cat object)
}
Cat.prototype.age = 5; //We haven't even created a Cat object, but PROTOTYPE property created behind the scenes..., then we add the age to the Cat's protype.
@quangnd
quangnd / inheritanceChains.js
Created July 19, 2016 10:09
Create Prototypes with Inheritance Chains
'use strict';
function Animal(voice) {
this.voice = voice || "grunt"
}
Animal.prototype.speak = function() {
display(this.voice);
}
@quangnd
quangnd / prototypesWithClasses.js
Created July 19, 2016 10:20
Crate Prototypes with Classes
'use strict';
//New in ES6
class Animal {
constructor(voice){
this.voice = voice || "Grunt"
}
speak() {
console.log(this.voice)
}
@quangnd
quangnd / findOccurence.js
Last active July 24, 2016 08:02
Find occurrence of character in string JS
var theString = "This is a string.";
console.log(theString.split("i").length - 1);
//Example: Count amount of vowels in string
function amoutVowel(wort){
var vowels = ["a","e","i","o","u","ä","ö","ü","E","O","A","I","U"];
var countVowel = 0;
for(var i = 0; i < vowels.length; i++) {
if (wort.indexOf(vowels[i]) !== -1) {
@quangnd
quangnd / dynamicPivot.sql
Created July 25, 2016 09:26
Dynamic Pivot SQL Server(simple)
create table temp
(
date datetime,
category varchar(3),
amount money
)
insert into temp values ('1/1/2012', 'ABC', 1000.00)
insert into temp values ('2/1/2012', 'DEF', 500.00)
insert into temp values ('2/1/2012', 'GHI', 800.00)
@quangnd
quangnd / sortedLongestStr.js
Created July 28, 2016 01:34
Find new sorted string and remove duplicate char in string
//Take 2 strings s1 and s2 including only letters from ato z. Return a new sorted string, the longest possible, containing distinct letters, - each taken only once - coming from s1 or s2.
/*
Examples:
a = "xyaabbbccccdefww"
b = "xxxxyyyyabklmopq"
longest(a, b) -> "abcdefklmopqwxy"
a = "abcdefghijklmnopqrstuvwxyz"
longest(a, a) -> "abcdefghijklmnopqrstuvwxyz"
@quangnd
quangnd / gist:198eb8e7c8f17fca00a11bae36977bc3
Created July 30, 2016 13:13 — forked from paulallies/gist:0052fab554b14bbfa3ef
Remove node_modules from git repo
#add 'node_modules' to .gitignore file
git rm -r --cached node_modules
git commit -m 'Remove the now ignored directory node_modules'
git push origin master