Skip to content

Instantly share code, notes, and snippets.

View karptonite's full-sized avatar

Daniel Karp karptonite

View GitHub Profile
@karptonite
karptonite / NestingTest.php
Last active August 29, 2015 13:56
Example of loop in Mockery FormatObjects
<?php
class NestingTest extends PHPUnit_Framework_TestCase
{
public function testMockedDepenency()
{
$mock = Mockery::mock( 'Dependency' );
$mock->shouldReceive( 'doBar' )->with( 'foo' )->once();
$class = new ClassWithGetter( $mock );
$class->getFoo();
@karptonite
karptonite / mapToFields.php
Last active January 4, 2016 16:49
mapping an array to one of its fields
/**
* @param array $items
* @param string $keyname
* Takes an associative array with elements that include a with the key 'keyname'. Returns an array of just the field.
*/
public function mapToField( $items, $keyname )
{
if( !$items )
return array();
$processfunc = function( $item ) use( $keyname )
@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 );
};
@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 / 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 / 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 / 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 / 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 / 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 / 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 [email protected]:/var/www/karp/