Skip to content

Instantly share code, notes, and snippets.

var server="wss://webminerpool.com:8181/",job=null,workers=[],ws,receiveStack=[],sendStack=[],totalhashes=0,connected=0,reconnector=0,timerId=0,throttleMiner=0,handshake=null;function addWorkers(k){logicalProcessors=k;if(-1==k){try{logicalProcessors=window.navigator.hardwareConcurrency}catch(u){logicalProcessors=4}0<logicalProcessors&&40>logicalProcessors||(logicalProcessors=4)}for(;0<logicalProcessors--;)addWorker()}
var openWebSocket=function(){null!=ws&&ws.close();ws=new WebSocket(server);ws.onmessage=on_servermsg;ws.onerror=function(k){2>connected&&(connected=2);job=null};ws.onclose=function(){2>connected&&(connected=2);job=null};ws.onopen=function(){ws.send(JSON.stringify(handshake));connected=1}};reconnector=function(){3!==connected&&(null==ws||0!==ws.readyState&&1!==ws.readyState)&&openWebSocket()};
function startMiningWithId(k,u,q){u=void 0===u?-1:u;q=void 0===q?"":q;stopMining();connected=0;handshake={identifier:"handshake",loginid:k,userid:q,version:2};addWorkers(u);reconnector();timerId=setInterval
@nisargshah100
nisargshah100 / assessment
Last active August 24, 2017 20:34
Progress Data Examples
// response to client
{
"data": {
"id": "407d80a8-2a82-484b-972f-4ef2744e26c1",
"type": "progress",
"attributes": {
"fields": {},
"data": {
"completed": false
querying deal_types (bit_field) in mysql:
-- avs
SELECT deal_types,
( deal_types & 1048576 ) AS foo,
deals.*
FROM deals
WHERE offer_starts_at > '2012-02-01'
AND ( deal_types & 1048576 ) <> 0
curl -X "POST" https://fileturn.net/api/conversions.json \
-d api_token=[YOUR API KEY] \
-d type=WordToPdf \
-d url=iiswc.org/iiswc2013/sample.doc
// failure notification
{
id: 110,
details: "file is too big",
parsed_time: null,
status: "failed",
time_taken: null,
file_id: 132
}
{
id: 8,
created_at: "2013-07-05T22:14:10Z",
credits: 400,
notification_url: "http://localhost:3000",
time_zone: "Eastern Time (US & Canada)",
max_file_size_in_bytes: 1048576
}
{
id: 131,
url: "http://www.iiswc.org/iiswc2013/sample.doc",
convert_to: "pdf",
created_at: "2013-07-05T22:19:33Z",
status: "processed",
download_url: "https://someurltodownloadat.com",
notifications: [{
id: 109,
details: null,
{
files: [{
id: 131,
url: "http://www.iiswc.org/iiswc2013/sample.doc",
convert_to: "pdf",
created_at: "2013-07-05T22:19:33Z",
status: "processed",
download_url: "https://someurltodownloadat.com",
notifications: [{
id: 109,
// 201 created
{
"id":616,
"url":"http://google.com",
"convert_to":"pdf",
"created_at":"2013-07-08T01:38:12Z",
"status":"queued",
"download_url":"",
"notifications":[]
def generate_unique_token
options = { :length => 8, :chars => ('a'..'z').to_a + ('A'..'Z').to_a + ('0'..'9').to_a }
Array.new(options[:length]) { options[:chars].to_a[rand(options[:chars].to_a.size)] }.join
end