Skip to content

Instantly share code, notes, and snippets.

@pixeldrew
pixeldrew / Math.js
Created August 31, 2011 21:21
Math extensions
// 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;
@pixeldrew
pixeldrew / gist:1855179
Created February 17, 2012 20:10
Using require.js with node.js, express and redis store for session management
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 / faster-decimal-conversion.js
Last active December 15, 2015 19:29
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.
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
});
};
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 / index.js
Created September 26, 2017 12:43
FARC themed platform components
import { Component } from 'react';
class BlahComponent extends Component {
constructor(props) {
super(props);
}
switchView = () => {
this.setState({ aBoolState: !(this.state.aBoolState)});
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.*;
/**
#!/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
@pixeldrew
pixeldrew / server.js
Created August 5, 2019 04:45
NextJS and ApolloServer playing nice
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);
@pixeldrew
pixeldrew / useForm.js
Created September 1, 2019 03:09
Simple Form Hook
function useForm(callback, defaultValues, schema) {
const [values, setValues] = useState({ ...defaultValues });
const [errors, setErrors] = useState([]);
const [validateOnChange, setValidateOnChange] = useState(false);
async function validate() {
if (schema) {
const errors = await catchErrors();
if (errors.length > 0) {
setErrors([...errors]);
ssh_authorized_keys:
- github:pixeldrew
k3os:
k3s_args:
- server
- "--no-deploy"
- traefik