Skip to content

Instantly share code, notes, and snippets.

View yasalmasri's full-sized avatar

Yaser Almasri yasalmasri

View GitHub Profile
@mchirico
mchirico / cal.swift
Created September 6, 2014 12:36
Example of creating and removing calendar entries in Swift. Also, shows how to list reminders
/*
You need to import EventKit
import EventKit
*/
@IBAction func buttonCalendar(sender: AnyObject) {
var eventStore : EKEventStore = EKEventStore()
// 'EKEntityTypeReminder' or 'EKEntityTypeEvent'
@radex
radex / NSTimer.md
Last active May 30, 2018 10:33
Swift Extensions: NSTimer

NSTimer is a great example of an over-verbose, outdated Objective-C API. To run a simple line of code after a delay, you need to write a lot of boilerplate crap.

How about this:

NSTimer.schedule(5.seconds) {
  println("Hello world!")
}
@hopsoft
hopsoft / db.rake
Last active July 4, 2025 14:22
Rails rake tasks for dump & restore of PostgreSQL databases
# lib/tasks/db.rake
namespace :db do
desc "Dumps the database to db/APP_NAME.dump"
task :dump => :environment do
cmd = nil
with_config do |app, host, db, user|
cmd = "pg_dump --host #{host} --username #{user} --verbose --clean --no-owner --no-acl --format=c #{db} > #{Rails.root}/db/#{app}.dump"
end
puts cmd
@mudassir0909
mudassir0909 / clear_selection.js
Created June 10, 2014 13:02
Selectize plugin which gives an option to clear selection
Selectize.define( 'clear_selection', function ( options ) {
var self = this;
//Overriding because, ideally you wouldn't use header & clear_selection simultaneously
self.plugins.settings.dropdown_header = {
title: 'Clear Selection'
};
this.require( 'dropdown_header' );
self.setup = (function () {
@apeckham
apeckham / controller.rb
Last active January 20, 2021 20:25
Sending a file upload to s3 with Fog, and writing a spec with Fog's built-in mocks, on Rails 4
storage = Fog::Storage.new(
provider: 'AWS',
aws_access_key_id: 'xxx',
aws_secret_access_key: 'yyy',
path_style: true
)
directory = storage.directories.get('yourbucket')
uploaded = directory.files.create(
key: "324324.jpg",
# config/routes.rb
resources :documents do
scope module: 'documents' do
resources :versions do
post :restore, on: :member
end
resource :lock
end
end
@mobilemind
mobilemind / git-tag-delete-local-and-remote.sh
Last active August 10, 2025 11:21
how to delete a git tag locally and remote
# delete local tag '12345'
git tag -d 12345
# delete remote tag '12345' (eg, GitHub version too)
git push origin :refs/tags/12345
# alternative approach
git push --delete origin tagName
git tag -d tagName
@pamelafox
pamelafox / babyhint.js
Created December 2, 2013 05:13
BabyHint
/*
* BabyHint does a line-by-line check for common beginner programming mistakes,
* such as misspelling, missing spaces, missing commas, etc. It is used in
* conjunction with JSHINT to report errors to the user.
*
* Each error returned contains the members:
* {
* row : the row at which the error was found
* column : the column at which the error was found
* text : the error messaage
@rwjblue
rwjblue / s3-put.sh
Created October 28, 2013 19:21
Short bash script to upload to S3 with no dependencies sans stock openssl & curl. From: https://github.com/sstephenson/ruby-build/blob/4ed38ba4bceafa3f8908a05b58e6bcf219fbbdc3/script/s3-put
#!/usr/bin/env bash
# Usage: s3-put <FILE> <S3_BUCKET> [<CONTENT_TYPE>]
#
# Uploads a file to the Amazon S3 service.
#
# Depends on AWS credentials being set via env:
# - AMAZON_ACCESS_KEY_ID
# - AMAZON_SECRET_ACCESS_KEY
#
# Outputs the URL of the newly uploaded file.
@jimothyGator
jimothyGator / README.md
Last active July 30, 2025 07:45
Nginx configuration for Mac OS X with Homebrew, using sites-enabled directory.
mkdir -p /usr/local/etc/nginx/sites-{enabled,available}
cd /usr/local/etc/nginx/sites-enabled
ln -s ../sites-available/default.conf
ln -s ../sites-available/default-ssl.conf

File locations:

  • nginx.conf to /usr/local/etc/nginx/
  • default.conf and default-ssl.conf to /usr/local/etc/nginx/sites-available
  • homebrew.mxcl.nginx.plist to /Library/LaunchDaemons/