Skip to content

Instantly share code, notes, and snippets.

@pablophg
pablophg / prettyround.lua
Last active December 30, 2015 03:19
Function that rounds a number to 2 decimals and returns it as string.
function prettyround(number)
return string.format('%.2f', number)
end
@pablophg
pablophg / sandbox.lua
Created November 9, 2014 07:51
Lua sandbox
local user_script = loadstring('print("hello")')
local env = {print=print}
setfenv(user_script, env)
pcall(user_script)
-- By Saml1er, for research :P
Testaz = { }
function Testaz:new (o,a,b)
setmetatable(o, self)
self.__index = self
self.str = tostring (a + b)
return o
@pablophg
pablophg / class.lua
Created December 22, 2014 08:41
SimpleLuaClasses
-- check "http://lua-users.org/wiki/SimpleLuaClasses" for this file
-- class.lua
-- Compatible with Lua 5.1 (not 5.0).
function class(base, init)
local c = {} -- a new class instance
if not init and type(base) == 'function' then
init = base
base = nil
@pablophg
pablophg / roundedbutton.xml
Created January 16, 2015 11:28
Android button with round corners
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#eeffffff" />
<corners android:bottomRightRadius="8dip"
android:bottomLeftRadius="8dip"
android:topRightRadius="8dip"
android:topLeftRadius="8dip"/>
</shape>
@pablophg
pablophg / ModoAvion.java
Created January 19, 2015 09:05
Detect airplane mode changes on Android
package net.pablophg.handlers;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
public class ModoAvion extends BroadcastReceiver {
@Override
@pablophg
pablophg / MainActivity.java
Created January 20, 2015 08:57
Notification example
package net.pablophg.notifications;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.support.v7.app.ActionBarActivity;
@pablophg
pablophg / MainActivity.java
Created January 20, 2015 09:04
Notification example with auto-cancel
package net.pablophg.notifications;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.support.v7.app.ActionBarActivity;
@pablophg
pablophg / activity_main.xml
Created January 21, 2015 09:00
Android layout 3 buttons in a row
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"
android:id="@+id/mainrellay">
<TextView android:text="Pulsa un botón" android:layout_width="wrap_content"
android:layout_height="wrap_content"
@pablophg
pablophg / styles.xml
Created January 22, 2015 12:08
Change ActionBar color
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="android:actionBarStyle">@style/MyActionBar</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar" parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">