Skip to content

Instantly share code, notes, and snippets.

Avatar
💻

Eneko Alonso eneko

💻
View GitHub Profile
View gist:288091
// Add callback support to Asset.css for all browsers
Asset.css = function(source, onLoad) {
var link = new Element('link', { rel: 'stylesheet', media: 'screen', type: 'text/css', href: source });
if (("onload" in link) && !Browser.Engines.webkit()) {
if (onLoad) link.onload = onLoad;
} else {
(function() {
try {
link.sheet.cssRules;
@eneko
eneko / gist:7715002
Created Nov 30, 2013
Generate aliases for a taxonomy (Drupal 6)
View gist:7715002
module_load_include('inc', 'path', 'path');
module_load_include('inc', 'pathauto', 'pathauto');
$terms = taxonomy_get_tree(1);
foreach($terms as $term) {
$cleaned = pathauto_cleanstring($term->name);
path_set_alias("taxonomy/term/{$term->tid}", "categorias/$cleaned");
}
View gist:b19dfeeb2047d3ff96d9
let image:CGImage = representation.fullScreenImage().takeUnretainedValue()
NSLog("%d: size %u x %u", index, CGImageGetWidth(image), CGImageGetHeight(image))
let latestPhoto = UIImage(CGImage: image)
NSLog("%d size: %lu x %lu", index, latestPhoto.size.height, latestPhoto.size.width)
View gist:84a1a88a6a32df4d6403
{
"dob" : "1970­-01-­08",
"spendgo_id" : "52463",
"first_name" : "John-383",
"last_name" : "Doe-886",
"email_opt_in" : false,
"sms_opt_in" : false
}
View gist:de7167bef764689c9efb
{
"research_opt_in" : false,
"is_activated" : true,
"favorite_store" : {
"id" : 563,
"state" : "IL",
"street" : "[redacted]",
"name" : "[redacted]",
"city" : "Bengaluru",
"zip" : "60626"
@eneko
eneko / console
Created Jul 1, 2015
Swift scripting and compiling
View console
$ chmod 755 hello.swift
$ ./hello.swift
Hello world!
$ swiftc hello.swift
$ ./hello
Hello world!
$
@eneko
eneko / List.swift
Last active Jul 29, 2018
Linked List in Swift
View List.swift
/// A list is either empty or it is composed of a first element (head)
/// and a tail, which is a list itself.
///
/// See http://www.enekoalonso.com/projects/99-swift-problems/#linked-lists
class List<T> {
var value: T
var nextItem: List<T>?
convenience init?(_ values: T...) {
self.init(Array(values))
View xcodeclean.sh
alias xcodeclean='rm -frd ~/Library/Developer/Xcode/DerivedData/* && rm -frd ~/Library/Caches/com.apple.dt.Xcode/*'
@eneko
eneko / Array.swift
Created Jul 19, 2016
Array.getAt(index:) - Retrieve an item from an array by index with optional result
View Array.swift
public extension Array {
/// Retrieve an item from an array by index with optional result
/// - parameter index: Index of the item to be retrieved
/// - returns: an item by index
public func getAt(index index: Int) -> Element? {
if count > index {
return self[index]
}
return nil
@eneko
eneko / gist:796c1fabd61eaa0ca540e76e78be5d89
Last active Sep 30, 2016
First run of vapor swift install on Ubuntu
View gist:796c1fabd61eaa0ca540e76e78be5d89
$ curl -sL swift.vapor.sh/ubuntu | bash
Swift 3 Quick Installer
🖥 Operating System: ubuntu1404
📦 Installing Dependencies
🔒 Sudo required
Ign http://eu-west-1.ec2.archive.ubuntu.com trusty InRelease
Get:1 http://eu-west-1.ec2.archive.ubuntu.com trusty-updates InRelease [65.9 kB]
Get:2 http://eu-west-1.ec2.archive.ubuntu.com trusty-backports InRelease [65.9 kB]
Hit http://eu-west-1.ec2.archive.ubuntu.com trusty Release.gpg
Hit http://eu-west-1.ec2.archive.ubuntu.com trusty Release