Skip to content

Instantly share code, notes, and snippets.

🦄
Jumping over Rainbows...

Theofanis Despoudis theodesp

🦄
Jumping over Rainbows...
  • Teckro
  • Ireland
Block or report user

Report or block theodesp

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@theodesp
theodesp / addBinary.go
Last active Sep 17, 2019
Add 2 Binary Strings #go
View addBinary.go
/*
Observation: We start from the last char for each string. As long as we have not reached the beginning we compare the chars. The math is
1 + 1 = 0 (curry = 1)
1 + 0 = 0 + 1 = 1 (curry = 0)
1 + 1 = 1 (curry = 1) if curry = 1
1 + 0 = 0 + 1 = 0 (curry = 1) if curry = 1
If we have a curry in the end we prepend the 1
@theodesp
theodesp / anagrams.go
Last active Sep 17, 2019
Check if 2 strings are anagrams #go
View anagrams.go
/*
To find if 2 strings are anagrams we simply put each letter of first into a frequency table. Then for each other letter of b we subtract that count.
At the end we have a frequency table that all the values are 0.
*/
func Anagrams(a string, b string) bool {
count := int32(0)
frequencies := make(map[rune]int32)
for _, val := range a {
frequencies[val] = frequencies[val] + 1
@theodesp
theodesp / substrings.go
Last active Sep 17, 2019
Find all substrings of string s #go
View substrings.go
/*
Observation: To find all substrings of s we have i = 0 til s.length and j = i+1 till s.length and we append each substring s[i:j] to the results.
We need to also have a map to check for duplicates.
*/
func Substrings(s string) []string {
result := []string{}
seen := make(map[string]interface{})
for i := 0;i < len(s); i += 1 {
for j := i+1; j <= len(s); j += 1 {
@theodesp
theodesp / PrimeNumber.go
Last active Sep 17, 2019
Find all the Prime Numbers until N #go
View PrimeNumber.go
/*
Observation: A prime number N cannot be factored. So to find all the prime numbers til N
then for each n <= N we try to find if any number factors the n. If yes we abort as we know that n is not a prime.
*/
func GetPrimeNumbers(to int) []int {
result := []int{}
for i := 1; i <= to; i+=1 {
isFactored := false
@theodesp
theodesp / flatten.js
Last active Sep 17, 2019
Flattens an array of arbitrarily nested arrays of integers into a flat array of integers #go
View flatten.js
/**
* Flattens an array of arbitrarily nested arrays of integers
* into a flat array of integers.
*
* @param {array} arr The array to flatten.
* @returns {array} Flattened array
*/
const flatten = (arr = []) => {
if (!isArray(arr)) {
return [];
View example.json
{ "name":"John", "age":30, "phone":null }
View console
Εσύ και 9 άλλοι το αγαπάτε
View loadTranslationsFor.js
function loadCldrData(languageTag = 'en', $ = jQuery) {
return $.when(
$.get( `js/vendor/cldr/${languageTag}/ca-gregorian.json` ),
$.get( `js/vendor/cldr/${languageTag}/currencies.json` ),
$.get( `js/vendor/cldr/${languageTag}/numbers.json`),
$.get( `js/vendor/cldr/${languageTag}/units.json` ),
).then(function() {
// Normalize $.get results, we only need the JSON, not the request statuses.
return [].slice.apply( arguments, [ 0 ] ).map(function( result ) {
return result[ 0 ];
View main.js
(function($) {
$.when(
$.get( 'js/vendor/cldr/en/ca-gregorian.json' ),
$.get( 'js/vendor/cldr/en/currencies.json' ),
$.get( 'js/vendor/cldr/en/numbers.json' ),
$.get( 'js/vendor/cldr/en/units.json' ),
$.get( 'js/vendor/cldr/supplemental/plurals.json' ),
$.get( 'js/vendor/cldr/supplemental/timeData.json' ),
$.get( 'js/vendor/cldr/supplemental/weekData.json' ),
$.get( 'js/vendor/cldr/supplemental/likelySubtags.json' )
View message.json
{
"el": {
"like": [
"{0, plural, offset:1",
" =0 {Αγάπησε το}",
" =1 {Το αγαπάς ήδη}",
" one {Εσύ και καποιος άλλος το αγαπάτε}",
" other {Εσύ και # άλλοι το αγαπάτε}",
"}"
]
You can’t perform that action at this time.