Skip to content

Instantly share code, notes, and snippets.

View sp90's full-sized avatar
🦜
Focusing

Simon sp90

🦜
Focusing
View GitHub Profile
@sp90
sp90 / dynogels-to-mongoose.js
Last active February 27, 2019 10:11
A script to help you move your data from your dynamodb to mongodb, if your using dynogels and mongoose
const Promise = require('bluebird')
const _ = require('lodash')
// Include your dynogels models
let models = require('./routes/helpers/models')
// Include your mongoose models
let mongooseModels = require('./routes/helpers/mongooseModels')
module.exports = (settings, itemsMapping) => {
@sp90
sp90 / elasticExample.js
Last active December 12, 2018 09:05
Elastic example - querying survey data
let dataSet = [{
"survey_answers": [
{
"id": "9ca01568e8dbb247", // As they are, this is the key to groupBy
"option_answer": 5, // Represent the index of the choosen option
"type": "OPINION_SCALE" // Opinion scales are 0-10 (meaning elleven options)
},
{
"id": "ba37125ec32b2a99",
"option_answer": 3,
@sp90
sp90 / find_count_of_lowest.py
Created November 15, 2018 16:52
Finding the lowest number and count the amount of occurrences
list_of_numbers = [1, 2 , 1, 3]
def find_count_of_lowest(numbers):
numbers.sort()
lowest_number = numbers[0]
count_lowest_number = 0
for number in numbers:
if number == lowest_number:
@sp90
sp90 / helper_functions.py
Last active November 12, 2018 08:46
Helper functions
# Numbers between
def numbers_between(numbers, min_range, max_range):
# Create empty list to contain our results
result = []
# Run through each number
for number in numbers:
# If number is bigger or equal to min_range and bigger or equal to max_range
if number >= min_range and number <= max_range:
@sp90
sp90 / scrollama-scale.js
Created October 15, 2018 21:25
A vue extension that uses scrollama to scale items on scroll in a smooth motion (Its abit janky)
import 'intersection-observer';
import scrollama from 'scrollama';
const scroller = scrollama();
// setup the instance, pass callback functions
scroller
.setup({
step: settings.$refs.slide__item,
# First we def (define) a function that takes 2 arguments:
# 1. argument is the text to look for occurances
# 2. argument is the word_to_count
def count_word_in_text(text, word_to_count):
# The count of our word that we're counting
count = 0
# The text index looking from
start = 0
@sp90
sp90 / count.py
Created October 1, 2018 08:11
Simple python function to count occurenances
# We need to count the occurance of words in a text
def count_word_in_text(text, word_to_count_by):
# We first have the text and then we run a "count" method on the text
# then we parse the word_to_count_by
return text.count(word_to_count_by)
# Now we add a string of text we want to count the occurances of a certain word in
# Secound paramater is the word we want to count
count_of_words = count_word_in_text("Hello world, its a great day in this world", "world")
@sp90
sp90 / increment.py
Created October 1, 2018 07:43
A simple increment function in python
# So first we def (define) the function and giving it
# the name increment, and adding one parameter
# i call that number_to_increment because its
# the number that you want to increment by 1
def increment(number_to_increment):
# Then we return the number_to_increment + 1
# So if the number_to_increment is 3 it will return 4, if number_to_increment is 500 it will return 501
return number_to_increment + 1
# Here we test the function works
@sp90
sp90 / angularjs.excelgenerator.js
Created July 13, 2018 07:24
A angular based file to generate excel from html
(function() {
'use strict';
angular
.module('factory.Excel', [])
.factory('Excel', Excel);
function Excel($document, $window) {
return {
create: create
@sp90
sp90 / whenScrolled.js
Last active June 12, 2018 08:11
Simplest infinite scroll module (194 bytes GZIPPED)
(function() {
'use strict';
var modules = [];
angular
.module('directive.whenScrolled', modules)
.directive('whenScrolled', whenScrolled);
function whenScrolled() {