Skip to content

Instantly share code, notes, and snippets.

Avatar
🦜
Focusing

Simon sp90

🦜
Focusing
View GitHub Profile
View atlas.ts
import { of, BehaviorSubject } from 'rxjs';
import { fromFetch } from 'rxjs/fetch';
import { switchMap, catchError } from 'rxjs/operators';
interface CustomMethodInterface {
name: string;
endpoint: string;
method: 'GET' | 'POST' | 'PATCH' | 'DELETE';
}
@sp90
sp90 / client.html
Created Jul 19, 2019
Simple karma testing client.html styling
View client.html
<!DOCTYPE html>
<!--
The entry point for client. This file is loaded just once when the client is captured.
It contains socket.io and all the communication logic.
-->
<html>
<head>
<!-- %X_UA_COMPATIBLE% -->
<title>Karma</title>
<link href="favicon.ico" rel="icon" type="image/x-icon" />
@sp90
sp90 / chainable-methods.js
Last active Jul 9, 2019
A simple way of chaining methods
View chainable-methods.js
class klass {
constructor() {}
sum(...args) {
this.value = args.reduce((sum, current) => sum + current, 0);
return this;
}
add(value) {
@sp90
sp90 / Array-operations.js
Created Mar 20, 2019
Small subset of javascript operations on an array
View Array-operations.js
let myArr = [0, 2, 5]
let arr2 = [1, 6, 7]
// Attach a value to the end of an array
myArr.push(6)
console.log(myArr) // [0, 2, 5, 6]
// Attach a value to the beginning of an array
myArr.unshift(3)
console.log(myArr) // [3, 0, 2, 5, 6]
@sp90
sp90 / dynogels-to-mongoose.js
Last active Feb 27, 2019
A script to help you move your data from your dynamodb to mongodb, if your using dynogels and mongoose
View dynogels-to-mongoose.js
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 Dec 12, 2018
Elastic example - querying survey data
View elasticExample.js
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 Nov 15, 2018
Finding the lowest number and count the amount of occurrences
View find_count_of_lowest.py
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 Nov 12, 2018
Helper functions
View helper_functions.py
# 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 Oct 15, 2018
A vue extension that uses scrollama to scale items on scroll in a smooth motion (Its abit janky)
View scrollama-scale.js
import 'intersection-observer';
import scrollama from 'scrollama';
const scroller = scrollama();
// setup the instance, pass callback functions
scroller
.setup({
step: settings.$refs.slide__item,
View count_word_in_text.py
# 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
You can’t perform that action at this time.