Skip to content

Instantly share code, notes, and snippets.

View alesanabriav's full-sized avatar
🗺️

Alejandro Sanabria alesanabriav

🗺️
View GitHub Profile
@Lancewer
Lancewer / CollectionViewCell.swift
Last active May 17, 2023 09:05
[Collection Single Selection] single selection in UICollectionView with swift #swift #UICollectionView #selection #select #single select
//custom cell class
import UIKit
class CollectionViewCell: UICollectionViewCell {
@IBOutlet weak var nameLabel: UILabel!
override var isSelected: Bool{
didSet(newValue){
contentView.backgroundColor = newValue ? UIColor.green : UIColor.white
@EzimetYusup
EzimetYusup / range.swift
Created October 12, 2016 19:41
extension NSMutableAttributedString for to find the range of String
extension NSMutableAttributedString {
public func getRangeOfString(textToFind:String)->NSRange{
let foundRange = self.mutableString.rangeOfString(textToFind)
return foundRange
}
}
@cbess
cbess / TimeParts.swift
Last active May 5, 2023 07:59
Swift: Seconds to minutes and hours parts
/// Represents parts of time
struct TimeParts: CustomStringConvertible {
var seconds = 0
var minutes = 0
/// The string representation of the time parts (ex: 07:37)
var description: String {
return NSString(format: "%02d:%02d", minutes, seconds) as String
}
}
@darrenscerri
darrenscerri / Middleware.js
Last active July 11, 2023 02:59
A very minimal Javascript (ES5 & ES6) Middleware Pattern Implementation
var Middleware = function() {};
Middleware.prototype.use = function(fn) {
var self = this;
this.go = (function(stack) {
return function(next) {
stack.call(self, function() {
fn.call(self, next.bind(self));
});
@austinhyde
austinhyde / js-observables-binding.md
Last active August 16, 2023 18:19
Vanilla JavaScript Data Binding

Observables

You don't really need a framework or fancy cutting-edge JavaScript features to do two-way data binding. Let's start basic - first and foremost, you need a way to tell when data changes. Traditionally, this is done via an Observer pattern, but a full-blown implementation of that is a little clunky for nice, lightweight JavaScript. So, if native getters/setters are out, the only mechanism we have are accessors:

var n = 5;
function getN() { return n; }
function setN(newN) { n = newN; }

console.log(getN()); // 5

setN(10);

@zmsaunders
zmsaunders / filters.php
Last active August 7, 2022 10:54
HTML Output Minification in laravel 4
<?php
### --- Snip --- ###
App::after(function($request, $response)
{
// HTML Minification
if(App::Environment() != 'local')
{
if($response instanceof Illuminate\Http\Response)
@johnschimmel
johnschimmel / express_s3_aws-sdk-js.js
Created April 19, 2013 16:00
ExpressJS file upload to S3
exports.new_photo = function(req, res){
// Get File upload information
var filename = req.files.image.filename; // actual filename of file
var path = req.files.image.path; //will be put into a temp directory
var mimeType = req.files.image.type; // image/jpeg or actual mime type
// Create a new blog post
var photoPost = new Photo(); // create Blog object
@juanje
juanje / gist:2210054
Created March 26, 2012 21:55
Get the opscode cookbooks for installing django with Chef-solo at Vagrant
# Create the local directory for the Cookbooks
mkdir cookbooks
# Change into the newly created ~/django_guide/cookbooks directory
cd cookbooks
# Clone the Chef Cookbooks repositories
git clone git://github.com/opscode-cookbooks/apt.git
git clone git://github.com/opscode-cookbooks/apache2.git
git clone git://github.com/opscode-cookbooks/build-essential.git
@elidupuis
elidupuis / handlebars-helpers.js
Last active December 7, 2021 02:24
Simple Handlebars.js helpers
/*! ******************************
Handlebars helpers
*******************************/
// debug helper
// usage: {{debug}} or {{debug someValue}}
// from: @commondream (http://thinkvitamin.com/code/handlebars-js-part-3-tips-and-tricks/)
Handlebars.registerHelper("debug", function(optionalValue) {
console.log("Current Context");
console.log("====================");