Recently shared snippets by user "anonymous"

Created 1 month ago by anonymous
// ==UserScript==
// @name         Aliexpress_Billy_edit
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       You
// @match        https://trade.aliexpress.com/orderList.htm*
// @grant        unsafeWindow
// @grant        GM_xmlhttpRequest
// @grant    GM_setClipboard
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
// ==/UserScript==


// Declare an array called data to hold each row of data to store to the clipboard
var data = [];

// Loop through each of the order div wrappers
$(".order-item-wraper").each(async (ind, el)=>{
    // Declaring a variable to hold the GST rate of 10% set on all Aliexpress invoices
    let GSTrate = 0.1;

    // Store information about the order in a orderInfo object
    let orderInfo = {
        id: $(el).find(".order-info .first-row .info-body ").text().trim(),
        status: $(el).find(".order-status .f-left").text().trim(),
        orderPriceUS: $(el).find(".amount-num").text().trim(),
        orderDate: $(el).find(".order-info .second-row .info-body").text().trim(),
        sellerName: $(el).find(".store-info .first-row .info-body").text().trim(),
    };

    // Trim the $ and leading white space on orderPrice attribute
    orderInfo.orderPriceUS = orderInfo.orderPriceUS.slice(2,orderInfo.orderPriceUS.length);

    // Declare a variable sumProduct to calculate the sum product of the items in the order (needed to calculate the delivery charge)
    let sumProduct = 0;

    // Make an API call to get the US & AUD foreign exchange rates
    // First convert the date to iso format to use a query parameter in the api request
    // Set the later date for the api request to get the AUD forex
    let start_date = new Date(orderInfo.orderDate);
    // The API service does not provide forex data for the weekend, therefore if the start date is a Saturday, Sunday or a Monday set it back 3 days
    if (start_date.getDay() === 6 || start_date.getDay() === 1 || start_date.getDay() === 2) {
        start_date.setDate(start_date.getDate()-3);
    };
    // Convert the date to iso format
    let isoDate2 = start_date.toISOString().slice(0,10);
    // Set the previous date for the forex api request
    let prev = new Date(isoDate2);
    prev.setDate(prev.getDate()-1);
    let isoDate1 = prev.toISOString().slice(0,10);

    // Setup the parameters and end point for the api request
    let params = {
        date1: "start_at="+isoDate1,
        date2: "end_at="+isoDate2,
        base: "base=USD",
        currency: "symbols=AUD"
    }
    // Make the API request

    let endPoint = "https://api.exchangeratesapi.io/history?"+params.date1+"&"+params.date2+"&"+params.base+"&"+params.currency;

    let response = await fetch(endPoint);
    let json = await response.json();
    // console.log(endPoint);
    // console.log(json);
    // console.log(json.rates[isoDate1].AUD);
    // Pluck the AUD exchange rate off of the json response
    let audToUSD = json.rates[isoDate1].AUD;
    orderInfo["AUDtoUSForex"] = audToUSD;
    orderInfo["orderPriceAUD"] = orderInfo.orderPriceUS*audToUSD;



    // Loop through the order body div wrapper
    $(el).find(".order-body").each((i,e)=>{

        // Loop through each of the products in the order
        $(e).find(".product-sets").each((i,e)=>{
            // Clone the orderInfo object into an object called row
            let row = JSON.parse(JSON.stringify(orderInfo));
            // Add in the product title, price and quantity ordered to the row
            row["rowType"] = "product";
            row["productTitle"] = $(e).find(".product-title").text().trim();
            row["productPriceUS"] = parseFloat($(e).find(".product-amount span:first()").text().trim().slice(1).trim());
            row["productQuantity"] = $(e).find(".product-amount span:eq(1)").text().trim().slice(1);
            // Add in the GST rate and amount of GST per order
            row["GSTrate"] = GSTrate;
            row["GSTPerProductUS"] = row.GSTrate*row.productPriceUS;
            // Calculate and add in the AUD product price and GST
            row["productPriceAUD"] = row.productPriceUS*row.AUDtoUSForex;
            row["GSTPerProductAUD"] = row.GSTPerProductUS*row.AUDtoUSForex;
            // Push row in the dataTable
            data.push(row);
            // Increment sumProduct by the current row's total
            sumProduct += row.productPriceUS*row.productQuantity;
        });
    });

    // Calculate the delivery charge, combine it with the order information and add it as a row of data
    let deliveryRow = JSON.parse(JSON.stringify(orderInfo));
    deliveryRow["rowType"] = "delivery";
    deliveryRow["deliveryChargeUS"] = deliveryRow.orderPriceUS/(1+GSTrate) - sumProduct;
    deliveryRow["deliveryChargeGSTUS"] = deliveryRow.deliveryChargeUS * (1+GSTrate);
    deliveryRow["deliveryChargeAUD"] = deliveryRow.deliveryChargeUS * deliveryRow.AUDtoUSForex;
    deliveryRow["deliveryChargeGSTAUD"] = deliveryRow.deliveryChargeGSTUS * deliveryRow.AUDtoUSForex;
    console.log(`total order is ${deliveryRow.orderPriceUS}. Delivery divided by order pricce is ${deliveryRow.orderPriceUS/(1+GSTrate)} Sum product is ${sumProduct}. Delivery charge is ${deliveryRow.deliveryChargeUS}`);
    data.push(deliveryRow);

    // Calculate the total tax paid, combine it with the order information and add it as a row of data
    let taxRow = JSON.parse(JSON.stringify(orderInfo));
    taxRow["rowType"] = "tax";
    taxRow["taxTotalUS"] = taxRow.orderPriceUS - taxRow.orderPriceUS/(1+GSTrate);
    taxRow["taxTotalAUD"] = taxRow.taxTotalUS * taxRow.AUDtoUSForex;
    data.push(taxRow);
});


