Skip to content

Instantly share code, notes, and snippets.

View danba340's full-sized avatar

Daniel Bark danba340

View GitHub Profile
@danba340
danba340 / server.js
Last active October 20, 2022 16:43
import { Application } from "https://deno.land/x/oak/mod.ts";
import { applyGraphQL, gql } from "https://deno.land/x/oak_graphql/mod.ts";
const app = new Application();
const types = gql`
type Dino {
name: String
image: String
}
@danba340
danba340 / ternary.js
Last active October 30, 2020 17:03
JS Ternary operator use cases
// conditional ? expression1 : expression2
// Variable assignments
const num = 20
const numDescription = num > 9 ? "10 or bigger" : "less than 10";
console.log("num is " + numDescription)
// Returning values
function getCost(isMember) {
return isMember ? '$1.00' : '$2.00';
@danba340
danba340 / index.js
Created November 14, 2020 09:22
Codingame Fall Challenge 2020 Boilerplate
console.error('Debug messages...');
function canBrew(inventory, order) {
const canBrew = true
for(const [index, delta] of order.deltas.entries()) {
if(delta > inventory[index]){
canBrew = false
}
}
return canBrew
}
module['exports'] = function myHook (hook) {
var request = require('request');
request.get(
"http://someurl.com",
function(err, res){
var index = res.body.indexOf('off">');
var time = parseInt(res.body.substring(index + 5, index + 8));
const numbers = [1, 2, 3];
const sum = numbers.reduce((acc, number) => {
console.log(acc, number);
return acc + number;
}, 0);
console.log(sum);
const multiplication = numbers.reduce((acc, number) => {
console.log(acc, number);
return acc + number;
@danba340
danba340 / index.js
Last active January 29, 2023 08:14
Socket.io server on Heroku
const app = require('express')();
// Heroku header fixes
app.use(function (req, res, next) {
res.setHeader(
'Access-Control-Allow-Origin',
'http://' + req.headers.host + ':8100',
);
res.setHeader(
'Access-Control-Allow-Methods',
@danba340
danba340 / lifx.yaml
Last active September 27, 2021 12:09
LIFX Home assistant
lifx:
light:
server: 192.168.1.106
broadcast: 192.168.1.255
@danba340
danba340 / value-cards.json
Last active December 6, 2021 15:20
values
{
"buckets": [
"Not important to Me",
"Somewhat important to Me",
"Important to Me",
"Very important to Me",
"Most important to Me"
],
"cards": [
{