Skip to content

Instantly share code, notes, and snippets.

View karptonite's full-sized avatar

Daniel Karp karptonite

View GitHub Profile
<?php
class PostsTest extends TestCase {
public function testShow()
{
$testpost = ['text' => 'Test post', 'id' => 1];
$this->instanceMock('PostRepositoryInterface')->shouldReceive('find')->with(1)->once()->andReturn($testpost);
}
}
@karptonite
karptonite / TestCase.php
Created February 17, 2013 21:15
Alternative facade mocking method
//this would go in the base TestCase class
public function mockFacade($facadeName)
{
$facadeClass = get_class(call_user_func([$facadeName, 'getFacadeRoot']));
$mock = m::mock($facadeClass);
call_user_func([$facadeName, 'swap'], $mock);
return $mock;
}
//it would be invoked like this:
@karptonite
karptonite / gist:5267877
Last active December 15, 2015 13:29
My setup for using rsync to work locally on a remote server
My setup has Cmd-S and Cmd-Shift-S remapped to run the following AFTER saving:
if [ $TM_RSYNC_SOURCE ]
then
rsync -e "ssh" -avz --exclude '.DS_Store' --exclude '.FBCLockFolder' --exclude 'templates_c/' --exclude 'css/compiled/' --exclude '*.git' --exclude '*.out' --exclude '*.mlog' --delete "$TM_RSYNC_SOURCE" "$TM_RSYNC_DEST"
fi
the variables are project-specific Textmate variables--I'm sure there must be a way to
do something similar with Sublime--I just haven't tried yet. For me, for example,
TM_RSYNC_DST is karp@ourdevsystem.com:/var/www/karp/
@karptonite
karptonite / gist:5268364
Created March 29, 2013 02:39
Transcript of a conversation about rsync and sublime text 2
DanielKarp: Hey--Sort of new to Sublime text. I'm trying to write a plugin to rsync my files to a remote server on save (I do the same thing in textmate). So far, not a lot of luck. Here is what I have so far: http://pastebin.com/Nv4QYG1N
[10:10pm] DanielKarp: any advice? am I going about this all wrong?
[10:11pm] DanielKarp: (this is a combination of what I used with textmate with some cut and paste from other people's plugins, mostly)
[10:19pm] aat joined the chat room.
[10:20pm] ggreer: if you're on linux, you can probably use inotify-tools to do that regardless what editor you're using
[10:20pm] ggreer: and if you're on OS X, I wrote an auto-rsync thing: https://github.com/ggreer/fsevents-tools
[10:20pm] ggreer: but going back to your plugin, it would be helpful if you linked to any error messages or exceptions you ran into
[10:26pm] aat left the chat room. (Quit: Computer has gone to sleep.)
[10:26pm] moo-_-: DanielKarp: http://pypi.python.org/pypi/watchdog
[10:27pm] ggreer: yeah, that too
@karptonite
karptonite / Rsync script
Created May 30, 2013 18:32
My textmate rsync script
if [ $TM_RSYNC_SOURCE ]
then
rsync -e "ssh" -avz --exclude '.DS_Store' --exclude '.FBCLockFolder' --exclude 'scaffold/cache' --exclude 'css/compiled/' --exclude '*.git' --exclude 'app/compiled/smarty/' --exclude '*.out' --exclude '*.mlog' --delete "$TM_RSYNC_SOURCE" "$TM_RSYNC_DEST"
fi
@karptonite
karptonite / cache_section_notes.php
Last active December 20, 2015 14:59
Suggested implentation for Laravel Cache Sections
<?php
//Intended use of Sections
//This is not functional code, but will give you and idea of the changes intended
//an ordered array of section names
$sections = array( 'people', 'authors' );
//to store
Cache::sections( $sections )->put('John', $john);
@karptonite
karptonite / gist:7093489
Created October 22, 2013 00:52
Use of Cache tags
<?php
//Intended use of Tags
//an ordered array of tag names
$tags = array( 'people', 'authors' );
//to store
Cache::tags( $tags )->put('John', $john);
//to access
@karptonite
karptonite / GeekCache_SimpleQuery.php
Last active December 27, 2015 04:39
A simplified version of our query caching system
<?php
//=================================================================================================
class GeekCache_SimpleQuery extends GeekCache_TrackedCache
{
//==============================================================================================
public function __construct( $query, $timelimit, $namespaces=array(), $filename = '' )
{
if ( !$filename )
$filename = 'query_' . md5( $query );
@karptonite
karptonite / Behavior observed
Created November 4, 2013 19:27
Restangular issue
Click a delete button. Get the confirm dialog box. Click yes.
Console logs "deleting [id]" and "done".
If I click delete again, or anything else, THEN the Restangular remove fires and sends the delete request.
@karptonite
karptonite / test.js
Created November 4, 2013 20:45
Angular requests in closure problem
$scope.delete = function( id ){
var deleteResource = function(){
$resource('api/geekcontest/contests/:id', {'id':id}).delete();
};
window.setTimeout( deleteResource, 5000 );
};