Browse Source

initial commit

master
Victor Fors 2 years ago
commit
8f7afc28a2
11 changed files with 182 additions and 0 deletions
  1. +2
    -0
      N33R_status.sh
  2. +53
    -0
      battery.scm
  3. +3
    -0
      battery_monitor.sh
  4. +2
    -0
      browse_source.sh
  5. +4
    -0
      coding-terminal
  6. +20
    -0
      define.lisp
  7. +2
    -0
      disable_internet.sh
  8. +2
    -0
      float_xinput_device.sh
  9. +2
    -0
      spotify-open
  10. +37
    -0
      wikifortune
  11. +55
    -0
      wikipedia

+ 2
- 0
N33R_status.sh View File

@@ -0,0 +1,2 @@
#!/bin/bash
sudo nmap minecraft.youdieifyou.work -PN -n -sV -p minecraft

+ 53
- 0
battery.scm View File

@@ -0,0 +1,53 @@
;;; Battery monitoring daemon script.

(import shell)

(import srfi-1)

;; Constant values.

;; Battery level control interval, in seconds.

(define check-interval 5)

;; Path to the virtual file containing the battery percentage number.

(define capacity-path "/sys/class/power_supply/BAT1/capacity")

;; Association list of threshold levels and formatting functions.

(define thresholds
`((20 . ,(lambda (battery-level)
(string-append "Battery level low: " (number->string battery-level) "%.")))
(5 . ,(lambda (battery-level)
(string-append "Battery level critical: " (number->string battery-level) "%.")))))

;; Utility functions.

;; Get the battery level, return it as a number.

(define (get-battery-level)
(with-input-from-file capacity-path read))

;; Method to display a notification dialog.

(define (user-notify message)
(run ("notify-send '" ,message "'")))

;; Core daemon loop.

(define (monitor-battery previous-level)
(let ((current-level (get-battery-level)))
(let ((crossed-thresholds
(filter (lambda (n)
(and (>= n current-level)
(< n previous-level)))
(map car thresholds))))
(if (not (null? crossed-thresholds))
(user-notify ((cdr (assoc (last crossed-thresholds) thresholds)) current-level))))
(sleep check-interval)
(monitor-battery current-level)))

;; Entry point of the program.

(monitor-battery 100)

+ 3
- 0
battery_monitor.sh View File

@@ -0,0 +1,3 @@
#!/bin/sh
BATTERY_PATH="/sys/class/power_supply/BAT1"
watch -tn 1 "cat $BATTERY_PATH/status && cat $BATTERY_PATH/capacity"

+ 2
- 0
browse_source.sh View File

@@ -0,0 +1,2 @@
#!/bin/sh
highlight -O ansi $1 | less -R

+ 4
- 0
coding-terminal View File

@@ -0,0 +1,4 @@
#!/bin/sh
xrdb -merge ~/.Xresources.green
urxvt -fn xft:inconsolata-22 -letsp -1 -im none &
xrdb -merge ~/.Xresources

+ 20
- 0
define.lisp View File

@@ -0,0 +1,20 @@
(asdf:load-system :drakma)
(asdf:load-system :yason)

(defun wiktionary-query (search-string)
(let ((query-string (format nil "https://en.wikipedia.org/w/rest.php/v1/search/page?q=~A&limit=1" search-string)))
(let ((http-result (handler-case (drakma:http-request query-string)
(usocket:ns-host-not-found-error (c)
(princ "Host not found.")
nil))))
(let ((json (yason:parse (coerce (map 'list #'code-char http-result) 'string))))
(let ((results (gethash "pages" json)))
(if (null results)
(princ "No results found.")
(let ((page-query-string (format nil "https://en.wikipedia.org/api/rest_v1/page/summary/~A" (gethash "title" (car results)))))
(let ((page-result (handler-case (drakma:http-request page-query-string)
(usocket:ns-host-not-found-error (c)
(princ "Host not found when retreiving data.")
nil))))
(let ((json (yason:parse (map 'string #'code-char page-result))))
(princ (gethash "extract" json)))))))))))

+ 2
- 0
disable_internet.sh View File

@@ -0,0 +1,2 @@
#!/bin/sh
newgrp no-internet

+ 2
- 0
float_xinput_device.sh View File

@@ -0,0 +1,2 @@
#!/bin/sh
xinput --float `xinput | grep "$1" | grep -o 'id=[[:digit:]]\+' | cut -d'=' -f2`

+ 2
- 0
spotify-open View File

@@ -0,0 +1,2 @@
#!/bin/sh
qdbus org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.OpenUri $1

+ 37
- 0
wikifortune View File

@@ -0,0 +1,37 @@
#!/usr/bin/python3
import requests
import sys
import textwrap

def connection_error():
print("Could not contact wikipedia servers.")
sys.exit(1)

def get_random_page():
params = {
'action' : 'query',
'format' : 'json',
'list' : 'random',
'rnlimit' : 1,
'rnnamespace' : 0
}
try:
return requests.get('https://en.wikipedia.org/w/api.php', params).json()['query']['random'][0]
except ConnectionError:
connection_error()

def get_page_with_summary(title):
try:
return requests.get('https://en.wikipedia.org/api/rest_v1/page/summary/' + title).json()
except ConnectionError:
connection_error()

def main():
while True:
page = get_page_with_summary(get_random_page()['title'])
if page['type'] == 'standard':
break
print(page['title'] + ':\n\n' + textwrap.fill(page['extract'], width=80))

if __name__ == '__main__':
main()

+ 55
- 0
wikipedia View File

@@ -0,0 +1,55 @@
#!/usr/bin/python3
import requests
import sys
import textwrap

def connection_error():
print("Could not contact wikipedia servers.")
sys.exit(1)

def page_search(string):
params = {
'q' : string,
'limit' : 1
}
try:
return requests.get('https://en.wikipedia.org/w/rest.php/v1/search/page', params).json()['pages']
except ConnectionError:
connection_error()

def get_page_with_summary(title):
try:
return requests.get('https://en.wikipedia.org/api/rest_v1/page/summary/' + title).json()
except ConnectionError:
connection_error()

def get_page_links(title):
params = {
'action' : 'query',
'titles' : title,
'prop' : 'links',
'format' : 'json'
}
try:
return list(requests.get('https://en.wikipedia.org/w/api.php', params).json()['query']['pages'].values())[0]['links']
except ConnectionError:
connection_error()

def main():
if not sys.argv[1:]:
print("Usage: wikipedia <list of search terms>")
sys.exit(1)
else:
result = page_search(' '.join(sys.argv[1:]))
if result:
page = get_page_with_summary(result[0]['title'])
if page['type'] == 'disambiguation':
print('Ambiguous result, please clarify:\n ' + '\n '.join([link['title'] for link in get_page_links(page['title'])]))
else:
print(page['title'] + ':\n\n' + textwrap.fill(page['extract'], width=80))
else:
print('No result found.')
sys.exit(1)

if __name__ == '__main__':
main()

Loading…
Cancel
Save