Skip to content

Instantly share code, notes, and snippets.

View morisasy's full-sized avatar

Risasi morisasy

View GitHub Profile
@morisasy
morisasy / 01-gulpfile.js
Created June 22, 2018 09:10 — forked from markgoodyear/01-gulpfile.js
Comparison between gulp and Grunt. See http://markgoodyear.com/2014/01/getting-started-with-gulp/ for a write-up.
/*!
* gulp
* $ npm install gulp-ruby-sass gulp-autoprefixer gulp-cssnano gulp-jshint gulp-concat gulp-uglify gulp-imagemin gulp-notify gulp-rename gulp-livereload gulp-cache del --save-dev
*/
// Load plugins
var gulp = require('gulp'),
sass = require('gulp-ruby-sass'),
autoprefixer = require('gulp-autoprefixer'),
cssnano = require('gulp-cssnano'),
@morisasy
morisasy / firstDublicate
Last active June 22, 2022 12:18
Given an array a that contains only numbers in the range from 1 to a.length, find the first duplicate number for which the second occurrence has the minimal index. In other words, if there are more than 1 duplicated numbers, return the number for which the second occurrence has a smaller index than the second occurrence of the other number does.…
def firstDuplicate(a):
""" This function return a first doublicate element if it exit and return -1 if it does not ."""
new_set = set()
for i in a:
if i in new_set:
return i
else:
new_set.add(i)
@morisasy
morisasy / .gitignore
Created May 17, 2018 09:27 — forked from octocat/.gitignore
Some common .gitignore configurations
# Compiled source #
###################
*.com
*.class
*.dll
*.exe
*.o
*.so
# Packages #
def nearest_square(limit):
""" Find the largest square number smaller than limit. """
answer = 0
while (answer+1)**2 < limit:
answer += 1
return answer**2
def word_count(document, search_term):
""" Count how many times search_term appears in document. """
words = document.split()
answer = 0
for word in words:
if word == search_term:
answer += 1
return answer
def remove_dublicates(source):
"""
-This program remove dublicate elements in string or list.
"""
target = []
for element in source:
if element not in target:
target.append(element)
def median(numbers):
numbers.sort()
if len(numbers) % 2:
# if the list has an odd number of elements,
# the median is the middle element
middle_index = int(len(numbers)/2)
return numbers[middle_index]
else:
# if the list has an even number of elements,
# the median is the average of the middle two elements
def which_prize(points):
"""
Returns the prize-winning message, given a number of points
"""
points = int(points)
prize = None
if points <= 50:
prize = "a wooden rabbit"
elif 151 <= points <= 180:
"""
def bus_fares(age):
"""
The bus fares program will print appropriate price for a particular age group.
User should enter a age and the program will suggest the price.
Parameters:
age: enter age as number:
"""
@morisasy
morisasy / garden_calendar.py
Created December 30, 2017 09:41
Garden calendar. A python program that user enter a season for the garden activities.
def garden_calendar(season):
if season == "spring":
print("time to plant the garden!")
elif season == "summer":
print("time to water the garden!")
elif season == "autumn" or season == "fall":
print("time to harvest the garden!")
elif season == "winter":
print("time to stay indoors and drink tea!")
else: