Skip to content

Instantly share code, notes, and snippets.

View seagoj's full-sized avatar

Jeremy Seago seagoj

View GitHub Profile
@seagoj
seagoj / mario-modular.c
Last active August 26, 2015 20:32
cs50 mario solution
#include <stdio.h>
#include <cs50.h>
int getHeightFromUser()
{
int height;
do {
printf("height: ");
height = GetInt();
@seagoj
seagoj / test50
Created August 27, 2015 16:01
Test runner for the CS50 course
#!/bin/sh
ps=${PWD##*/}
style50 $1.c
clang -o $1 $1.c -lcs50 $2
check50 2014.fall.$ps.$1 $1.c
@seagoj
seagoj / 0_reuse_code.js
Created March 18, 2014 19:13
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@seagoj
seagoj / gist:10736442
Created April 15, 2014 14:19
Custom error handler
public static function error_handler($errno, $errstr, $errfile, $errline, $errcontext) {
global $errorLog;
if (is_array($errstr) || is_object($errstr)) {
$errstr = var_export($errstr, true);
}
$message = "$errno:$errfile:$errline:$errstr:".json_encode($errcontext);
if (isset($errorLog) && get_class($errorLog)==='Devtools\Log') {
$errorLog->write($message, false);
} else {
echo $message;
@seagoj
seagoj / msmq.php
Created June 3, 2014 19:57
PHP:MSMQ
<?php
define(MQ_SEND_ACCESS , 2);
define(MQ_DENY_NONE , 0);
$msgQueueInfo = new COM("MSMQ.MSMQQueueInfo") or die("can not create MSMQ Info object");
$msgQueueInfo->PathName = ".\TestQueue";
$msgQueue = new COM("MSMQ.MSMQQueue") or die("can not create MSMQ object");
$msgQueue=$msgQueueInfo->Open(MQ_SEND_ACCESS, MQ_DENY_NONE );
@seagoj
seagoj / gist:db02f7fdacabd3a22080
Created September 29, 2014 20:50
Vimscript Issue
function! TagbarGotoTag()
normal! "zyiw
call tagbar#OpenWindow('fcj')
:exe "/".@z.""
" Need to send a carriage return here to select the tag
:nohlsearch
endfunction
@seagoj
seagoj / gist:917d941c5f91138b42c7
Last active August 29, 2015 14:07
Interfaces and type hints
interface Entity {}
class UserEntity implements Entity {}
interface Repository
{
public function persist(Entity $entity);
}
class UserRepository implements Repository
{
function it_saves_values_to_repository(
Devtools\Model $model,
Repository\UserRepositoryAdapter $repository
) {
$repository
->getProperties()
->shouldBeCalled()
->willReturn(
[
'userId',
@seagoj
seagoj / gist:86c919f6d4c821557eaa
Created October 22, 2014 18:03
Discern between SELECT, INSERT & UPDATE
$stmt = $this->connection->prepare($queryString);
$executeResult = !is_null($params)
? $stmt->execute($params)
: $stmt->execute();
$data = $stmt->fetchAll($fetchType);
$isInsertStatement = empty($data)
&& $executeResult
&& ($lastInsertId = $this->connection->lastInsertId()) !== 0;
$isUpdateStatement = empty($data);
@seagoj
seagoj / Response.php
Created November 11, 2014 01:03
Autoloading
<?php namespace Devtools;
// /vendor/Devtools/Response.php
class Response
{
...
}