Skip to content

Instantly share code, notes, and snippets.

View Dessix's full-sized avatar
🏳️‍⚧️

Zoey Dessix

🏳️‍⚧️
  • Microsoft; Theseus Institute
  • Redmond, WA, U.S.
View GitHub Profile
@Dessix
Dessix / gist:3113799
Created July 14, 2012 22:57
Reduction of PHP/MySQL Boilerplate for DB interaction via PDO
//Before:
public static function getTeamUsers($Team){
if(!static::checkvar($Team,'id'))
{
return false;
}
$sql = static::conn();
$sel = $sql->prepare("SELECT TeamMembers.UserID AS User FROM TeamMembers WHERE TeamMembers.TeamID = ?");
@Dessix
Dessix / gist:3894838
Created October 15, 2012 19:47
Get Google via WinSock2
#include <iostream>
#include <stdio.h>
#include <winsock2.h>
#pragma comment(lib,"ws2_32.lib")
int main(int argc, char** argv)
{
WSADATA WsaDat;
WSAStartup(MAKEWORD(2,2),&WsaDat);
SOCKET Socket=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
Creep.prototype.findNearestStorage: function() {
var pref = undefined;
if (this.room.storage != undefined) {
pref = this.room.storage;
}
for (var link in this.room.memory.energy.linkSources) {
var l = Game.getObjectById(link);
if (l != null && this.pos.getRangeTo(pref) > this.pos.getRangeTo(l)) {
pref = l;
}
@Dessix
Dessix / LiteDB.Extensions.Upsert.cs
Created January 2, 2016 00:20
Basic Upsert substitute
using System;
using LiteDB;
namespace LiteDB.Extensions {
public static class LiteCollectionX {
/// <summary>
/// Upserts the specified value.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="collection">The collection within which to upsert the <paramref name="value"/>.</param>
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
namespace FlashFormatting {
public static class EnumerableX {
//"today is nice".Span<char>(x => x != ' ') => (['t','o','d','a','y'], [' ','i','s',' ','n','i','c','e'])
public static Tuple<T[], T[]> Span<T>(this IEnumerable<T> chain, Predicate<T> qualifier) {
@Dessix
Dessix / PossiblePeopleTowerSolution.py
Created October 5, 2016 04:47
Possible for the people tower teaser
from typing import *
class Athlete:
def __init__(self, mass: float, strength: float):
self.Mass = mass
self.Strength = strength
def __hash__(self):
return hash((self.Mass, self.Strength))
def __lt__(self, other):
return (self.Mass, self.Strength) < (other.Mass, other.Strength)
@Dessix
Dessix / MaxSummedSubarray.cpp
Created October 7, 2016 04:22
Max Summed Subarray Problem in O(N), C++
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <stdexcept>
#include <memory>
using namespace std;
typedef unsigned int uint;
@Dessix
Dessix / HeapSort.scala
Created November 1, 2016 01:57
Crazy attempt at heapsort in Scala- Also, Scala's generics are finicky when it comes to upper type bounds
import scala.annotation.tailrec
import scala.collection.mutable.ListBuffer
import scala.language.postfixOps
import scala.math._
import scala.math.Ordering._
import scala.math.Ordered._
//MIN HEAP
def makeMutable[T](in: Seq[T]): ListBuffer[T] = {
@Dessix
Dessix / GithubFlipComparison.user.js
Last active November 17, 2016 18:12
Github Script - Flip Comparison Direction - Install: https://git.io/vXQ4p
// ==UserScript==
// @name Github - Flip Comparison
// @namespace http://dessix.net/userscripts/github/flip
// @version 0.1
// @updateURL https://gist.github.com/Dessix/d1d4c4090f4348cf030ec61977952898/raw/GithubFlipComparison.user.js
// @description Flip github branches in comparison.
// @author Dessix
// @match *://github.com/*/*/compare/*...*
// @grant none
// @require https://code.jquery.com/jquery-3.1.1.slim.min.js
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.AbstractTypeExtended$2E$get_prop = exports.TypeModule = undefined;
var _Symbol2 = require("fable-core/umd/Symbol");
var _Symbol3 = _interopRequireDefault(_Symbol2);