Skip to content

Instantly share code, notes, and snippets.

View vekexasia's full-sized avatar

Andrea Baccega vekexasia

View GitHub Profile
@vekexasia
vekexasia / gist:2328838
Created April 7, 2012 13:20
Database schema for a password reset functionality.
CREATE TABLE IF NOT EXISTS `resetpasswordtokens` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`userID` int(11) NOT NULL,
`token` char(32) NOT NULL,
`status` set('used','new') NOT NULL DEFAULT 'new',
`date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
KEY `userID` (`userID`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
@vekexasia
vekexasia / gist:2367508
Created April 12, 2012 14:01
Check if the user is opening the app for the first time
private Boolean firstTime = null;
/**
* Checks if the user is opening the app for the first time.
* Note that this method should be placed inside an activity and it can be called multiple times.
* @return boolean
*/
private boolean isFirstTime() {
if (firstTime == null) {
SharedPreferences mPreferences = this.getSharedPreferences("first_time", Context.MODE_PRIVATE);
firstTime = mPreferences.getBoolean("firstTime", true);
@vekexasia
vekexasia / gist:2383248
Created April 14, 2012 09:56
Add Events on Google Calendar on Android Froyo and above
/**
* Adds the event to a calendar. It lets the user choose the calendar
* @param ctx Context ( Please use the application context )
* @param title title of the event
* @param dtstart Start time: The value is the number of milliseconds since Jan. 1, 1970, midnight GMT.
* @param dtend End time: The value is the number of milliseconds since Jan. 1, 1970, midnight GMT.
*/
private static void addToCalendar(Context ctx, final String title, final long dtstart, final long dtend) {
final ContentResolver cr = ctx.getContentResolver();
Cursor cursor ;
@vekexasia
vekexasia / snippet_example_a.html
Created April 27, 2012 13:55
Xss Injection Post on andreabaccega.com
<a href='http://www.example.com' onClick='javascript:alert("blabla");'>Click Me!</a>
@vekexasia
vekexasia / nodejs.js
Created June 15, 2012 15:59
Node js less compiler
var fs = require('fs'),
less = require('less'),
compressor = require('node-minify'),
directory = 'bootstrapless/',
rootLess = 'bootstrap.less';
var parser = new(less.Parser)({
paths: [directory] // Specify search paths for @import directives
});
@vekexasia
vekexasia / check_last_logs_lines.sh
Last active December 14, 2015 20:58
Nagios plugin that let you search within a logfile for a pattern ( could be empty ) and have a critical/warning value when the number of lines matching the pattern exceeds critical/warning within the last N minutes
#!/usr/bin/env bash
## This program is free software: you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@vekexasia
vekexasia / test1.php
Last active December 20, 2015 15:29 — forked from anonymous/test1.php
<?php
$arr = array(1,2,3,4,5,6,7,8,9,10);
$arrLess = array();
$arrGret = array();
$total = 0;
$nuEle = count($arr);
foreach ($arr as $arr_ele){
$total += $arr_ele;
}
@vekexasia
vekexasia / test2.php
Last active December 20, 2015 15:38 — forked from anonymous/test2.php
<?php
$arr = array();
for($i = 4; $i <= 1000000; $i++){
if(!isPrime($i)){
array_push($arr,$i);
}
}
function isPrime($number){
if ($number % 2 == 0) {
@vekexasia
vekexasia / domain_mapping.patch
Created July 7, 2014 08:23
Domain Mapping Patch
From 14a75ecbab4812acbe49e00ed0dd7c34375a9306 Mon Sep 17 00:00:00 2001
From: "Andrea BACCEGA" <vekexasia@gmail.com>
Date: Mon, 7 Jul 2014 08:16:51 +0000
Subject: [PATCH] Added pagination Fixed search with a real working LIKE
---
domain_mapping.php | 33 ++++++++++++++++++++++++++++++---
1 file changed, 30 insertions(+), 3 deletions(-)
diff --git a/domain_mapping.php b/domain_mapping.php
@vekexasia
vekexasia / fix_ubuntu.sh
Last active August 29, 2015 14:06
Fix Bash Bug 'Shell Shock' ubuntu
sudo apt-get -y install build-essential
mkdir src
cd src
wget http://ftp.gnu.org/gnu/bash/bash-4.3.tar.gz
#download all patches
for i in $(seq -f "%03g" 0 25); do wget http://ftp.gnu.org/gnu/bash/bash-4.3-patches/bash43-$i; done
tar zxvf bash-4.3.tar.gz
cd bash-4.3
#apply all patches
for i in $(seq -f "%03g" 0 25);do patch -p0 < ../bash43-$i; done