Skip to content

Instantly share code, notes, and snippets.

View peterwillcn's full-sized avatar
📡
011010001000100010101010101

open source peterwillcn

📡
011010001000100010101010101
View GitHub Profile
@peterwillcn
peterwillcn / self_signed_cert.rb
Created January 5, 2016 08:37 — forked from nickyp/self_signed_cert.rb
create a self-signed certificate using ruby-openssl
We couldn’t find that file to show.
@peterwillcn
peterwillcn / gist:6e1c375ff93ca3f77619
Created March 22, 2016 15:12 — forked from bentonporter/gist:2891463
Ruby - HMAC-SHA256 example
require 'openssl'
require 'Base64'
key = "secret-key"
data = "some data to be signed"
Base64.encode64(OpenSSL::HMAC.digest(OpenSSL::Digest::Digest.new('sha256'), key, data)).strip()
connection = Faraday::Connection.new('http://example.com') do |builder|
builder.request :url_encoded # for POST/PUT params
builder.adapter :net_http
end
# same as above, short form:
connection = Faraday.new 'http://example.com'
# GET
connection.get '/posts'
@peterwillcn
peterwillcn / gist:188d73b56c9e863f5416752077cd1ac1
Created June 5, 2016 15:16
connecting-docker-containers-on-multiple-hosts
1 # From http://goldmann.pl/blog/2014/01/21/connecting-docker-containers-on-multiple-hosts/
2 # Edit this variable: the 'other' host.
3 REMOTE_IP=192.168.0.103
4
5 # Edit this variable: the bridge address on 'this' host.
6 BRIDGE_ADDRESS=172.17.43.1/24
7
8 # Name of the bridge (should match /etc/default/docker).
9 BRIDGE_NAME=docker0
10
@peterwillcn
peterwillcn / main.cpp
Created August 18, 2016 06:08 — forked from nikotan/main.cpp
face detection sample code for OpenCV
#include <opencv/cv.h>
#include <opencv/highgui.h>
#include <opencv/ml.h>
void doMosaic(IplImage* in, int x, int y,
int width, int height, int size);
int main (int argc, char **argv)
{
int i, c;
@peterwillcn
peterwillcn / build_nginx.sh
Created September 15, 2016 04:45 — forked from MattWilcox/build_nginx.sh
Fetch, build, and install the latest nginx with the latest OpenSSL for RaspberryPi
#!/usr/bin/env bash
# names of latest versions of each package
export VERSION_PCRE=pcre-8.38
export VERSION_OPENSSL=openssl-1.0.2d
export VERSION_NGINX=nginx-1.9.7
# URLs to the source directories
export SOURCE_OPENSSL=https://www.openssl.org/source/
export SOURCE_PCRE=ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/
@peterwillcn
peterwillcn / cnxsoft.md
Created November 10, 2016 13:31 — forked from stefanozanella/cnxsoft.md
Emulate a Raspberry Pi with Qemu+ KVM

Booting with CNXSoft image

Reference: http://www.cnx-software.com/2012/07/31/84-mb-minimal-raspbian-armhf-image-for-raspberry-pi/

curl -O https://dl.dropbox.com/u/45842273/2012-07-15-wheezy-raspian-minimal.img.7z

yum install p7zip
7za e 2012-07-15-wheezy-raspian-minimal.img.7z

qemu-system-arm -kernel kernel-qemu -cpu arm1176 -m 256 -M versatilepb -no-reboot -serial stdio -append "root=/dev/sda2 panic=1" -hda 2012-07-15-wheezy-raspian-minimal.img -net nic -net user -vnc :0 -net tap,ifname=vnet0,script=no,downscript=no
@peterwillcn
peterwillcn / hotp.rb
Created February 24, 2017 03:11 — forked from Martin91/hotp.rb
OTP algorithms in Ruby
require 'openssl'
def hotp(secret, counter, digits = 6)
hash = OpenSSL::HMAC.digest(OpenSSL::Digest.new('sha1'), secret, int_to_bytestring(counter))
"%0#{digits}i" % (truncate(hash) % 10**digits)
end
def truncate(string)
offset = string.bytes.last & 0xf
partial = string.bytes[offset..offset+3]
@peterwillcn
peterwillcn / hotp.rb
Created February 24, 2017 03:11 — forked from Martin91/hotp.rb
OTP algorithms in Ruby
require 'openssl'
def hotp(secret, counter, digits = 6)
hash = OpenSSL::HMAC.digest(OpenSSL::Digest.new('sha1'), secret, int_to_bytestring(counter))
"%0#{digits}i" % (truncate(hash) % 10**digits)
end
def truncate(string)
offset = string.bytes.last & 0xf
partial = string.bytes[offset..offset+3]
@peterwillcn
peterwillcn / upgrade.md
Created March 9, 2017 06:39 — forked from chrismccord/upgrade.md
Phoenix 1.2.x to 1.3.0 Upgrade Instructions

If you want a run-down of the 1.3 changes and the design decisions behidn those changes, check out the LonestarElixir Phoenix 1.3 keynote: https://www.youtube.com/watch?v=tMO28ar0lW8

To use the new phx.new project generator, you can install the archive with the following command:

$ mix archive.install https://github.com/phoenixframework/archives/raw/master/phx_new.ez

Bump your phoenix dep

Phoenix v1.3.0 is a backwards compatible release with v1.2.x. To upgrade your existing 1.2.x project, simply bump your phoenix dependency in mix.exs: