Skip to content

Instantly share code, notes, and snippets.

View beepony's full-sized avatar
👻

beepony beepony

👻
View GitHub Profile
@beepony
beepony / base64-image-upload.js
Created July 4, 2017 09:44 — forked from madhums/base64-image-upload.js
save base64 encoded image
/*
* Taken from http://stackoverflow.com/questions/5867534/how-to-save-canvas-data-to-file/5971674#5971674
*/
var fs = require('fs');
// string generated by canvas.toDataURL()
var img = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0"
+ "NAAAAKElEQVQ4jWNgYGD4Twzu6FhFFGYYNXDUwGFpIAk2E4dHDRw1cDgaCAASFOffhEIO"
+ "3gAAAABJRU5ErkJggg==";
// strip off the data: url prefix to get just the base64-encoded bytes
@beepony
beepony / parse_json_file.js
Created May 5, 2017 07:03
使用 Node 解析 Json 格式的文件
var fs = require('fs');
var file = __dirname + '/config.json';
fs.readFile(file, 'utf8', function (err, data) {
if (err) {
console.log('Error: ' + err);
return;
}
data = JSON.parse(data);
@beepony
beepony / getReddit.js
Created April 26, 2017 09:22
nodejs GET request with custom headers
const request = require('request');
const options = {
url: 'https://www.reddit.com/r/funny.json',
method: 'GET',
headers: {
'Accept': 'application/json',
'Accept-Charset': 'utf-8',
'User-Agent': 'my-reddit-client'
}
@beepony
beepony / gist:d27b575785b4a289153e63e1fd9b2dbd
Last active March 29, 2017 06:40 — forked from kitek/gist:1579117
NodeJS create md5 hash from string
var data = "do shash'owania";
var crypto = require('crypto');
crypto.createHash('md5').update(data).digest("hex");
@beepony
beepony / pdf.rb
Created March 23, 2017 02:49
使用 Ruby 把 HTML 转成 PDF 输出
#! /usr/bin/ruby -w
# test html to pdf lib
require 'pdfkit'
# 从 URL 转换成 PDF
kit = PDFKit.new('https://techs.b0.upaiyun.com/article/%E9%98%BF%E9%87%8C%E4%BA%91%E5%AE%89%E5%85%A8%E7%BB%84%E5%92%8C%E4%BA%91%E7%9B%BE%E8%AE%BE%E7%BD%AE.html')
# 从本地 HTML 文件转换成 PDF
kit = PDFKit.new(File.new('./pdf.html'))
@beepony
beepony / Aircrack Commands
Created March 11, 2017 12:28 — forked from victorreyesh/Aircrack Commands
Cracking WPA2 / WEP Wifi / Aircrack 10 seconds guide. For Mac OSX
//Install Macports.
//Install aircrack-ng:
sudo port install aircrack-ng
//Install the latest Xcode, with the Command Line Tools.
//Create the following symlink:
sudo ln -s /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport /usr/sbin/airport
//Figure out which channel you need to sniff:
sudo airport -s
sudo airport en1 sniff [CHANNEL]
@beepony
beepony / ruby_regx_group.rb
Created February 21, 2017 05:31
ruby regx
#!/usr/bin/env ruby
string = "RyanOnRails: This is a test"
one, two, three = string.match(/(^.*)(:)(.*)/i).captures
p one #=> "RyanOnRails"
p two #=> ":"
p three #=> " This is a test"
# better one
@beepony
beepony / json_to_hash_eg.rb
Created January 9, 2017 07:21
convert json to hash in ruby
require 'json'
value = '{"val":"test","val1":"test1","val2":"test2"}'
puts JSON.parse(value) # => {"val"=>"test","val1"=>"test1","val2"=>"test2"}
@beepony
beepony / hmac_sha1_for_upyun.rb
Last active May 11, 2018 14:46
ruby HMAC SHA1 for UPYUN API
#!/usr/bin/ruby -w
# hexdigest 16 进制,digest 二进制
# HMAC SHA1 加密方法
require 'base64'
require 'digest'
require 'openssl'
def hamc_sha_for_upyun(key, data)
@beepony
beepony / hmac-sha1.rb
Created January 6, 2017 08:12 — forked from kovacshuni/hmac-sha1.rb
Ruby HMAC-SHA1 digest creation
require 'base64'
require 'cgi'
require 'openssl'
base = 'POST&https%3A%2F%2Fapi.twitter.com%2F1%2Fstatuses%2Fupdate.json&include_entities%3Dtrue%26oauth_consumer_key%3Dxvz1evFS4wEEPTGEFPHBog%26oauth_nonce%3DkYjzVBB8Y0ZFabxSWbWovY3uYSQ2pTgmZeNu2VS4cg%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1318622958%26oauth_token%3D370773112-GmHxMAgYyLbNEtIKZeRNFsMKPR9EyMZeS9weJAEb%26oauth_version%3D1.0%26status%3DHello%2520Ladies%2520%252B%2520Gentlemen%252C%2520a%2520signed%2520OAuth%2520request%2521'
key = 'kAcSOqF21Fu85e7zjz7ZN2U4ZRhfV3WpwPAoE3Z7kBw&LswwdoUaIvS8ltyTt5jkRh4J50vUPVVHtR2YPi5kE'
puts CGI.escape(Base64.encode64("#{OpenSSL::HMAC.digest('sha1', key, base)}\n"))