Skip to content

Instantly share code, notes, and snippets.

Drew Foehn pixeldrew

Block or report user

Report or block pixeldrew

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@pixeldrew
pixeldrew / server.js
Created Aug 5, 2019
NextJS and ApolloServer playing nice
View server.js
const path = require("path");
const next = require("next");
const express = require("express");
const { createServer } = require("http");
const { ApolloServer } = require("apollo-server-express");
const helmet = require("helmet");
const { PORT = 3000, NODE_ENV = "dev" } = process.env;
const port = parseInt(PORT, 10);
View addvpnuser.sh
#!/usr/bin/env bash
# OpenVPN configuration Directory
OPENVPN_CFG_DIR=/usr/local/etc/openvpn
# Directory where EasyRSA outputs the client keys and certificates
KEY_DIR=/usr/local/etc/openvpn/certs
# Where this script should create the OpenVPN client config files
OUTPUT_DIR=/usr/local/etc/openvpn/client-config
View PokerHandEvaluatorImpl.java
package com.interview.poker.solution;
import com.interview.poker.PokerHand;
import com.interview.poker.PokerHandEvaluator;
import com.interview.poker.card.Card;
import com.interview.poker.card.Card.Rank;
import java.util.*;
/**
@pixeldrew
pixeldrew / index.js
Created Sep 26, 2017
FARC themed platform components
View index.js
import { Component } from 'react';
class BlahComponent extends Component {
constructor(props) {
super(props);
}
switchView = () => {
this.setState({ aBoolState: !(this.state.aBoolState)});
View RootComponent.js
import React from 'React';
import {connect} from 'react-redux';
import {populateStore} from 'actions'; // simple action
// (state, props) => ({})
// state is the redux store
// props is provided to the HigherOrderComponent on line 16 of loadDefaultState.js
const mapStateToProps = (state, {initialData}}) => ({
populateStore,
initialData,
@pixeldrew
pixeldrew / faster-decimal-conversion.js
Last active Dec 15, 2015
Converts a decimal array to a binary array, eg [12,13,5,4] == [0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0] f2 is almost 6x faster in v8.
View faster-decimal-conversion.js
var f1 = function (a) {
return a.map(function (n) {
// convert number to decimal reverse the order then left pad it to a byte
return String((n).toString(2).split('').reverse().join('') + Array(8 + 1).join("0")).substr(0, 8);
}).join('')
.split('')
.map(function (n) {
return +n; // convert each of the numbers to int
});
};
@pixeldrew
pixeldrew / gist:1855179
Created Feb 17, 2012
Using require.js with node.js, express and redis store for session management
View gist:1855179
var requirejs = require('requirejs');
requirejs.config({
nodeRequire: require
});
requirejs(['express', 'connect', 'connect-redis'], function(express, connect, ConnectRedis) {
var app = express.createServer();
var RedisStore = new ConnectRedis(express);
@pixeldrew
pixeldrew / Math.js
Created Aug 31, 2011
Math extensions
View Math.js
// http://www.ideashower.com/our_solutions/leastgreatest-common-mulitple-lcmgcm-in-php-and-javascript/
/* Greatest Common Divisor */
Math.gcd = function(a, b) {
return ( b == 0 ) ? (a):( Math.gcd(b, a % b) );
};
/* Lowest Common Divisor */
Math.lcd = function(a, b) {
return ( a / Math.gcd(a,b) ) * b;
You can’t perform that action at this time.