Skip to content

Instantly share code, notes, and snippets.

@Juddd
Created October 18, 2016 13:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Juddd/d78d66937e7116ee235b249f09d6c483 to your computer and use it in GitHub Desktop.
Save Juddd/d78d66937e7116ee235b249f09d6c483 to your computer and use it in GitHub Desktop.
You can use it in Mathematica.The function can convert everyting into a expression including Pictrue bed link.
ShareAny[expr_] :=
Module[{list, imageWidth, imageHeight, n},
list = ToCharacterCode[Compress[expr]];
{imageWidth,
imageHeight} = {If[(n = Ceiling[Sqrt[Length[list]/3]])*(n - 1) >
Length[list]/3, n - 1, n], n};
Print[Style[
The following expression to share is in your clipboard., 11,
Red]]; (CopyToClipboard@#; #) &[
Defer[Uncompress@*FromCharacterCode@*
Flatten@*(ImageData[#, "Byte"] &)@*Import][
ImportString[
URLFetch["https://sm.ms/api/upload", Method -> "POST",
"MultipartElements" -> {{"smfile\"; filename=\"tmp.png",
"image/png"} ->
ExportString[
Image[ArrayReshape[list, {imageWidth, imageHeight, 3}],
"Byte"], "PNG"]}], "RawJSON"]["data", "url"]]]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment