Skip to content

Instantly share code, notes, and snippets.

View lhuria94's full-sized avatar
🏠
Working from home

Love Huria lhuria94

🏠
Working from home
View GitHub Profile
@lhuria94
lhuria94 / old-mode-100755-new-mode-100644.md
Created March 29, 2018 07:51
How do I remove files saying “old mode 100755 new mode 100644” from unstaged changes in Git?

Vá até o seu repositório e execute

git config core.filemode false

@lhuria94
lhuria94 / rebase.md
Created January 6, 2018 08:20
Ultimate rebase-onto-master guide

Rebase "web-123-my-branch" onto master:

if you're the only person who is working on a branch...

$ git checkout web-123-my-branch # make sure you're on the right branch
$ git fetch # update remote refs
$ git rebase origin/master # perform the rebase onto the current state of master
  # for each conflict, edit file, resolve conflicts, git add -u <file>, git rebase --continue
$ git push -f origin web-123-my-branch # overwrite remote branch with newly rebase branch
@lhuria94
lhuria94 / node-beginner-part1.js
Last active January 5, 2018 11:34
Node.js (Notes) -- Beginner Part 1
-------------------------------------------------------------
// The process object is a global that provides information about,
// and control over, the current Node.js process.
// As a global, it is always available to Node.js applications without using require().
// Instead of depending on process.argv property
// we can use a third party node module called `yargv` as process.argv
// can be a bit messy.
-------------------------------------------------------------
@lhuria94
lhuria94 / tribonacci.js
Created January 2, 2018 14:15
If you have completed the Tribonacci sequence kata, you would know by now that mister Fibonacci has at least a bigger brother. If not, give it a quick look to get how things work.
// Well, time to expand the family a little more: think of a Quadribonacci starting with a signature of 4 elements and each following element is the sum of the 4 previous, a Pentabonacci (well Cinquebonacci would probably sound a bit more italian, but it would also sound really awful) with a signature of 5 elements and each following element is the sum of the 5 previous, and so on.
// Well, guess what? You have to build a Xbonacci function that takes a signature of X elements - and remember each next element is the sum of the last X elements - and returns the first n elements of the so seeded sequence.
// xbonacci {1,1,1,1} 10 = {1,1,1,1,4,7,13,25,49,94}
// xbonacci {0,0,0,0,1} 10 = {0,0,0,0,1,1,2,4,8,16}
// xbonacci {1,0,0,0,0,0,1} 10 = {1,0,0,0,0,0,1,2,3,6}
// xbonacci {1,1} produces the Fibonacci sequence
function Xbonacci(signature, n){
@lhuria94
lhuria94 / growth.js
Last active July 1, 2022 15:16
In a small town the population is p0 = 1000 at the beginning of a year. The population regularly increases by 2 percent per year and moreover 50 new inhabitants per year come to live in the town. How many years does the town need to see its population greater or equal to p = 1200 inhabitants?
// At the end of the first year there will be:
// 1000 + 1000 * 0.02 + 50 => 1070 inhabitants
// At the end of the 2nd year there will be:
// 1070 + 1070 * 0.02 + 50 => 1141 inhabitants (number of inhabitants is an integer)
// At the end of the 3rd year there will be:
// 1141 + 1141 * 0.02 + 50 => 1213
// It will need 3 entire years.
@lhuria94
lhuria94 / narcissistic.js
Created January 2, 2018 13:16
A Narcissistic Number is a number which is the sum of its own digits, each raised to the power of the number of digits.
// For example, take 153 (3 digits):
// 1^3 + 5^3 + 3^3 = 1 + 125 + 27 = 153
// and 1634 (4 digits):
// 1^4 + 6^4 + 3^4 + 4^4 = 1 + 1296 + 81 + 256 = 1634
// The Challenge:
// Your code must return true or false depending upon whether the given number is a Narcissistic number.
@lhuria94
lhuria94 / maskify.js
Created January 2, 2018 13:14
Usually when you buy something, you're asked whether your credit card number, phone number or answer to your most secret question is still correct. However, since someone could look over your shoulder, you don't want that shown on your screen. Instead, we mask it.
// Your task is to write a function maskify, which changes all but the last four characters into '#'.
// Examples
// maskify("4556364607935616") == "############5616"
// maskify( "64607935616") == "#######5616"
// maskify( "1") == "1"
// maskify( "") == ""
// "What was the name of your first pet?"
// maskify("Skippy") == "##ippy"
@lhuria94
lhuria94 / vowel.js
Created January 2, 2018 13:13
For example, the string "This website is for losers LOL!" would become "Ths wbst s fr lsrs LL!".
function disemvowel(str) {
return str.replace(/[aeiou]/gi, '');
}
@lhuria94
lhuria94 / middle.js
Created January 2, 2018 13:12
As a part of this Kata, you need to create a function that when provided with a triplet, returns the index of the numerical element that lies between the other two elements.
var gimme = function (inputArray) {
// Clone the input array.
var clonedArray = inputArray.slice(0);
// Sort it in ascending order.
clonedArray.sort(function(a, b){
return a-b
});
return inputArray.indexOf(clonedArray[1]);
};
@lhuria94
lhuria94 / xbonacci.js
Created January 2, 2018 13:10
Build a Xbonacci function that takes a signature of X elements - and remember each next element is the sum of the last X elements - and returns the first n elements of the so seeded sequence.
// This solves the problem with last and previous digit addition.
function Xbonacci(signature, n){
var totalCallsToMake = n - signature.length;
var tempArr = signature.slice(0);
const reducer = (accumulator, currentValue) => accumulator + currentValue;
// Looping through.
for (var i=1; i<=totalCallsToMake; i++) {
var lastTwoEl = tempArr.slice(-2);
tempArr.push(lastTwoEl.reduce(reducer));
}