Skip to content

Instantly share code, notes, and snippets.

View wlib's full-sized avatar
🔙
delete all code

Daniel Ethridge wlib

🔙
delete all code
View GitHub Profile
@wlib
wlib / parseQuery.js
Last active December 15, 2016 02:40
Parse a URL query i.e. https://example.com/page?queryKey=value&embeddedJson={"json":{"can":"be%20embedded","nested":true}} into an object using javascript. Parses both key=value pairs and nested JSON just fine.
// Without an argument, just parse the current page's URL, if an argument is supplied, parse that
function parseQuery(query = window.location.search.substring(1)) {
// Decode the URL-safe query string into a regular string e.g.("%20" => " ")
const decodedQuery = decodeURIComponent(query);
// Split that string at every "&" to get all the key=value pairs
const allpairs = decodedQuery.split("&");
// Declare an object to hold our output
const out = {};
// This regex matches what seems to look like valid JSON
const regex = /^[\[|\{](\s|.*|\w)*[\]|\}]$/g;
@wlib
wlib / .bashrc-apt-functions
Created December 31, 2016 00:46
Bash functions to quickly install programs with apt, from a repository and from any .deb file
# Add this to your ~/.bashrc file for quick installation of .deb files, you can then update programs with `debinst URL`
inst() {
sudo apt install $1 --assume-yes
}
debinst() {
wget $1 -O /tmp/install.deb
sudo dpkg -i /tmp/install.deb
inst -f
@wlib
wlib / get_favicon.rb
Last active January 5, 2017 16:26
Get a website's favicon via duckduckgo
def get(path="/", domain="https://api.duckduckgo.com")
require 'open-uri'
endpoint = "#{domain}/#{path}"
body = open(endpoint).read
return body
end
def get_favicon(page)
favicon = get("/i/#{page}.ico")
require 'digest'
@wlib
wlib / summ
Last active February 10, 2017 06:46
Summarize a file with freesummarizer.com
#!/usr/bin/env ruby
# Summarize a long file
# Uses the wonderful freesummarizer.com API
# Implemented by Daniel Ethridge
require 'uri'
require 'net/http'
# Get the text to summarize
@wlib
wlib / e.rb
Last active February 14, 2017 00:22
Calculate E in Ruby
#!/usr/bin/env ruby
# Watch how E changes as n increases
# For good display, I set the cursor off
# To make your cursor appear again, try ``printf "\033[?25h"
def e(rounds)
print "\033[?25l"
for n in 1..rounds do
e = (1 + 1.0 / n) ** n
if n % 10 == 0
@wlib
wlib / githubCodeWindowEnlarger.js
Last active February 22, 2017 03:15
Make the gist or github online editor larger
javascript:(function(){const editor%3Ddocument.querySelector("div.commit-create > div.CodeMirror");editor.setAttribute("style"%2C"height%3A50%25");})();//
@wlib
wlib / githubOpenHTML.js
Created February 22, 2017 03:29
Open a gist or github code window as html in a new tab
javascript:(function(){const code%3Ddocument.querySelector("div.commit-create > textarea").value;const tab%3Dwindow.open();tab.document.write(code)})();//
@wlib
wlib / duolingoTanslateAPI.rb
Last active February 24, 2017 02:53
Duolingo translate API
# Duolingo's unofficial translation API
# Please comment or send me a message if you find more endpoint and/or info
require "open-uri"
require "json"
require "cgi"
def ask()
# Get languages
puts "* Use language codes, i.e. `en`, `de`, `ru` *"
@wlib
wlib / duolingoVocab.js
Last active February 24, 2017 14:55
Get all your duolingo vocab words, then import them to quizlet as a set
// You must run this on the website because of the
// authentication method and CORS
// We get the definitions here
function callback(defs) {
window.quizlet = "";
for (let word in defs) {
quizlet += (word + "\t" + defs[word].join(", ") + "\n");
}
console.log(quizlet);
pro = new Promise(function(resolve, reject) {
setTimeout(function() {
if (true) {
resolve("Yay");
}
else {
reject("Uh oh");
}
}, 1000);
});