Skip to content

Instantly share code, notes, and snippets.

@richardpeng
richardpeng / README.md
Last active July 9, 2023 23:05
Dynamic CUE

Example Usages

Enable feature1

go run ./fill.go "features=[\"feature1\"]" 

Output:

{
class Supercooling {
static def delta(Integer temperature, BigDecimal slope, BigDecimal intercept) {
return slope * temperature + intercept
}
static def coolingTime(ArrayList<Integer> morningForecast, coolingRequired, coolSlope, coolIntercept) {
def coolingAmount = 0
def time = 0
def hour = 0
while (coolingAmount < coolingRequired) {
@richardpeng
richardpeng / fido2_openssh.sh
Last active July 17, 2020 02:40
Yubikey FIDO2 OpenSSH #bash
#!/bin/bash
# MacOS: Install latest OpenSSH
brew install openssh
# Generate new keypair
ssh-keygen -t ecdsa-sk
# Your key pair will be in ~/.ssh/id_ecdsa_sk and can be used as normal ssh key so id_ecdsa_sk.pub can be copied to your servers authorized_keys file
@richardpeng
richardpeng / active_admin.rb
Last active December 13, 2018 20:05 — forked from francois-ferrandis/active_admin.rb
Customize the active admin layout
# config/initializers/active_admin.rb
# ...rest of the initializer here...
module AdminPageLayoutOverride
def build(*args)
# you can move the call to super at the end, if you wish
# to insert things at the begining of the page
super
@richardpeng
richardpeng / module_inheritance.rb
Created October 30, 2018 18:03
Inherit both class and instance methods from another module with a single include
module GraphQL
module PunditIntegration
module BaseIntegration
def self.included(child)
child.extend ClassMethods
end
module ClassMethods
def policy_class
@richardpeng
richardpeng / Button.jsx
Created January 19, 2017 16:08
React Stateless Functional Button Component
import React from 'react';
import classNames from 'classnames';
import filterKeys from './filterKeys';
import './button.less';
const Button = (props) => {
let elementProps = filterKeys( props, Button.propTypes );
return <button {...elementProps} className={classNames( {
button: true,
'button--primary': props.type == 'primary' || props.type == 'submit'
@richardpeng
richardpeng / gopro_photo.sh
Last active May 24, 2016 19:03
Takes a picture on a networked GoPro
GP_HOST=https://user:pass@live.richardpeng.com
OUTPUT_DIR=/home/richard/public_html/plants
VIDEO_FILE=$OUTPUT_DIR/video/video.mp4
# take picture
curl -s $GP_HOST/gp/gpControl/command/shutter?p=1
sleep 5
# download picture
IMAGE_FILE=`curl -s $GP_HOST/gp/gpMediaList | sed -r "s/.*(GOPR[0-9]+\.JPG).*/\1/"`
@richardpeng
richardpeng / ssl_puma.sh
Created April 8, 2016 19:10 — forked from tadast/ssl_puma.sh
localhost SSL with puma
# 1) Create your private key (any password will do, we remove it below)
$ cd ~/.ssh
$ openssl genrsa -des3 -out server.orig.key 2048
# 2) Remove the password
$ openssl rsa -in server.orig.key -out server.key
@richardpeng
richardpeng / cli.ini
Last active December 28, 2015 05:15 — forked from thisismitch/le-renew-webroot
Let's Encrypt Auto-Renewal using the Webroot Plugin (Nginx)
# This is an example of the kind of things you can do in a configuration file.
# All flags used by the client can be configured here. Run Let's Encrypt with
# "--help" to learn more about the available options.
# Use a 4096 bit RSA key instead of 2048
rsa-key-size = 4096
# Always use the staging/testing server
# server = https://acme-staging.api.letsencrypt.org/directory
class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
protected
def current_user
@current_user ||= session[:user_id] and User.find(session[:user_id]['$oid'])
end