Skip to content

Instantly share code, notes, and snippets.

Tristan Wright tristaaan

Block or report user

Report or block tristaaan

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View prank.java
if (user.refrigeratorRunning){
try{
user.refrigerator.interrupt();
}
catch (InterruptedException e){
system.println("Catching...");
user.refrigerator.terminate();
}
}
@tristaaan
tristaaan / SortedInsert.cpp
Last active Aug 29, 2015
Create a sorted array by inserting the elements in a sorted manner.
View SortedInsert.cpp
void sortedInsert(vector<double> &v, double val){
if (v.size() == 0){
v.push_back(val);
return;
}
vector<double>::iterator start = v.begin();
vector<double>::iterator end = v.end();
while (true){
end -= 1;
vector<double>::iterator middle = v.begin();
View fullscreen.js
function toggleFullscreen(){
if (!document.fullscreenElement && // alternative standard method
!document.mozFullScreenElement &&
!document.webkitFullscreenElement &&
!document.msFullscreenElement ) { // current working methods
if (document.documentElement.requestFullscreen) {
document.documentElement.requestFullscreen();
} else if (document.documentElement.msRequestFullscreen) {
document.documentElement.msRequestFullscreen();
} else if (document.documentElement.mozRequestFullScreen) {
@tristaaan
tristaaan / simpleHTTP.java
Created Oct 29, 2014
GET and POST in Android
View simpleHTTP.java
//import stuff
public void sendPOST(final String url, final ArrayList<NameValuePair> params){
Thread t = new Thread(new Runnable(){
@Override
public void run(){
try {
HttpClient client = new DefaultHttpClient();
String postURL = url;
HttpPost post = new HttpPost(postURL);
@tristaaan
tristaaan / array-extensions.js
Last active Aug 29, 2015
some array helpers.
View array-extensions.js
Array.prototype.max = function(){
return this.reduce(function(prev, current){
if (current > prev){
prev = current;
}
return prev;
}, 0);
}
Array.prototype.min = function(){
View Array-Extensions.swift
extension Array{
func every(fn: (T)->Bool) -> Bool{
var out = true
for i in self {
out = out && fn(i);
}
return out
}
func some(fn: (T) -> Bool) -> Bool{
var out = false
View UIColorEquality.swift
func == (left:UIColor, right:UIColor) -> Bool{
let lref:CGColorRef = left.CGColor
let rref:CGColorRef = right.CGColor
let lComponents = CGColorGetComponents(lref)
let rComponents = CGColorGetComponents(rref)
if CGColorGetNumberOfComponents(lref) == CGColorGetNumberOfComponents(rref) {
return floor(lComponents[0]*255) == floor(rComponents[0]*255) &&
floor(lComponents[1]*255) == floor(rComponents[1]*255) &&
View file_save.jsx
//react 0.14.7
saveModel() {
this.downloadFile(JSON.stringify(this.props.data, null, ' '));
},
downloadFile(contents) {
var newFileContent = new Blob([contents], {type: 'application/octet-binary'}),
downloadURL = window.URL.createObjectURL(newFileContent),
downloadLink = document.getElementById('file-download-link');
@tristaaan
tristaaan / duo_scraper.js
Last active Nov 18, 2016
Duolingo word scraper
View duo_scraper.js
// found from http://pastebin.com/jnEViBPz
// simple run in console on duolingo homepage
var $words = $('<table><thead><tr><th>Language</th><th>Category</th><th>Word</th><th>Strength</th></thead><table>');
var ld=duo.user.attributes.language_data;
var count = 0;
var waiting = 0;
for(l in ld){
waiting = ld[l].skills.models.length;
ld[l].skills.models.forEach(function(e){
var t=e.attributes;
View generator_pitfall.py
def evil_gen():
a = [0, 0, 0, 0, 0]
while 1:
for i in range(10):
for j in range(5):
a[i] = [i+1]
yield (a)
def good_gen():
while 1:
You can’t perform that action at this time.