Skip to content

Instantly share code, notes, and snippets.

View aesmail's full-sized avatar
🇯🇵
日本語を勉強しています

Abdullah Esmail aesmail

🇯🇵
日本語を勉強しています
View GitHub Profile
def application(app, didReceiveLocalNotification: notification)
if app.applicationState == UIApplicationStateInactive
NSLog("didReceiveLocalNotification...")
url = NSURL.URLWithString("sms:12345678")
NSLog("finished creating URL...")
app.openURL(url)
NSLog("opened URL... Done.")
elsif app.applicationState == UIApplicationStateActive
App.alert(notification.alertBody)
end
Abdullahs-iMac-2:GM abdullah$ bundle update
Fetching gem metadata from https://rubygems.org/............
Fetching version metadata from https://rubygems.org/...
Fetching dependency metadata from https://rubygems.org/..
Resolving dependencies...
Using rake 10.4.2
Using i18n 0.7.0
Using json 1.8.3
Using minitest 5.7.0
Using thread_safe 0.3.5
@aesmail
aesmail / gist:813612
Created February 6, 2011 19:05
facebook api wrapper for django
class FacebookMiddleware():
def process_request(self, request):
api_key = settings.FACEBOOK_API_KEY
secret_key = settings.FACEBOOK_SECRET_KEY
request.facebook = Facebook(api_key=api_key, secret_key=secret_key, request=request)
if request.facebook.is_logged_in():
username = request.facebook.get_uid()
try:
curr_user = User.objects.get(username=username)
try:
@aesmail
aesmail / gist:1250458
Created September 29, 2011 10:17
Some django sample code
class Item(models.Model):
category = models.ForeignKey(Category, related_name='items')
city = models.ForeignKey(City, verbose_name=u'المنطقة', related_name='items')
activation_code = models.CharField(max_length=64)
is_active = models.BooleanField(default=False)
is_deleted = models.BooleanField(default=False)
email = models.EmailField(u'البريد الإلكتروني')
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
title = models.CharField(u'العنوان', max_length=200)
<% content_for(:calendar) do %>
<%= render 'calendar' %>
<% end %>
------------
<% content_for(:calendar) { render :partial => 'calendar' } %>
------------
@aesmail
aesmail / gist:3369047
Created August 16, 2012 10:11
syntax error in rails time zone conversion file
# code in Blog model
##########################
feed.entries.each do |entry|
puts "=== creating new post..."
post = Post.new(:title => entry.title)
post.blog_id = self.id
puts "=== blog_id = #{post.blog_id}"
# code never reaches past Post.new line
# I have a datetime field (post_date)
class CreatePosts < ActiveRecord::Migration
def change
create_table :posts do |t|
t.references :blog, :null => false
t.datetime :post_date, :null => false
t.string :url, :null => false
t.string :author
t.string :title, :null => false
t.attachment :image, :null => false
t.text :body
@aesmail
aesmail / gist:4365006
Created December 23, 2012 18:16
BackgroundLayer is not positioned in the center of the screen.
// BackgroundLayer
-(id) init {
self = [super init];
if(self != nil) {
CCSprite *backgroundImage;
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
backgroundImage = [CCSprite spriteWithFile:@"background.png"];
} else {
backgroundImage = [CCSprite spriteWithFile:@"backgroundiPhone.png"];
}
# controller
def create
user = User.create(params[:user])
respond_with(user, include: :extras)
end
# nginx conf
server {
listen 80;
@aesmail
aesmail / Python's Decimal behaviour
Created April 27, 2016 10:17
Python: Difference when passing a number or a string to decimal.Decimal
# Scenario ONE
price = Decimal(33.000) # <-- passed in a number
factor = Decimal(0.3020)
price = price / factor
price = price * factor
price.quantize(Decimal("0.01"), rounding=ROUND_UP) # --> 33
# Scenario TWO
price = Decimal('33.000') # <-- passed in a string
factor = Decimal('0.3020')