// Create a button to click at the top of the order list page which will load the product details to the clip board
$('#mybutton').one('click', function(){
    var r=$('<input/>').attr({
        type: "button",
        id: "field",
        value: 'LOAD CSV'
    });
    $("body").append(r);
});
$('<button/>', {
    text: "LOAD", //set text 1 to 10
    id: 'csvBtn',
    click: function () {
        $("#csvBtn").text("Loading...");
        var s = "";// "rowType\t id\t productTitle\t productPriceUS\t productQuantity\t AUDtoUSForex\t productPriceAUD\t GSTrate\t GSTPerProductUS\t  GSTPerProductAUD\t orderDate\t orderPriceUS\t orderPriceAUD\t sellerName\t  url \n";
        Promise.all(data).then(() => {
            data.forEach(e=> {
                if (e.rowType === "product") {
                    s += e.rowType + "\t";
                    s += e.id + "\t";
                    s += e.productTitle + "\t";
                    s += e.productPriceUS + "\t";
                    s += e.productQuantity + "\t";
                    s += e.AUDtoUSForex + "\t";
                    s += e.productPriceAUD + "\t";
                    s += e.GSTrate + "\t";
                    s += e.GSTPerProductUS + "\t";
                    s += e.GSTPerProductAUD + "\t";
                    s += e.orderDate + "\t";
                    s += e.orderPriceUS + "\t";
                    s += e.orderPriceAUD + "\t";
                    s += e.sellerName + "\t";
                    s += "https://trade.aliexpress.com/order_detail.htm?orderId=" + e.id + "\t";
                    s += "\n";
                } else if (e.rowType === "delivery") {
                    s += e.rowType + "\t";
                    s += e.id + "\t";
                    s += "Delivery charge on order (USD): " + "\t";
                    s += e.deliveryChargeUS + "\t";
                    s += "Delivery charge on order (AUD): " + "\t";
                    s += e.deliveryChargeAUD + "\t";
                    s += "GST on delivery charge (@ 10% rate, USD): " + "\t";
                    s += e.deliveryChargeGSTUS + "\t";
                    s += "GST on delivery charge (@ 10% rate, AUD): " + "\t";
                    s += e.deliveryChargeGSTAUD + "\t";
                    s += "\n";
                } else {
                    s += e.rowType + "\t";
                    s += e.id + "\t";
                    s += "Total GST paid on order (@ rate 10%, USD): " + "\t";
                    s += e.taxTotalUS + "\t";
                    s += "Total GST paid on order (@ rate 10%, AUD): " + "\t";
                    s += e.taxTotalAUD + "\t";
                    s += "\n";
                }
            });
            GM_setClipboard (s);
            $("#csvBtn").text("Loaded to clipboard");
        });
    }

}).appendTo("#appeal-alert");


function test(data){ return data;}
Created 1 year ago by anonymous
grep -rnw '/path/to/somewhere/' -e 'pattern'
-r or -R is recursive,
-n is line number, and
-w stands for match the whole word.
-l (lower-case L) can be added to just give the file name of matching files.
Created 1 year ago by anonymous
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import SplitSlider from './SplitSlider';
import registerServiceWorker from './registerServiceWorker';

ReactDOM.render(<SplitSlider
    BottomLayerTitle={'Captain America'}
    BottomLayerText={'Colored by Ruben J DelValle'}
    BottomLayerSrc={'http://www.rededits.com/projects/images/rjd_art/capamerica_colored_rjd.jpg'}
    TopLayerTitle={'B/W Captain America'}
    TopLayerText={'Inked by Ruben J DelValle'}
    TopLayerSrc={'http://www.rededits.com/projects/images/rjd_art/capamerica_inked_rjd.jpg'}
    handleColor={'orange'}
    handleRotation={33} />, document.getElementById('root'));
registerServiceWorker();
Created 1 year ago by anonymous
import math
E=3
T=40**E
D=10**E

def nu():
	for c in range(-T,T):
		yield c/D

def fu(n):
	r=n**n
	if isinstance(r,float):return r
	else:return ""

def va():
	for n in nu():
		yield fu(n)

def vb():
	for n in nu():
		yield fu(n+1/D)

def d(n):return int(n*D)

def inv(n):
	for a,b,r in zip(va(),vb(),nu()):
		if a=="" or b=="":continue
		if (d(a)<=d(n)<=d(b))or(d(b)<=d(n)<=d(a)):yield d(r)/D

while True:
	i=float(input())
	s=""
	for r in inv(i):
		if fu(r)==i:s+="="
		s+=str(r)
		s+="\n"
	print(s)
Created 1 year ago by anonymous
LocalDateTime time = LocalDateTime.now();
				LocalDateTime nextHour = time.plus(1l, ChronoUnit.HOURS).truncatedTo(ChronoUnit.HOURS)
				                                .plusMinutes(60 * (time.getMinute() / 60));
				long minutes = Duration.between(LocalDateTime.now(), nextHour).toMinutes();