Skip to content

Instantly share code, notes, and snippets.

@decklord
decklord / gist:3dd17499972635b2c858d10d7d260bdc
Created January 23, 2020 14:34
First code challenge for Adereso.
Hi, welcome to Adereso's first code challenge.
You need to implement a function called "letter_counter". It's first and only parameter will be called "letters".
The "letter" parameter should be a string and will contain, as it naims states, only letters, like "abcdef".
Your function must output a dictionary with the number of aparition of each letter.
Examples:
"abc" outputs: {"a":1, "b":2, "c":3}
"zaxayyyy" outputs: {"z":1, "a":2, "x":1, "y": 4}
@decklord
decklord / rfc3339.py
Last active October 9, 2019 10:47
This gist shows how to calculate the diff in seconds between host UTC time and Google Cloud remote machine creation UTC time and use it to wait_for SSH only if the machine is new to avoid being blocked by SSH Guard
#!/usr/bin/python
import datetime
class FilterModule(object):
def filters(self):
return {
'rfc3339_to_utc': self.rfc3339_to_utc
}
module.factory('RecursionHelper', ['$compile', function($compile){
return {
/**
* Author: Mark Lagendijk from Stack Overflow
* Reference: http://stackoverflow.com/questions/14430655/recursion-in-angular-directives
* Manually compiles the element, fixing the recursion loop.
* @param element
* @param [link] A post-link function, or an object with function(s) registered via pre and post properties.
* @returns An object containing the linking functions.
*/
@decklord
decklord / angular_recursion_helper.js
Created March 13, 2017 14:25
Angular 1.x Recursion Helper
module.factory('RecursionHelper', ['$compile', function($compile){
return {
/**
* Manually compiles the element, fixing the recursion loop.
* @param element
* @param [link] A post-link function, or an object with function(s) registered via pre and post properties.
* @returns An object containing the linking functions.
*/
compile: function(element, link){
// Normalize the link parameter

PostCenter

Git Culture: Code Reviews & Commits

Documentation is really important when done right. We must make it a smart process instead of doing it painfully. One good way to document the development process is with git: commits and code reviews. Here are some really good tips for improving our team's work and build a strong development methodology and philosophy.

Better Commits

From 5 Useful Tips For A Better Commit Message and Better Commit Messages with a .gitmessage Template

@decklord
decklord / cache.js
Created July 29, 2015 17:43
This file is a cache module for Appcelerator Platform, now it works just with images but can be extended to support other stuff. Currently supports n number of retries and gets the image path on a callback, so you don't need to fake a dummy imageView if you want to precache some image.
exports.image = function(url, callback, directory) {
if (directory === undefined) {
var directory = 'cachedImages';
}
var filename = Ti.Utils.md5HexDigest(url);
var file = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory, directory, filename);
@decklord
decklord / rutValidator.js
Created February 4, 2015 17:52
Validador de Rut en Coffeescript
formatRut = (str) ->
str.replace(/\./g, '')
checkRut = (str) ->
if not str?
return false
str = str.toString().trim()
str = formatRut str
@decklord
decklord / django-crossdomainxhr-middleware.py
Last active August 29, 2015 13:57 — forked from valsteen/django-crossdomainxhr-middleware.py
Enables to do cross domain requests with django
from django import http
from django.conf import settings
class XsSharingMiddleware(object):
"""
This middleware allows cross-domain XHR using the html5 postMessage API.
Access-Control-Allow-Origin: http://foo.example
Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE
"""
@decklord
decklord / circus_test.py
Created December 5, 2013 19:39
Load watcher on running CIRCUS instance.
from circus.client import CircusClient, make_message
from circus.util import DEFAULT_ENDPOINT_DEALER
client = CircusClient(endpoint=DEFAULT_ENDPOINT_DEALER)
virtual_env_dir = "/path/to/.virtualenvs/virtualenv/bin"
watcher_options = {
"numprocesses": 2,
"working_dir": "my/path/to/file",
@decklord
decklord / .zshrc
Last active December 29, 2015 04:38
ZSH Config File
# Path to your oh-my-zsh configuration.
ZSH=$HOME/.oh-my-zsh
#bind '"\e[A": history-search-backward'
#bind '"\e[B": history-search-forward'
# Set name of the theme to load.
# Look in ~/.oh-my-zsh/themes/
# Optionally, if you set this to "random", it'll load a random theme each
# time that oh-my-zsh is loaded.
ZSH_THEME="robbyrussell"