Skip to content

Instantly share code, notes, and snippets.

Avatar
👨‍💻
beeping and booping

Nick Robson nickrobson

👨‍💻
beeping and booping
View GitHub Profile
@nickrobson
nickrobson / MyAwesomeBot.java
Last active Nov 12, 2018
An example of how the DatePicker extension for jTelegramBotAPI can be used.
View MyAwesomeBot.java
import com.jtelegram.api.TelegramBotRegistry;
import com.jtelegram.api.chat.id.ChatId;
import com.jtelegram.api.commands.filters.MentionFilter;
import com.jtelegram.api.commands.filters.TextFilter;
import com.jtelegram.api.menu.Menu;
import com.jtelegram.api.menu.MenuHandler;
import com.jtelegram.api.menu.viewer.RegularMenuViewer;
import com.jtelegram.api.requests.message.send.SendText;
import com.jtelegram.api.update.PollingUpdateProvider;
import com.jtelegram.api.util.TextBuilder;
@nickrobson
nickrobson / Permute.java
Last active Nov 1, 2016
Gets all permutations of a string.
View Permute.java
public class Permute {
public static void main(String[] args) {
for (String res : permute(args.length > 0 ? args[0] : "AABC")) {
System.out.println(res);
}
}
public String[] permute(String str) {
if (str.length() <= 1)
@nickrobson
nickrobson / sonos_get_queue.py
Created Oct 18, 2016
Gets your Sonos speaker's queue.
View sonos_get_queue.py
import json
import requests
import xml.etree.cElementTree as XML
SOAP_TEMPLATE = '<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body>{0}</s:Body></s:Envelope>'
GET_QUEUE_BODY_TEMPLATE = '<u:Browse xmlns:u="urn:schemas-upnp-org:service:ContentDirectory:1"><ObjectID>Q:0</ObjectID><BrowseFlag>BrowseDirectChildren</BrowseFlag><Filter>dc:title,res,dc:creator,upnp:artist,upnp:album,upnp:albumArtURI</Filter><StartingIndex>{0}</StartingIndex><RequestedCount>{1}</RequestedCount><SortCriteria></SortCriteria></u:Browse>'
def cmd(sonos_ip, endpoint, soap_action, body):
headers = {
View keybase.md

Keybase proof

I hereby claim:

  • I am nickrobson on github.
  • I am nickrobson (https://keybase.io/nickrobson) on keybase.
  • I have a public key whose fingerprint is 3569 207D 80BC 0CE5 34C0 606D 7387 E46A FFBD A4CE

To claim this, I am signing this object:

View MyCoolGameObject.java
package ass1;
public class MyCoolGameObject extends GameObject {
public MyCoolGameObject() {
super(GameObject.ROOT);
new PolygonalGameObject(this, new double[] {0, 0, 0, .5, .5, .5, .5, 0}, new double[] {1, 0, 0, .5}, null);
new LineGameObject(this, 0, 0, 1, 0, new double[] {0, 1, 0, .5});
new LineGameObject(this, 0, 0, 0, 1, new double[] {0, 1, 0, .5});
@nickrobson
nickrobson / euref.py
Last active Jun 25, 2016
Brexit Results Scraper: Gets current voting status.
View euref.py
#!/usr/bin/env python
import re
import urllib2
import bs4
BASE_URL = 'http://www.bbc.co.uk/news/politics/eu_referendum/results/local/'
VOTES = re.compile(r'[0-9]+(?:,[0-9]+)*')
def get_urls():
@nickrobson
nickrobson / euref.py
Created Jun 24, 2016
EU Referendum Scraper:
View euref.py
#!/usr/bin/env python
import re
import urllib2
import bs4
BASE_URL = 'http://www.bbc.co.uk/news/politics/eu_referendum/results/local/'
VOTES = re.compile(r'[0-9]+(?:,[0-9]+)*')
def get_urls():
@nickrobson
nickrobson / temperature.pde
Last active Jun 2, 2016
Read a temperature from A0, print to LCD at 0x3F.
View temperature.pde
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#define I2C_ADDR 0x3F
#define TEMP_SENSOR A0
LiquidCrystal_I2C lcd(I2C_ADDR, 20, 4);
void setup() {
@nickrobson
nickrobson / strawpoll.py
Last active May 20, 2016
Automatic Strawpoll voter
View strawpoll.py
import sys
import time
import urllib
import urllib2
import bs4
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64; rv:40.0) Gecko/20100101 Firefox/40.0'}
def scrape(id):
req = urllib2.Request('http://www.strawpoll.me/%s' % id, headers=headers)
@nickrobson
nickrobson / permutations.rb
Last active Jan 29, 2016
Gets all permutations of a given number.
View permutations.rb
def number_shuffle(number)
dig = number.to_s.split ''
if dig.length == 1
return dig
end
out = []
(0...dig.length).each do |d|
nums = []
if d > 0
nums = nums << dig[0..d-1]