Skip to content

Instantly share code, notes, and snippets.

@ezekg
ezekg / eu_country_codes.rb
Created June 11, 2018 14:39 — forked from henrik/eu_country_codes.rb
EU (European Union) country codes, ISO 3166-1 alpha-2. (This Gist is from 2012. Please see comments for updates.)
# Note: VAT identification numbers for Greece use "EL", not "GR".
COUNTRY_CODES_EU = %w[
AT BE BG CY CZ DK EE FI FR DE GR HU IE IT
LV LT LU MT NL PL PT RO SK SI ES SE GB
]
@ezekg
ezekg / macapp.go
Created May 18, 2018 19:02 — forked from mholt/macapp.go
Distribute your Go program (or any single binary) as a native macOS application
// Package main is a sample macOS-app-bundling program to demonstrate how to
// automate the process described in this tutorial:
//
// https://medium.com/@mattholt/packaging-a-go-application-for-macos-f7084b00f6b5
//
// Bundling the .app is the first thing it does, and creating the DMG is the
// second. Making the DMG is optional, and is only done if you provide
// the template DMG file, which you have to create beforehand.
//
// Example use:
@ezekg
ezekg / _.sh
Last active March 23, 2018 02:04
Example of using Keygen's licensing and distribution APIs together to only load an app's main logic for licensed users. The example below uses Keygen's demo account and is fully functional. Download the HTML file and open it in a browser.
# Copy this snippet below and paste into a terminal to download the HTML file
# and open it in your default browser
tmp=$(mktemp /tmp/keygen-XXXXXX) && \
curl -o "$tmp" https://gist.githubusercontent.com/ezekg/0f87abd27e60be3ffeef02c7c2829319/raw/97b71eb58dcd85383a4c8fccb8ce38c887e0eacb/index.html && \
open "$tmp"
@ezekg
ezekg / generate.js
Last active September 18, 2020 10:14
How to generate an offline-capable license resource, as well as an example of how to validate the license both online and offline. Do note that anything outside of expiry validation cannot be done offline e.g. machine validation, scope requirements, etc. Shell script implementation: https://gist.github.com/ezekg/57d1508fc1557236fe5eb8803e0e47af.
const fetch = require('node-fetch')
const NodeRSA = require('node-rsa')
const crypto = require('crypto')
const now = new Date()
// The policy we want to use for generated licenses, as well as the
// user the license is for. Feel free to omit the user.
const POLICY_ID = '3bc8bc4c-78fd-4d8b-89dd-f4d2cda1d353'
const USER_ID = '4796e950-0dcf-4bab-9443-8b406889356f'
@ezekg
ezekg / example.sh
Last active September 18, 2020 10:16
Example of using pub/priv keys for license generation, so license's can be validated online and offline. Note: each step should be run separately. Requires the great https://stedolan.github.io/jq/ command line tool. Node implementation: https://gist.github.com/ezekg/f021009b4c419f2462f3706a4478f200.
# 1. Generate a public/private keypair
openssl genrsa -out priv.pem 512
openssl rsa -in priv.pem -out pub.pem -outform PEM -pubout
# 2. Verify public/private keys look OK
cat priv.pem pub.pem
# 3. Generate a key with an expiry in 1 year and sign with *private* key (server-side)
#
# Note: the expiry you choose should match your license's policy, so that online
@ezekg
ezekg / example.html
Last active January 8, 2024 23:18
Example of validating a node-locked license from an Electron app
<!DOCTYPE html>
<html>
<head>
<meta charset='UTF-8'>
<title>Node-locked License Validation Example</title>
</head>
<body>
<button type='button' id='validate-license'>
Validate License
</button>
@ezekg
ezekg / licensing.cs
Last active December 29, 2020 21:02
Dead-simple license key validation using Keygen (https://keygen.sh)
using RestSharp;
using System;
using System.Collections.Generic;
public class Example
{
// This is your Keygen account ID or slug.
//
// Available at: https://app.keygen.sh/settings
const string KEYGEN_ACCOUNT_ID = "YOUR_KEYGEN_ACCOUNT_ID";
@ezekg
ezekg / example.cs
Last active October 18, 2017 00:34
Using metadata to store Stripe and Keygen resource details to later use
// Set your Stripe API key. Remember to change this to your live secret key in production.
//
// NEVER USE YOUR SECRET KEY IN CLIENT-SIDE CODE.
//
// See your keys here: https://dashboard.stripe.com/account/apikeys
StripeConfiguration.SetApiKey("YOUR_STRIPE_SECRET_KEY");
using RestSharp;
using System;
using System.Collections.Generic;
@ezekg
ezekg / example.sh
Last active September 21, 2017 14:06
Import licenses from an existing system into Keygen (https://keygen.sh)
# Install the 'node-fetch' library
npm install node-fetch
# Run the script by providing the required environment vars
KEYGEN_PRODUCT_TOKEN='' KEYGEN_ACCOUNT_ID='' KEYGEN_POLICY_ID='' ./import.js
@ezekg
ezekg / keygen.cs
Last active February 3, 2018 13:03
Keygen user and license creation example in C# (https://keygen.sh)
using RestSharp;
using System;
using System.Collections.Generic;
using System.Text;
public class Example
{
// This is your account ID or slug.
//
// Available at: https://app.keygen.sh/settings