Skip to content

Instantly share code, notes, and snippets.

View abyx's full-sized avatar

Aviv Ben-Yosef abyx

View GitHub Profile
@abyx
abyx / angular-error-handling.js
Last active February 4, 2022 19:19
AngularJS HTTP Error Handling Mechanism
var HEADER_NAME = 'MyApp-Handle-Errors-Generically';
var specificallyHandleInProgress = false;
angular.module('myApp').factory('RequestsErrorHandler', ['$q', function($q) {
return {
// --- The user's API for claiming responsiblity for requests ---
specificallyHandled: function(specificallyHandledBlock) {
specificallyHandleInProgress = true;
try {
return specificallyHandledBlock();
@abyx
abyx / RetrierTest.java
Created March 31, 2011 20:51
Simple JUnit rule to make tests retry
public class RetrierTest {
private static int count = 0;
@Rule public RetryRule rule = new RetryRule();
@Test
@Retry
public void failsFirst() throws Exception {
count++;
assertEquals(2, count);
@abyx
abyx / list_filter_collapse.js
Created June 9, 2011 20:09
java script trick to hide the "filter" in a django admin view
(function($){
ListFilterCollapsePrototype = {
bindToggle: function(){
var that = this;
this.$filterTitle.click(function(){
that.$filterContent.slideToggle();
that.$list.toggleClass('filtered');
});
},
init: function(filterEl) {
@abyx
abyx / OuterClassTest.java
Created August 11, 2011 16:22
Reusing context with JUnit Enclosed runner
@RunWith(Enclosed.class)
public class OuterClassTest {
@Mock protected Dependency dependency;
protected SUT subject;
@Before
public void setUp() {
subject = new SUT(dependency);
}
let URLCache = NSURLCache(memoryCapacity: 4 * 1024 * 1024, diskCapacity: 25 * 1024 * 1024, diskPath: nil)
NSURLCache.setSharedURLCache(URLCache)
@abyx
abyx / Board.lua
Created June 7, 2012 05:14
Game of Life in Codea | Video available here http://www.youtube.com/watch?v=G5yg64joL-8
Board = class()
CELL_SIZE = 30
function Board:init(size)
self.grid = {}
for i = 1, size do
self.grid[i] = {}
for j = 1, size do
self.grid[i][j] = false
public void betterTest() throws Exception {
// Do some setup
// ...
final Exchanger<Exception> exchanger = new Exchanger<Exception>();
new Thread() {
@Override
public void run() {
Exception thrown = null;
<target name="compile" depends="compile-grammar">
<javac srcdir="${src}" destdir="${build}">
<classpath refid="classpath.base"/>
</javac>
</target>
<target name="compile-grammar" depends="-check_grammar_needs_compile"
if="grammarBuildRequired">
<java classname="org.antlr.Tool" failonerror="true">
<arg value="${grammar-file}"/>
@abyx
abyx / evernote_exporter.applescript
Created October 1, 2015 07:17
Evernote exporter
#!/usr/bin/osascript
do shell script "open -a /Applications/Evernote.app"
delay 10 # Evernote is slooooooow
with timeout of (10 * 60) seconds
tell application "Evernote"
set allnotebooks to notebooks
repeat with anotebook in allnotebooks
set aname to name of anotebook