Skip to content

Instantly share code, notes, and snippets.

View theodesp's full-sized avatar
🦄
Jumping over Rainbows...

Theofanis Despoudis theodesp

🦄
Jumping over Rainbows...
View GitHub Profile
@theodesp
theodesp / substrings.go
Last active September 17, 2019 14:30
Find all substrings of string s #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 September 17, 2019 14:31
Find all the Prime Numbers until N #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 September 17, 2019 14:30
Flattens an array of arbitrarily nested arrays of integers into a flat array of integers #go
/**
* 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 [];
{ "name":"John", "age":30, "phone":null }
Εσύ και 9 άλλοι το αγαπάτε
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 ];
(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' )
{
"el": {
"like": [
"{0, plural, offset:1",
" =0 {Αγάπησε το}",
" =1 {Το αγαπάς ήδη}",
" one {Εσύ και καποιος άλλος το αγαπάτε}",
" other {Εσύ και # άλλοι το αγαπάτε}",
"}"
]
➜ tree src/locale
src/locale
├── el
│   └── messages.json
└── en
└── messages.json
2 directories, 2 files
Detected user locale is en
main.js:21 Locale Changed to el
main.js:36 Current user locale is el