Skip to content

Instantly share code, notes, and snippets.

View marekdano's full-sized avatar
😁
coding for 🚀

Marek Dano marekdano

😁
coding for 🚀
View GitHub Profile
@marekdano
marekdano / progress-work.js
Created November 23, 2015 15:11
careerfoundry module 4 exercise 4
var works = [
{
title: "First Project",
pic: "http://www.animal-photography.com/thumbs/red_tabby_long_hair_kitten_~AP-0UJFTC-TH.jpg"
},
{
title: "Second Project",
pic: "img/silver_kitten.jpg"
},
@marekdano
marekdano / scripts.js
Created November 24, 2015 11:48
careerfoundry module 4 exercise 5
// twitter follow button
!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';
if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';
fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');
$(document).ready(function(){
// smooth scrolling
var $root = $('html, body');
# Find the longest string in an array
words = ["fun", "time", "ab"]
# Simply calling words.sort would sort based on the alphabetic position of the first letter of each word.
puts words.sort_by{ |word| word.length}.last
#The above method can be rewritten with ampersand as
puts words.sort_by(&:length).last
#############################################################################################
# Write a function fib() that a takes an integer "n" and returns the n-th fibonacci number
# fib(0) # => 0
# fib(1) # => 1
# fib(2) # => 1
# fib(3) # => 2
# fib(4) # => 3
# ...
def fib(n)
@marekdano
marekdano / looping_recursively.js
Last active October 27, 2017 13:07
example of looping recursively through array of objects
const list = [
{
n: 1,
children: [{
n: 11,
children: []
}, {
n: 12,
children: []
}]
function balancedParens(string) {
return !string.split("").reduce((previous, char) => {
if (previous < 0) { return previous; }
if (char === "(") { return ++previous };
if (char === ")") { return --previous };
return previous;
}, 0);
}
// test
const coins = {
'penny': 1,
'nickel': 5,
'dime': 10,
'quarter': 25
}
const coinsByAmount = Object.keys(coins).reverse();
function getChange(amount) {
import Redux from 'redux';
const reducer = (state = [], action) => {
if (action.type === 'split_string') {
return action.payload.split('');
} else if (action.type === 'add_character') {
return [...state, action.payload];
}
return state;
}
const files = event.dataTransfer ? event.dataTransfer.files : event.target.files;
const fileToUpload = files[0];
let xhr = new XMLHttpRequest(),
formData = new FormData();
formData.append("test", fileToUpload, fileToUpload.name);
xhr.onreadystatechange = () => {
if(xhr.readyState == 4) {
if(xhr.status >= 200 && xhr.status < 300)
class StoreHelpers {
constructor() {
// This should never run because StoreHelpers is a class of static methods.
// Sanity check: throw an exception if the main application tries to instantiate
throw new Error('ERROR: Unexpected instantiation of static class StoreHelpers.');
}
static cloneDeep(obj) {
var out, v, key;
out = Array.isArray(obj) ? [] : {};