Skip to content

Instantly share code, notes, and snippets.

@wikjez
wikjez / polynomial.rb
Created May 13, 2019 00:08
Polynomial Manipulation in Ruby
class Polynomial
# maps e.g. {x: 1, y: 2} => 3 which corresponds to term 3 * x ** 1 * y ** 2
attr_reader :coefficients
def initialize(coefficients = {})
puts @coefficients.inspect
@coefficients = coefficients.reject do |_index, coefficient|
coefficient == 0
end
end
@wikjez
wikjez / gauss_elimination.rb
Created May 10, 2019 13:39 — forked from komasaru/gauss_elimination.rb
Ruby script to solve simultaneous equations with Gauss elimination method.
#! /usr/local/bin/ruby
#*********************************************
# 連立方程式の解法 ( ガウスの消去法 )
#*********************************************
#
class GaussElimination
def initialize
# 係数
@a = [
#[ 2, -3, 1, 5],
@wikjez
wikjez / signing-gpg-keys.md
Created April 17, 2019 20:23 — forked from F21/signing-gpg-keys.md
Signing someone's GPG key

This is a quick guide of the commands we use to sign someone's GPG key in a virtual key signing party.

Note: The steps cover only the technical aspects of signing someone's key. Before signing someone's key, you must verify their identity. This is usually done by showing government-issued ID and confirming the key's fingerprint

The commands will work for both GPG and GPG2.

I use Julian's key for the examples. His key id is 2AD3FAE3. You should substitute with the appropriate key id when running the commands.

Signing the key

  1. List the keys currently in your keyring: gpg --list-keys.
@wikjez
wikjez / self-signed-certificate-with-custom-ca.md
Created April 10, 2019 20:32 — forked from fntlnz/self-signed-certificate-with-custom-ca.md
Self Signed Certificate with Custom Root CA

Create Root CA (Done once)

Create Root Key

Attention: this is the key used to sign the certificate requests, anyone holding this can sign certificates on your behalf. So keep it in a safe place!

openssl genrsa -des3 -out rootCA.key 4096
@wikjez
wikjez / seeds.rb
Created May 19, 2016 00:26 — forked from averyvery/seeds.rb
Seeding images in Rails
# encoding: utf-8
environment_seed_file = File.join(Rails.root, 'db', 'seeds', "#{Rails.env}.rb")
def seed_image(file_name)
File.open(File.join(Rails.root, "/app/assets/images/seed/#{file_name}.jpg"))
end
products = [
{:name => 'foo', :description => 'lorem ipsum', :product_type => ProductType.find_by_name('Sandwiches')},
@wikjez
wikjez / bijective.rb
Created May 8, 2016 22:45 — forked from zumbojo/bijective.rb
Simple bijective function (base(n) encode/decode)
# Simple bijective function
# Basically encodes any integer into a base(n) string,
# where n is ALPHABET.length.
# Based on pseudocode from http://stackoverflow.com/questions/742013/how-to-code-a-url-shortener/742047#742047
ALPHABET =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".split(//)
# make your own alphabet using:
# (('a'..'z').to_a + ('A'..'Z').to_a + (0..9).to_a).shuffle.join
getFactors :: Integer -> [Integer]
getFactors n = filter (\x -> n `mod` x == 0) [2..n]
isPrime :: Integer -> Bool
isPrime n = n > 1 && (head . getFactors) n == n
occurs :: Integer -> [Integer] -> Integer
occurs _ [] = 0
occurs n (x:xs) = if n == x
then 1 + occurs n xs
@wikjez
wikjez / typing.md
Created January 29, 2016 10:20 — forked from chrisdone/typing.md
Typing Haskell in Haskell

Typing Haskell in Haskell

MARK P. JONES

Pacific Software Research Center

Department of Computer Science and Engineering

Oregon Graduate Institute of Science and Technology

/*
* robot.js
*
* You'll need three keys in order to unlock the
* Algorithm: the red key, the green key, and the
* blue key. Unfortunately, all three of them are
* behind human-proof barriers.
*
* The plan is simple: reprogram the maintenance
* robots to grab the key and bring it through