Skip to content

Instantly share code, notes, and snippets.

@icantrank
icantrank / Fibbonacier.js
Last active June 9, 2021 12:55
Fibbonacier.js - Someone showed me a bad example of array restructuring yesterday. i thought this was prettier.
let Fibbonacier = function() {
let cache = [1,1]
let step = () => {
let nums = [...cache]
let [a,b] = [nums.pop() || 1, nums.pop() || 1]
cache.push(a+b)
}
return {
step : step,
result: cache
@icantrank
icantrank / proxy.js
Created January 25, 2021 13:23
websocket proxy nodejs
// proxies requests to /folder to / on 8081
// proxies requests to /folder2 to /folder2/ on 8081
// all other requests sent to 8080
// listens on 80
var http = require('http');
//2 dependencies, install them
var proxyRules = require('http-proxy-rules')
var websocket = require('http-proxy');
@icantrank
icantrank / oodler.js
Last active June 9, 2021 12:56
oodler.js - node oodler and visit localhost in browser and lol
//node oodler and visit localhost in browser and lol
var http = require('http')
http.createServer( (req,res) => {
res.writeHead(200, {'contentType' : 'text/html'})
res.write(
`
<!DOCTYPE html>
<html lang="en">
<head>
@icantrank
icantrank / weather.js
Created September 18, 2017 20:41
Repeating OpenWeather API in node.js with database
let cron = require('node-schedule'), //npm install these or you're gna hae a bad time
loki = require('lokijs'), //loki is db with persistance coz saves json as a file
fetch = require('node-fetch') //browser fetch in node
let locations = ['London','Newcastle','Glasgow'] //or export an arr of locs in another file and require('./locations.js')
let openWeatherKey = '123456789abcdefghijk' //not a reel api key
let openWeatherUrl = (location) => {
return 'http://api.openweathermap.org/data/2.5/weather?q=' + location + ',uk&appid=' + openWeatherKey //change uk if you're grabbing data from elsewhere durr
@icantrank
icantrank / mailchimp-ajax.html
Last active September 18, 2017 20:21
Mailchimp subscription with ajax and jsonp (and publicly visible apikey but who gives af)
<!doctype html>
<!-- This works, but it's sketchy and leaves ur api key available for stealing -->
<!-- 17 revisions coz 8 tabs wtf github? -->
<head>
<title>Scetchy mailchimp form</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js">
</script>
</head>
<body>