Skip to content

Instantly share code, notes, and snippets.

@iezg
iezg / gist:3793033
Created September 27, 2012 09:10
Get the attribute of an iTunes Store's application by bundle Id
# encoding: utf-8
import requests, json
APPSTORE_URL = "http://itunes.apple.com/lookup?bundleId=";
def get_app_data_by_bundle_id(bundle_id):
"""Queries the iTunes store by app's bundle Id and if
the app exists, returns the app's data (dict)"""
@iezg
iezg / HibernateListener.java
Created October 2, 2012 14:04
Integrate Hibernate 4.1 in a raw Tomcat 7 (no JPA, no Spring, etc)
package com.playground.myapp.web;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.service.ServiceRegistryBuilder;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
@iezg
iezg / bash_profile
Created October 28, 2012 13:00
Django + Virtualenvwrapper
export WORKON_HOME=$HOME/.virtualenvs
source /usr/local/bin/virtualenvwrapper.sh
@iezg
iezg / context.xml
Created December 11, 2012 09:36
c3p0 configuration inside app's context
<?xml version="1.0" encoding="UTF-8"?>
<Context antiJARLocking="true" path="/">
<Resource
name="jdbc/sample"
auth="Container"
driverClass="com.mysql.jdbc.Driver"
jdbcUrl="jdbc:mysql://localhost:3306/yourdbname"
user="your_user"
@iezg
iezg / random.java
Created January 9, 2013 11:21
Generating random number in a range with Java
// Example assumes these variables have been initialized
// above, e.g. as method parameters, fields, or otherwise
int min, max;
// nextInt is normally exclusive of the top value,
// so add 1 to make it inclusive
Random rand = new Random();
int randomNum = rand.nextInt(max - min + 1) + min;
@iezg
iezg / gist:4500615
Last active December 10, 2015 22:18
Modifing max connections setting in MySQL
show variables like "max_connections";
@iezg
iezg / .htaccess
Last active December 12, 2015 04:18
AddHandler x-web-app-manifest+json .webapp
AddType application/x-web-app-manifest+json .webapp
@iezg
iezg / tizen.py
Last active December 18, 2015 09:49
Tizen package name generator
import string
import random
def generate_tizen_app_id(self):
"""Generates a 10-character alphanumeric value used to identify
a Tizen application"""
chars = string.ascii_letters + string.digits
return ''.join(random.choice(chars) for x in range(10))
@iezg
iezg / gist:7184686
Created October 27, 2013 16:37
Python in OSX Mavericks
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named virtualenvwrapper.hook_loader
virtualenvwrapper.sh: There was a problem running the initialization hooks.
If Python could not import the module virtualenvwrapper.hook_loader,
check that virtualenv has been installed for
VIRTUALENVWRAPPER_PYTHON=/usr/bin/python and that PATH is
set properly.
@iezg
iezg / drop_connection.sql
Last active January 3, 2016 05:29
Get Postgres active connections, and drop the idle ones
-- PostgreSQL 9.1 and below:
SELECT pg_terminate_backend(pg_stat_activity.procpid)
FROM pg_stat_activity
WHERE pg_stat_activity.datname = 'TARGET_DB'
AND procpid <> pg_backend_pid();
-- PostgreSQL 9.2 and above:
SELECT pg_terminate_backend(pg_stat_activity.pid)
FROM pg_stat_activity
WHERE pg_stat_activity.datname = 'TARGET_DB'