Skip to content

Instantly share code, notes, and snippets.

View rallat's full-sized avatar
🏠
Working from home

Israel Ferrer Camacho rallat

🏠
Working from home
View GitHub Profile
@evansolomon
evansolomon / gist:945513
Created April 28, 2011 00:00
French Laundry Alerts
<?php
//number of people in the reservation
$people = 2;
//time, just the hour, pm
$time = 7;
$url = 'http://www.opentable.com/nextavailabletable.aspx?hpu=1025002033&shpu=1&rid=1180&m=4&d=8/13/2010+'.$time.':00:00+PM&p='.$people;
$data = file_get_contents($url);
$regex = '/\[\'\d{1,2}\/\d{1,2}\/\d{4} \d{1,2}\:\d{2}\:\d{2} PM/';
@romannurik
romannurik / button_bar_layout.xml
Created April 10, 2012 04:24
How to make a proper button bar on ICS
<!--
A button bar is a set of buttons at the bottom of an activity.
An example is an AlertDialog with OK/Cancel buttons.
Note that something similar can be accomplished using a
split action bar and text-only action buttons, but this is an
alternate presentation that's often preferred.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
@Goles
Goles / CountryCodes.json
Created July 29, 2012 05:37
Country and Dial or Phone codes in JSON format
[{"name":"Israel","dial_code":"+972","code":"IL"},{"name":"Afghanistan","dial_code":"+93","code":"AF"},{"name":"Albania","dial_code":"+355","code":"AL"},{"name":"Algeria","dial_code":"+213","code":"DZ"},{"name":"AmericanSamoa","dial_code":"+1 684","code":"AS"},{"name":"Andorra","dial_code":"+376","code":"AD"},{"name":"Angola","dial_code":"+244","code":"AO"},{"name":"Anguilla","dial_code":"+1 264","code":"AI"},{"name":"Antigua and Barbuda","dial_code":"+1268","code":"AG"},{"name":"Argentina","dial_code":"+54","code":"AR"},{"name":"Armenia","dial_code":"+374","code":"AM"},{"name":"Aruba","dial_code":"+297","code":"AW"},{"name":"Australia","dial_code":"+61","code":"AU"},{"name":"Austria","dial_code":"+43","code":"AT"},{"name":"Azerbaijan","dial_code":"+994","code":"AZ"},{"name":"Bahamas","dial_code":"+1 242","code":"BS"},{"name":"Bahrain","dial_code":"+973","code":"BH"},{"name":"Bangladesh","dial_code":"+880","code":"BD"},{"name":"Barbados","dial_code":"+1 246","code":"BB"},{"name":"Belarus","dial_code":"+375","
@zac-xin
zac-xin / AddBinary.java
Created December 26, 2012 16:58
Given two binary strings, return their sum (also a binary string). For example, a = "11" b = "1" Return "100".
public class Solution {
public String addBinary(String a, String b) {
// Start typing your Java solution below
// DO NOT write main() function
int la = a.length();
int lb = b.length();
int max = Math.max(la, lb);
StringBuilder sum = new StringBuilder("");
@kvnsmth
kvnsmth / example-subtree-usage.md
Last active March 5, 2023 21:58
A real world usage for git subtrees.

Let's say you have an iOS project, and you want to use some external library, like AFNetworking. How do you integrate it?

With submodules

Add the project to your repo:

git submodule add [email protected]:AFNetworking/AFNetworking.git Vendor/AFNetworking

or something to that effect.

@patrickcousins
patrickcousins / VerticalSmoothScrollView.java
Last active September 21, 2016 12:20
VerticalSmoothScrollView from http://stackoverflow.com/questions/5193678/android-horizontalscrollview-smoothscroll-animation-time/13639106 Added vertical computation. NOTE: to use with API 8 or lower you need to find a compat Scroller, ViewPagerIndicator is a good source to look for a compat Scroller.
public class VerticalSmoothScrollView extends ScrollView
{
private OverScroller myScroller; //TODO implement our own scroller, Scroller and OverScroller can usually be swapped
public VerticalSmoothScrollView( Context context, AttributeSet attrs, int defStyle )
{
super( context, attrs, defStyle );
init();
}
@JakeWharton
JakeWharton / dex.sh
Last active March 25, 2024 13:54
`classes.dex` method count helpers. Requires smali/baksmali from https://code.google.com/p/smali/ and dexdump from the build-tools in the Android SDK be on your PATH.
function dex-method-count() {
cat $1 | head -c 92 | tail -c 4 | hexdump -e '1/4 "%d\n"'
}
function dex-method-count-by-package() {
dir=$(mktemp -d -t dex)
baksmali $1 -o $dir
for pkg in `find $dir/* -type d`; do
smali $pkg -o $pkg/classes.dex
count=$(dex-method-count $pkg/classes.dex)
name=$(echo ${pkg:(${#dir} + 1)} | tr '/' '.')
package com.android.dex;
import java.io.File;
import java.io.IOException;
import java.util.Map;
import java.util.TreeMap;
import java.util.concurrent.atomic.AtomicInteger;
public class Summary {
public static void main(String[] args) throws IOException {
@nicktoumpelis
nicktoumpelis / repo-rinse.sh
Created April 23, 2014 13:00
Cleans and resets a git repo and its submodules
git clean -xfd
git submodule foreach --recursive git clean -xfd
git reset --hard
git submodule foreach --recursive git reset --hard
git submodule update --init --recursive
@grantland
grantland / post.md
Last active February 9, 2023 05:09
RecyclerView item onClick

RecyclerView item onClick

RecyclerView does not have an OnItemClickListener like it's predecessor, ListView. However, detecting item clicks is pretty simple.

Set an OnClickListener in your ViewHolder creation:

private class MyAdapter extends RecyclerView.Adapter<MyAdapter.ViewHolder>  {

    public static class ViewHolder extends RecyclerView.ViewHolder