Skip to content

Instantly share code, notes, and snippets.

if (user.refrigeratorRunning){
try{
user.refrigerator.interrupt();
}
catch (InterruptedException e){
system.println("Catching...");
user.refrigerator.terminate();
}
}
@tristaaan
tristaaan / SortedInsert.cpp
Last active August 29, 2015 14:06
Create a sorted array by inserting the elements in a sorted manner.
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();
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 October 29, 2014 23:20
GET and POST in Android
//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 August 29, 2015 14:11
some array helpers.
Array.prototype.max = function(){
return this.reduce(function(prev, current){
if (current > prev){
prev = current;
}
return prev;
}, 0);
}
Array.prototype.min = function(){
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
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) &&
//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 November 18, 2016 06:37
Duolingo word scraper
// 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;
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: