Skip to content

Instantly share code, notes, and snippets.

View nesquena's full-sized avatar

Nathan Esquenazi nesquena

View GitHub Profile
@nesquena
nesquena / MainThreadCallback.java
Last active June 6, 2018 08:16 — forked from petitviolet/MainThreadCallback.java
OkHttp Callback on Main Thread.
public abstract class MainThreadCallback implements Callback {
private static final String TAG = MainThreadCallback.class.getSimpleName();
abstract public void onFail(final Exception error);
abstract public void onSuccess(final String responseBody);
@Override
public void onFailure(final Request request, final IOException e) {
@nesquena
nesquena / Contact.java
Last active January 15, 2023 13:03 — forked from rogerhu/Contact.java
Endless Scrolling with RecyclerVIew
package codepath.com.recyclerviewfun;
import java.util.ArrayList;
import java.util.List;
public class Contact {
private String mName;
private boolean mOnline;
public Contact(String name, boolean online) {
@nesquena
nesquena / default.vcl
Created September 27, 2012 04:52 — forked from alanmackenzie/default.c
Add X-Request-Start header so we can track queue times in New Relic RPM beginning at Varnish. - Fixed for Varnish 3.0.2-1 on Ubuntu.
# For Varnish NewRelic Tracking
# https://gist.github.com/2820068
C{
#include <stddef.h>
#include <stdio.h>
#include <sys/time.h>
}C
sub vcl_recv {
@nesquena
nesquena / default.vcl
Created September 27, 2012 04:35 — forked from alanmackenzie/default.c
Add X-Request-Start header so we can track queue times in New Relic RPM beginning at Varnish. - Modified by me for varnish 2.X
#
# Add X-Request-Start header so we can track queue times in New Relic RPM beginning at Varnish.
# Taken from https://gist.github.com/494265 & modified to compile on OSX.
#
sub vcl_recv {
// NewRelic X-Request-Start tracking
C{
#include </etc/varnish/newrelic.h>
}C
@nesquena
nesquena / benchmark.rb
Created July 18, 2011 18:42 — forked from ernie/benchmark.rb
A benchmark of some enumerable methods
require 'benchmark'
haystack = (1..1_000_000).to_a
needles = 1.upto(100).map {|n| n * 10_000}
module EachDetector
def self.find(haystack, needle)
haystack.each do |v|
return true if v == needle
end
@nesquena
nesquena / counter_backfill_migration.rb
Created November 17, 2010 21:13 — forked from mpakes/counter_backfill_migration.rb
Populate a cached counter field via a single SQL query.
# Credit to Mike Perham for this gem of an idea
# http://www.mikeperham.com/2007/12/17/creating-a-counter_cache-column/
class RailsMigration < ActiveRecord::Migration
def self.up
add_column :media, :followers_count, :integer, :default => 0, :null => false
# Populate the media follower counter cache in one fell swoop.
sql = "update media, (select operable_id, count(*) as the_count from follow_operations "\
"group by operable_id) as follows set media.followers_count = follows.the_count "\
"where media.id = follows.operable_id;"
@nesquena
nesquena / example_file.yml
Created September 10, 2010 01:04 — forked from trshafer/example_file.yml
TermInit Script
# you can make as many tabs as you wish...
# tab names are actually arbitrary at this point too.
---
- tab1: cd ~/foo/bar
- tab2:
- mysql -u root
- use test;
- show tables;
- tab3: echo "hello world"
- tab4: cd ~/baz/ && svn up
project :test => :shoulda, :renderer => :haml, :stylesheet => :sass, :script => :jquery, :orm => :activerecord, :dev => true
#default routes
APP_INIT = <<-APP
get "/" do
"Hello World!"
end
get :about, :map => '/about_us' do
render :haml, "%p This is a sample blog created to demonstrate the power of Padrino!"
project :test => :shoulda, :renderer => :haml, :stylesheet => :sass, :script => :jquery, :orm => :activerecord, :dev => true
#default routes
APP_INIT = <<-APP
get "/" do
"Hello World!"
end
get :about, :map => '/about_us' do
render :haml, "%p This is a sample blog created to demonstrate the power of Padrino!"
$ padrino-gen project sample_blog -t shoulda -e haml -c sass -s jquery -d activerecord -b
create
create app/app.rb
create config/apps.rb
create config/boot.rb
create config.ru
create public/favicon.ico
create .gitignore
exist app
create app/controllers