Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View D-32's full-sized avatar
:shipit:
Shipping stuff

Dylan Marriott D-32

:shipit:
Shipping stuff
View GitHub Profile
import requests
import json
import uuid
import time
from requests import Request, Session
# this is the initial call to get cookies and shit
s = Session()
r1 = s.get('https://challengethefuture.postfinance.ch/Contest/2')
totals = []
@D-32
D-32 / NSUserDefaults+UIColor.swift
Created January 7, 2017 19:26 — forked from aclissold/NSUserDefaults+UIColor.swift
Swift NSUserDefaults UIColor extension
extension UserDefaults {
func color(forKey defaultName: String) -> UIColor? {
var color: UIColor?
if let colorData = data(forKey: defaultName) {
color = NSKeyedUnarchiver.unarchiveObject(with: colorData) as? UIColor
}
return color
}
func set(_ value: UIColor?, forKey defaultName: String) {
@D-32
D-32 / sub.py
Created December 20, 2016 19:34
Notify when youtube subscriber count changes
import requests
import json
import time
import os
from datetime import datetime
stat = ""
while True:
r = requests.get("https://www.googleapis.com/youtube/v3/channels?part=statistics&id=$$$CHANNEL_ID$$$&key=$$$YOUR_API_KEY$$$")
j = json.loads(r.content)
@D-32
D-32 / gist:b765a8d8a6a952221236bc419844b0e4
Created June 6, 2016 08:43
Storing non "Object" classes in a Realm List
var textReco: [CGRect] {
get {
return _backingTextReco.map { CGRectFromString($0.stringValue) }
}
set {
_backingTextReco.removeAll()
_backingTextReco.appendContentsOf(newValue.map({ RealmString(value: [NSStringFromCGRect($0)]) }))
}
}
let _backingTextReco = List<RealmString>()
@D-32
D-32 / gist:217d89cf87c2a6615392
Created November 1, 2015 09:50
Correctly vertically center a text field
CGFloat topLetterPadding = self.nameLabel.font.ascender - self.nameLabel.font.capHeight;
NSLayoutConstraint *nameLabelCenterConstraint = [NSLayoutConstraint constraintWithItem:self.nameLabel
attribute:NSLayoutAttributeCenterY
relatedBy:NSLayoutRelationEqual
toItem:self
attribute:NSLayoutAttributeCenterY
multiplier:1
constant:roundf(-(topLetterPadding / 2))];
@D-32
D-32 / gist:a70005f59801d789479a
Created September 15, 2015 20:36
Level 5 Solution
_levelNr = 5;
delay = 100;
function exec() {
// new function -> getX(); and getY();
// use these to check that you don't leave the playing field
var check = 9;
for (var i = 0; i < 200; i++) {
@D-32
D-32 / search.js
Created July 20, 2015 20:09
Firebase search service
var Firebase = require("firebase");
var lunr = require("lunr");
var http = require('http');
var url = require('url');
var index = lunr(function () {
this.field('title', {boost: 10})
this.field('description')
this.ref('id')
})
@D-32
D-32 / ModalViewController
Last active August 29, 2015 14:21
Modal Window
static CGFloat kHeight = 480;
@implementation ModalViewController {
UIView *_bg;
UIView *_container;
}
- (instancetype)init {
if (self = [super init]) {
self.providesPresentationContextTransitionStyle = YES;
@D-32
D-32 / UIAlertController
Last active August 29, 2015 14:20
UIAlertController with text field check
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Title"
message:nil
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *cancelAlertAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {}];
_saveAlertAction = [UIAlertAction actionWithTitle:@"Save" style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
}];
_saveAlertAction.enabled = NO;
@D-32
D-32 / node_server.js
Last active November 6, 2015 10:37
Simple node server to debug stuff
http = require('http');
fs = require('fs');
url = require('url');
server = http.createServer( function(req, res) {
console.log(req.url)
if (req.method == 'POST') {
var body = '';
req.on('data', function (data) {
body += data;