Skip to content

Instantly share code, notes, and snippets.

View Restuta's full-sized avatar
🦄
Hacking fast and slow.

Anton Vynogradenko Restuta

🦄
Hacking fast and slow.
View GitHub Profile
@Restuta
Restuta / gist:10404410
Last active August 29, 2015 13:58
For Helen
#Define a function calledget_class_average that has one argumentstudents. You can expect students to be a list containing your three students.
#First, make an empty list calledresults.
#For each student item in the classlist, calculate get_average(student) and then call results.append() with that result.
#Finally, return the result of callingaverage() with results.
def get_class_average(students):
results = {} //should be results = []
for item in students:
results.append(get_average(item))
return average(results)
@Restuta
Restuta / reverse.py
Created May 5, 2014 18:52
Helen's poor attempt with Python
def reverse_string(list):
list_length = len(list)
for i in range(0, list_length//2, 1):
temp_letter = list[i]
list[i] = list[list_length - i - 1]
list[list_length - i - 1] = temp_letter
return list
@Restuta
Restuta / gist:fae29de35554dcf7b785
Last active August 29, 2015 14:06
JS local scope definition
<html>
<body>
<script>
/* this function will be accessible through global scope, which is a bad practice
meaning you will be able to call it through window.bla() */
function bla() {
console.log('bla function');
}
</script>
@Restuta
Restuta / _config.yml
Last active August 29, 2015 14:08 — forked from ravasthi/_config.yml
authors:
hanzou:
name: Hanzou Hattori
display_name: Hanzou
gravatar: c66919cb194f96c696c1da0c47354a6a
email: hanzou@company.com
web: http://company.com
twitter: company
github: hhattori
jorgen:
@Restuta
Restuta / gist:6444e056de464af8a0d1
Last active August 29, 2015 14:22
momentjs countdown
//bug: in the following case 1d 00h 00m 25s it would not show "00m" since it only checks previous time component
var x = moment()
.add(1, 'month')
.add(1, 'day')
.add(1, 'hour')
.add(1, 'minute')
.add(10, 'seconds');
function format(duration) {
@Restuta
Restuta / gist:1cfa4d20816a6fa864fc
Created July 20, 2015 05:50
Get random Marvel character
function getRandomBetween(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
var apiKey = 'apikey=ed23113a7ebab2304b0aad655ec41c6a';
var totalCharacters = 1485;
var randomOffset = getRandomBetween(1, totalCharacters);
//var randomOffset = 1341;
$.get('http://gateway.marvel.com:80/v1/public/characters?limit=1&offset=' + randomOffset + '&' + apiKey)
@Restuta
Restuta / gist:9eea61605c01c81dc991
Created July 20, 2015 06:26
Find MARVEL characters without images
function getRandomBetween(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
var apiKey = 'apikey=ed23113a7ebab2304b0aad655ec41c6a';
var totalCharacters = 1485;
var randomOffset = getRandomBetween(1, totalCharacters);
//var randomOffset = 1341;
var idsOfCharsWithoutImage = [];
var imageNotAvailable = 'image_not_available';
@Restuta
Restuta / gist:6f09cf05a5ea2c8e87b3
Last active August 29, 2015 14:25
Ids of Marvel characters without Image
//http://gateway.marvel.com/v1/public/characters?limit=1&offset=1475&apikey=<your-api-key>
//at the time of Jun 20th 2015 512/1485 characters are without image (34.5%)
var idsOfCharactersWithoutImage =
[1010699, 1016823, 1011266, 1011031, 1011198, 1011175, 1011136, 1011170, 1009240, 1009497, 1011164, 1009567, 1011120, 1011194, 1010672, 1011214, 1011382, 1010673, 1016824, 1009153, 1011324, 1009151, 1009346, 1010905, 1011208, 1011253, 1010686, 1011275, 1010827, 1009161, 1010835, 1009162, 1010336, 1015239, 1011766, 1010718, 1017438, 1011137, 1011354, 1009550, 1009176, 1009177, 1009179, 1011262, 1009183, 1010859, 1011296, 1011224, 1009189, 1010881, 1010356, 1009198, 1009201, 1011073, 1010850, 1009204, 1011339, 1011264, 1010688, 1009205, 1011090, 1014973, 1009167, 1009210, 1010887, 1009213, 1011209, 1011190, 1011196, 1011096, 1011355, 1010143, 1009688, 1011258, 1009261, 1009344, 1009536, 1011141, 1009733, 1011331, 1009238, 1011187, 1014999, 1010809, 1011286, 1010798, 1010917, 1009246, 1009237, 1009250, 1011169,
@Restuta
Restuta / nav-highlight.js
Last active August 29, 2015 14:26
Scroll Highlighting (as seen at http://geojson.org/geojson-spec.html)
/**
* Nav Highlighting
*
* Automatically highlights the visible anchored elements
*
* Inspiration
* http://www.phptherightway.com/
*
* @author David King
* @copyright Copyright (c) 2013 +
@Restuta
Restuta / gist:c09ea9cf61f0359f6435
Last active August 29, 2015 14:27
activate-deactivate for header
activate() {
//read model for application header
var appModel = this.modelFor(`application`);
//get current header that is rendered before we enter current route
var currentHeader = appModel.get(`currentHeader`);
//save that header to our current route
this.set(`prevHeader`) = currentHeader;
//set current app header to one that is defined in current route
appModel.set(‘currentHeader’) = this.get(`header`);