Skip to content

Instantly share code, notes, and snippets.

View elyezer's full-sized avatar

Elyézer Rezende elyezer

View GitHub Profile
@elyezer
elyezer / gist:1505833
Created December 21, 2011 12:20
Find a contact name from phone number in Android
Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(phoneNumber));
String[] projection = {PhoneLookup.DISPLAY_NAME};
Cursor c = contentResolver.query(uri, projection, null, null, null);
if (c.moveToFirst()) {
name = c.getString(c.getColumnIndex(PhoneLookup.DISPLAY_NAME));
}
@elyezer
elyezer / gist:1511455
Created December 22, 2011 19:09
Updating a preference value without reloading PreferenceActivity
// Get the preference
EditTextPreference textPreference = (EditTextPreference) super.findPreference("text_preference_key");
// Change its value
textPreference.setText("Default Value");
@elyezer
elyezer / gist:3885790
Created October 13, 2012 19:07
LoginRequiredMixin
from django.contrib.auth.decorators import login_required
from django.utils.decorators import method_decorator
from django.views.generic.base import View
class LoginRequiredMixin(View):
@method_decorator(login_required)
def dispatch(self, *args, **kwargs):
return super(LoginRequiredMixin, self).dispatch(*args, **kwargs)
@elyezer
elyezer / navigation.py
Last active October 12, 2015 16:58
Django template tag to add active class in navigation links
{% load navigation %}
<!-- Specific path, only when visiting /accounts/ -->
<li class="{% active request "^/accounts/$" %}"><a href="/accounts/">Accounts</a></li>
<!-- Glob path, when visiting /blog/* example /blog/, /blog/post1/, /blog/post2/, /blog/post2/subitem/, ... -->
<li class="{% active request "^/blog/" %}"><a href="/blog/">Blog</a></li>
@elyezer
elyezer / validate_cnpj.php
Created August 23, 2013 13:53
Function that validates Brazilian CNPJ in PHP
<?
//------------------------------------------------------------------------------
// Description: Function that validates Brazilian CNPJ
// Author: Elyézer Mendes Rezende
// Inspired by:
// http://codigofonte.uol.com.br/codigos/validar-numero-do-cnpj
// https://github.com/django/django-localflavor/blob/master/localflavor/br/forms.py
//------------------------------------------------------------------------------
function validate_cnpj($cnpj) {
@elyezer
elyezer / blink_led.html
Created August 29, 2013 14:23
Beagle Bone Black HTML version of blink LED example
@elyezer
elyezer / ring_buffer.sql
Last active May 16, 2024 03:38
How to create a ring buffer table in SQLite
-- Example table
CREATE TABLE ring_buffer (id INTEGER PRIMARY KEY AUTOINCREMENT, data TEXT);
-- Number 10 on where statement defines the ring buffer's size
CREATE TRIGGER delete_tail AFTER INSERT ON ring_buffer
BEGIN
DELETE FROM ring_buffer WHERE id%10=NEW.id%10 AND id!=NEW.id;
END;
@elyezer
elyezer / gist:6594539
Created September 17, 2013 13:48
How to install OpenVPN on BeagleBone Black
# Change the version 2.3.2 as needed
wget http://swupdate.openvpn.org/community/releases/openvpn-2.3.2.tar.gz
tar zxf openvpn-2.3.2.tar.gz
cd openvpn-2.3.2
./configure
make
make install
@elyezer
elyezer / mount-virtualbox-share.sh
Created September 25, 2013 18:43
Mount a VirtualBox shared folder on a guest linux system
#!/usr/bin/env bash
MOUNT_NAME="virtual-box-mount-name"
MOUNT_PATH="/path/to/mount/on/guest"
sudo mkdir -p $MOUNT_PATH
sudo mount -t vboxsf -o uid=`id -u $USER`,gid=`getent group $USER | cut -d: -f3`,rw $MOUNT_NAME $MOUNT_PATH
sudo chown `id -u $USER`:`getent group $USER | cut -d: -f3` $MOUNT_PATH
@elyezer
elyezer / compile.sh
Created October 22, 2013 11:56
Create and use a shared library using Python's ctypes module
# Compile a shared library
gcc -shared -o libmean.so.1 mean.c