Skip to content

Instantly share code, notes, and snippets.

View yasalmasri's full-sized avatar

Yaser Almasri yasalmasri

View GitHub Profile
@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",
@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 () {
@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
@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!")
}
@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'
@e7d
e7d / bootstrap-autocomplete.html
Last active March 5, 2021 20:44
Bootstrap autocomplete field
<form class="form-horizontal" role="form">
<div class="form-group">
<label for="sampleAutocomplete" class="col-sm-3 control-label">Sample Autocomplete</label>
<div class="col-sm-9">
<input type="text" class="autocomplete form-control" id="sampleAutocomplete" data-toggle="dropdown" />
<ul class="dropdown-menu" role="menu">
<li><a>Action</a></li>
<li><a>Another action</a></li>
<li><a>Something else here</a></li>
<li><a>Separated link</a></li>
@minorbug
minorbug / timeago.swift
Created November 7, 2014 15:28
"Time ago" function for Swift (based on MatthewYork's DateTools for Objective-C)
func timeAgoSinceDate(date:NSDate, numericDates:Bool) -> String {
let calendar = NSCalendar.currentCalendar()
let unitFlags = NSCalendarUnit.CalendarUnitMinute | NSCalendarUnit.CalendarUnitHour | NSCalendarUnit.CalendarUnitDay | NSCalendarUnit.CalendarUnitWeekOfYear | NSCalendarUnit.CalendarUnitMonth | NSCalendarUnit.CalendarUnitYear | NSCalendarUnit.CalendarUnitSecond
let now = NSDate()
let earliest = now.earlierDate(date)
let latest = (earliest == now) ? date : now
let components:NSDateComponents = calendar.components(unitFlags, fromDate: earliest, toDate: latest, options: nil)
if (components.year >= 2) {
return "\(components.year) years ago"
@kukat
kukat / currency-flag.sh
Created December 3, 2014 18:33
currency >> country flag
wget http://www.currencysymbols.in/flags/afghanistan.png -O AFN.png
wget http://www.currencysymbols.in/flags/argentina.png -O ARS.png
wget http://www.currencysymbols.in/flags/aruba.png -O AWG.png
wget http://www.currencysymbols.in/flags/australia.png -O AUD.png
wget http://www.currencysymbols.in/flags/azerbaijan.png -O AZN.png
wget http://www.currencysymbols.in/flags/bahamas.png -O BSD.png
wget http://www.currencysymbols.in/flags/barbados.png -O BBD.png
wget http://www.currencysymbols.in/flags/belarus.png -O BYR.png
wget http://www.currencysymbols.in/flags/belize.png -O BZD.png
wget http://www.currencysymbols.in/flags/bermuda.png -O BMD.png
@justmoon
justmoon / custom-error.js
Last active November 19, 2024 02:40 — forked from subfuzion/error.md
Creating custom Error classes in Node.js
'use strict';
module.exports = function CustomError(message, extra) {
Error.captureStackTrace(this, this.constructor);
this.name = this.constructor.name;
this.message = message;
this.extra = extra;
};
require('util').inherits(module.exports, Error);
@wacko
wacko / pre-commit
Last active September 16, 2020 22:57
Git hook to avoid commit debug lines (binding.pry console.log debugger...)
#!/usr/bin/env ruby
# Validates that you don't commit forbidden keywords to the repo
# You can skip this checking with 'git commit --no-verify'
exit 0 if ARGV.include?('--no-verify')
# Update this list with your own forbidden keywords
KEYWORDS = %w(binding.pry console.log debugger)
def red(text) "\033[31m#{text}\033[0m"; end