This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Simple script I put together showing mypy in action | |
# standard type annotations - we can give arguments a type and expect a return type | |
def add(x: int, y: int) -> int: | |
return x + y | |
print(add(1, 2)) | |
# we can let it pick within a list of types | |
from typing import Union |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!bin/bash | |
# Usage: | |
# bash jekyll_new.sh file_title | |
# Example: | |
# bash jekyll_new.sh daily-angst | |
# This script is for creating a new jeykll post under _posts/ | |
# Change as needed |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Paul Graham website beautifier | |
// @version 1 | |
// @grant none | |
// ==/UserScript== | |
// Based off http://bettermotherfuckingwebsite.com/ | |
var styles = ` | |
body { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This script goes into my Pictures/ folder and uploads it to ffsend. | |
# Requires: jq | |
set -e | |
cd ~/Pictures # configure to other source of pictures if you want | |
API_KEY="[YOUR KEY IT'S FREE TO GET]" | |
FILE_NAME=$(ls -rt | tail -n 1) | |
IMAGE=$( base64 "$FILE_NAME" ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'sinatra' | |
# Ex. http://localhost:4567/calc/add?x=1&y=2 | |
get '/calc/:operation' do | |
operations = { 'add' => ->(x, y) {x + y}, | |
'sub' => ->(x, y) {x - y}, | |
'mul' => ->(x, y) {x * y}, | |
'div' => ->(x, y) {x / y}, | |
'mod' => ->(x, y) {x % y} } | |
# Yes I could DRY that further but I don't trust user input |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'colorize' | |
require 'date' | |
def dash_seperator | |
'-' * 50 | |
end | |
def get_date | |
Date.today.to_s | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Download all RHTML links | |
// @version 1 | |
// @grant none | |
// ==/UserScript== | |
// @for any page with annoying .rhtml links | |
const all_links = Array.from(document.getElementsByTagName('a')); | |
const rhtml_links = all_links.filter( link => link.href.endsWith("rhtml") ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'pry' | |
require 'rqrcode' | |
qrcode = RQRCode::QRCode.new('https://cs125.cs.illinois.edu') | |
png = qrcode.as_png( | |
bit_depth: 1, | |
border_modules: 4, | |
color_mode: ChunkyPNG::COLOR_GRAYSCALE, | |
color: 'black', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun main() { | |
// normal function | |
repeat(3) { print("Yay $it ") } | |
// => Yay 0 Yay 1 Yay 2 | |
2.times { print("Looop ") } | |
// => Looop Looop | |
10.times { print("$it ") } | |
// => 0 1 2 3 4 5 6 7 8 9 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun main() { | |
// Both are the same | |
val array1: Array<Int> = arrayOf(0, 1, 4, 9, 16) | |
val list1: List<Int> = listOf(0, 1, 4, 9, 16) | |
val map1: Map<Int, Int> = mapOf(0 to 0, 1 to 1, 2 to 4, 3 to 9, 4 to 16) | |
val array2: Array<Int> = Array(5) { it*it } | |
val list2: List<Int> = List(5) {it*it} | |
val map2: Map<Int, Int> = (Array(5) {it}).associate {it to it*it} | |
} |
NewerOlder