Skip to content

Instantly share code, notes, and snippets.

View erans's full-sized avatar
馃挱
Thinking about new things!

Eran Sandler erans

馃挱
Thinking about new things!
View GitHub Profile
@erans
erans / get_lat_lon_exif_pil.py
Created May 20, 2011 21:16
Get Latitude and Longitude from EXIF using PIL
from PIL import Image
from PIL.ExifTags import TAGS, GPSTAGS
def get_exif_data(image):
"""Returns a dictionary from the exif data of an PIL Image item. Also converts the GPS Tags"""
exif_data = {}
info = image._getexif()
if info:
for tag, value in info.items():
decoded = TAGS.get(tag, tag)
@erans
erans / kestrel.sh
Created June 28, 2011 19:04
Twitter鈥檚 Kestrel init script for Ubuntu 10.04 Lucid
#!/bin/sh
#
# kestrel init.d script.
#
# All java services require the same directory structure:
# /usr/local/$APP_NAME
# /var/log/$APP_NAME
# /var/run/$APP_NAME
APP_NAME="kestrel"
@erans
erans / gmail_email.py
Created July 17, 2011 07:45
Check if an Email address is Gmail or Google Apps for your domain
import sys
import re
import dns.resolver # Requires dnspython
email_host_regex = re.compile(".*@(.*)$")
gmail_servers_regex = re.compile("(.google.com.|.googlemail.com.)$", re.IGNORECASE)
def is_gmail(email):
""" Returns True if the supplied Email address is a @gmail.com Email or is a Google Apps for your domain - hosted Gmail address
Checks are performed by checking the DNS MX records """
@erans
erans / s3clonebucket.py
Last active April 25, 2020 12:27
Clone S3 Bucket
import argparse
import time
from boto.s3.connection import S3Connection
from boto.exception import S3ResponseError
def run(args):
s3_connection = S3Connection(args.aws_access_key, args.aws_secret_access_key)
source_bucket = s3_connection.get_bucket(args.source_bucket)
destination_bucket = None
@erans
erans / UIImage+Resize.m
Created November 7, 2011 07:10
UIImage+Resize.m Fix for Rotation / Orientation on iOS 5
- (UIImage *)resizedImage:(CGSize)newSize interpolationQuality:(CGInterpolationQuality)quality {
BOOL drawTransposed;
CGAffineTransform transform = CGAffineTransformIdentity;
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 5.0) {
// Apprently in iOS 5 the image is already correctly rotated, so we don't need to rotate it manually
drawTransposed = NO;
} else {
switch (self.imageOrientation) {
case UIImageOrientationLeft:
@erans
erans / encrypt_decrypt_example.js
Last active October 14, 2022 02:31
Example of encryption and decryption in node.js
var crypto = require("crypto")
function encrypt(key, data) {
var cipher = crypto.createCipher('aes-256-cbc', key);
var crypted = cipher.update(data, 'utf-8', 'hex');
crypted += cipher.final('hex');
return crypted;
}
@erans
erans / alert_areas_to_city_mappings
Created July 10, 2014 05:40
诪讬驻讜讬 讗讬讝讜专讬 讛转专讗讛 诇注专讬诐
var cities = [{label:"讗 讚讛讗讘砖讛", value:"124"},
{label:"讗 讚讬专讗转", value:"122"},
{label:"讗 讚谞驻讬专讬", value:"205"},
{label:"讗 讝讬讗讚谞讛 讚专讜诪讬转 诇专讛讟", value:"179"},
{label:"讗 讝讬讗讚谞讛 爪驻讜谞讬转 诇专讛讟", value:"179"},
{label:"讗 讝注讬讬诐", value:"96"},
{label:"讗 讟讘拽讛", value:"122"},
{label:"讗 讟讜讜讗谞讬", value:"122"},
{label:"讗 诇讜讘讗谉", value:"92"},
{label:"讗 谞讘讗专讬", value:"199"},
@erans
erans / mongobackup.sh
Last active October 7, 2019 16:59
MongoDB ReplicaSet Backup Script on Google Compute Engine and Google Cloud Storage
# Path to boto config file, needed by gsutils
BOTO_CONFIG="/etc/boto.cfg"
# Path in which to create the backup (will get cleaned later)
BACKUP_PATH="/mnt/data/dump/"
# DB name
DB_NAME="mydatabase"
# Google Cloud Storage Bucket Name
@erans
erans / main.go
Last active June 5, 2024 14:36
Go Example: Google CloudSQL with CloudSQL Proxy and GORM
package main
import (
"github.com/jinzhu/gorm"
_ "database/sql"
_ "github.com/GoogleCloudPlatform/cloudsql-proxy/proxy/dialers/mysql"
)
// You can read more in this post: http://forecastcloudy.net/2016/06/28/using-google-cloud-sql-from-go-with-gorm-in-google-container-engine-and-google-compute-engine/
func main() {
@erans
erans / json-unmarshal-test.go
Created July 18, 2016 07:38
Unmarshaling JSON text with a long integer number to Struct with field of type interface{}
package main
import (
"encoding/json"
"fmt"
)
type container struct {
Name string
Value interface{}