Skip to content

Instantly share code, notes, and snippets.

View pchrysa's full-sized avatar
:octocat:
Code, Love and Rock n Roll

Chrysa pchrysa

:octocat:
Code, Love and Rock n Roll
View GitHub Profile
@pchrysa
pchrysa / Converter.kt
Created August 8, 2017 17:16
Convert Decimal to Binary and Vice Versa in Kotlin
package com.thecodevs.Converter
import com.thecodevs.Math.*
fun toDecimal(binaryNumber : String) : Int {
var sum = 0
binaryNumber.reversed().forEachIndexed {
k, v -> sum += v.toString().toInt() * pow(2, k)
}
return sum
@pchrysa
pchrysa / TextToMorse.kt
Last active August 3, 2017 13:27
Convert text to morse code in Kotlin
/*
Write a function to convert a string given by the user, to the respective morse code sequence.
Morse code https://en.wikipedia.org/wiki/Morse_code
Example:
User Input: Hello
Output: .... . .-.. .-.. ---
*/
@pchrysa
pchrysa / SumOfDigits.kt
Created August 2, 2017 21:29
Sum digits of a given number in Kotlin
/*
In mathematics, the digit sum of a given integer is the sum of all its digits (e.g.
the digit sum of 84001 is calculated as 8+4+0+0+1 = 13).
Write a function that will get an integer and will return the digit sum for that integer.
*/
fun main(args: Array<String>) {
sumOfDigits("84001");
}
@pchrysa
pchrysa / FloydsTriangle.kt
Last active August 1, 2017 21:31
Floyd's triangle in Kotlin
/*
Floyd's triangle lists the natural numbers in a right triangle aligned to the left where
- the first row is 1
- successive rows start towards the left with the next number followed by successive naturals listing one more number than the line above.
The first few lines of a Floyd triangle (n=5) looks like this:
1
2 3
@pchrysa
pchrysa / fork_up_to_date.md
Created February 14, 2017 09:22
How to keep a forked project up to date with the original repo changes

1. Clone forked repo from your github:

git clone git@github.com:YOUR-GITHUB-USERNAME/FORKED-REPO-NAME.git

2. Add remote from original repository in your forked repository:

cd forked-repo-name
git remote add forked git://github.com/ORIGINAL-USERNAME/FORKED-REPO-NAME.git

3. Updating your fork master branch to keep up with original repo changes:

@pchrysa
pchrysa / index.js
Last active February 10, 2017 10:27
Scrape with Cheerio
var fs = require('fs');
var request = require('sync-request');
var cheerio = require('cheerio');
var _ = require('lodash');
const months = ['gennaio', 'febbraio', 'marzo', 'aprile', 'maggio', 'giugno', 'luglio', 'agosto', 'settembre', 'ottobre', 'novembre', 'dicembre'];
var dates = [];
const url = 'http://m.paginainizio.com/onomasticimob.php?mese=';
for (var m in months) {
@pchrysa
pchrysa / index.js
Last active October 11, 2016 10:38
Playing with passphrases
function playPass(s, n) {
let finalStr = '';
for (let i in s) {
let letter = s[i];
if (isLetter(letter)) {
finalStr += upperOrLower(nextLetter(letter, n), i);
} else {
if (isNumeric(letter)) {
finalStr += "" + nineComplement(letter);
} else {