Skip to content

Instantly share code, notes, and snippets.

💭
Hiring developers in Oakland and the Bay area!

Eran Sandler erans

💭
Hiring developers in Oakland and the Bay area!
View GitHub Profile
@erans
erans / mem.c
Created Oct 14, 2018 — forked from ekampf/mem.c
Eran's Interview Question
View mem.c
// Implement a memory manager that takes a large contiguous block of memory and manages allocations
// and deallocations on it.
// The entire buffer needs to be available for allocation. You can use whatever extra memory you need to manage it.
//
// Clearly document design choices, algorithm and possible optimizations.
// While we require you to implement one memory allocation algorithm,
// also document future looking design considerations.
// There are many ways to implement this memory manager. It is important for us to know why you implemented it the way you did,
// whats the pros and cons to your implementation, etc.
//
View keybase.md

Keybase proof

I hereby claim:

  • I am erans on github.
  • I am erans (https://keybase.io/erans) on keybase.
  • I have a public key whose fingerprint is 2DBE C674 27AD 6FD9 209F 0C1D 2403 18B5 90D1 4A2F

To claim this, I am signing this object:

@erans
erans / json-unmarshal-test.go
Created Jul 18, 2016
Unmarshaling JSON text with a long integer number to Struct with field of type interface{}
View json-unmarshal-test.go
package main
import (
"encoding/json"
"fmt"
)
type container struct {
Name string
Value interface{}
@erans
erans / main.go
Last active Jan 8, 2020
Go Example: Google CloudSQL with CloudSQL Proxy and GORM
View main.go
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 / mongobackup.sh
Last active Oct 7, 2019
MongoDB ReplicaSet Backup Script on Google Compute Engine and Google Cloud Storage
View mongobackup.sh
# 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 / alert_areas_to_city_mappings
Created Jul 10, 2014
מיפוי איזורי התראה לערים
View alert_areas_to_city_mappings
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 / encrypt_decrypt_example.js
Last active Jun 8, 2019
Example of encryption and decryption in node.js
View encrypt_decrypt_example.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 / UIImage+Resize.m
Created Nov 7, 2011
UIImage+Resize.m Fix for Rotation / Orientation on iOS 5
View UIImage+Resize.m
- (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 / s3clonebucket.py
Last active Apr 25, 2020
Clone S3 Bucket
View s3clonebucket.py
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 / gmail_email.py
Created Jul 17, 2011
Check if an Email address is Gmail or Google Apps for your domain
View gmail_email.py
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 """
You can’t perform that action at this time.