Skip to content

Instantly share code, notes, and snippets.

@amitittyerah
amitittyerah / laravel.php
Last active August 29, 2015 14:03
Custom token based filtering in Laravel
<?php
# app/models/TokenFilter.php
class TokenFilter {
public function filter()
{
if(!Token::valid(Input::get('token')))
{
@amitittyerah
amitittyerah / inject_xss.php
Created June 5, 2014 06:56
SQL Injection and XSS demonstration
<?php
/**
* SQL Injection and XSS attacks demonstrated
*
* Last modified : 5th June 2014
*/
$SAFE = TRUE;
@amitittyerah
amitittyerah / DatabaseFileManager.hm
Last active August 29, 2015 14:00
Copy db files to app documents
// DatabaseFileManager.h
#import <Foundation/Foundation.h>
@interface DatabaseFileManager : NSObject
+ (void) manageFiles :(NSArray *) arrayOfDatabaseNames;
@end
@amitittyerah
amitittyerah / crud_examples.py
Created April 25, 2014 05:17
Django CRUD example
# urls.py
urlpatterns += patterns('',
url(r'^platform$', views.platform_list, name='platform_list'),
url(r'^platform/new$', views.platform_create, name='platform_new'),
url(r'^platform/edit/(?P<pk>\d+)$', views.platform_update, name='platform_edit'),
url(r'^platform/delete/(?P<pk>\d+)$', views.platform_delete, name='platform_delete'),
)
@amitittyerah
amitittyerah / gmaps_helpers.js
Created April 24, 2014 00:15
Get bounds from the Google Maps Autocomplete response
function get_bounds(gmaps_autocomplete_response) {
var lats = false, longs = false;
$.each(gmaps_autocomplete_response.geometry.viewport, function () {
if (!lats || !longs) {
var x,y = false;
var ref = false;
$.each(this, function () {
if (!x || !y) {
if (!x) x = this;
else y = this;
@amitittyerah
amitittyerah / service_helpers.py
Last active August 29, 2015 14:00
Django web service helpers to iterate through and return expected parameters from the request object. Static methods can be left generic doing overrides on certain getattrs instead of having to redefine attributes at every stage.
# service_helpers.py
def create_img_name(identifier):
return '%s%s%s' % (identifier, to_unix.to_unix(datetime.now()), randomstring.get_random_string())
def get_params(obs, params, struct='dict'):
if struct == 'dict':
values = dict([ (param, obs.get(param)) for param in params if param in obs])
else:
values = [(param, obs.get(param)) for param in params]
@amitittyerah
amitittyerah / udp_listener.py
Created April 18, 2014 08:02
Python UDP Port Listener
import socket
import select
PORT = 1002
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.bind(('0.0.0.0', PORT))
while True:
package, w, x = select.select([sock], [], [])
@amitittyerah
amitittyerah / WhatsAppShare.java
Created April 12, 2014 11:17
Share via WhatsApp for Android
class WhatsAppShare extends ShareManager
{
public WhatsAppShare(Context context)
{
super(context);
}
public void shareViaWhatsApp(String msg)
{
Intent whatsAppIntent = new Intent(Intent.ACTION_SEND);
@amitittyerah
amitittyerah / read_config.sh
Created April 11, 2014 05:00
Bash profile function to read the SSH config and to copy it to the clipboard
function config()
{
cat ~/.ssh/config | while read line; do
if [[ $line == Host* ]];then
lline=$(echo $line| tr '[:upper:]' '[:lower:]')
if [ $# -eq 0 ];then
echo "$line"
echo "ssh ${line:5}" | pbcopy
elif [[ "${lline}" == *"$1"* ]];then
echo "$line"
@amitittyerah
amitittyerah / gist:10441608
Created April 11, 2014 04:59
Simple webserver with Rack
$ sudo apt-get install ruby-bundler
# Gemfile
source :rubygems
gem 'rack'
$ bundler install
# config.ru
use Rack::Static,