Skip to content

Instantly share code, notes, and snippets.

@laginha87
laginha87 / gist:d3f81d5545ff4bde1388
Last active August 29, 2015 14:01
quick zsh script for writing daily logs
function log_write() { echo "$(date +%H:%M:%S) $*" >> ~/work_logs/$(date +%d-%m-%y) }
function log_see() { atom ~/work_logs/$(date +%d-%m-%y) }
function log_peek() { tail ~/work_logs/$(date +%d-%m-%y)}
alias log_arrived=' log_write arrived'
alias log_left=' log_write left'
@laginha87
laginha87 / archive.rb
Last active August 29, 2015 14:23
zip paperclip attachment processor
require 'zip'
# requires gem rubyzip
# usage has_attached_file :attachment, path: path, processors: %i(archive), styles: {original: {format: 'zip', archived_file_name:}}
module Paperclip
class Archive < Processor
def make
tempfile = create_zip_tempfile
Zip::File.open(tempfile.path, Zip::File::CREATE) do |zip|
zip.add(archived_file_name, @file.path)
end
IMG_EXTENSION_REGEX = /(-(\d+)x(\d+))?\.(\w*)$/
PREFERED_IMAGE_SIZE_WITH_CAPTURED_EXTENSION = '-300x160.\+'
def extract_image(html)
img_src = Nokogiri::HTML(e.content).css("img").first.attributes['src'].value
img_src.sub(IMG_EXTENSION_REGEX, PREFERED_IMAGE_SIZE_WITH_CAPTURED_EXTENSION)
end
version: '2'
services:
postgres:
ports:
- "5432:5432"
image: postgres
redis:
ports:
- "6379:6379"
image: redis
#!/usr/bin/env ruby
# Needs https://github.com/schacon/git-pulls to work
current_branch = %x(git rev-parse --abbrev-ref HEAD).sub("\n","")
repo_url = %x(git config --get remote.origin.url).sub(".git\n", '')
%x(git pulls update)
pull_requests = %x(git pulls list)
possible_pull_request = pull_requests.split("\n").grep(Regexp.new(current_branch))
has_pull_request = !possible_pull_request.empty?
#!/usr/bin/env ruby
require 'json'
USAGE = "USAGE:\ngit ticket TICKET_ID\n"
# get ticket ID from first command line argument
ticket_id = ARGV[0]
unless ticket_id
print USAGE
#!/usr/bin/env python
import socket
import sys
# Create a TCP/IP socket
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
# Bind the socket to the port
server_address = ('localhost', 8125)
@laginha87
laginha87 / array_and_hash_1.cr
Created May 2, 2018 18:11
array_and_hash_1.cr
# Declaring empty Int array and hashes
array = [] of Int32
hash = {} of String => Int32
@laginha87
laginha87 / array_and_hash_2.cr
Created May 2, 2018 18:14
array_and_hash_2
# Declaring arrays and hashes that can have nils
array = [] of Int32?
hash = {} of String => Int32?
@laginha87
laginha87 / array_and_hash_3.cr
Created May 2, 2018 18:15
array_and_hash_3
# Declaring arrays and hashes that can have nils and have either strings or ints
array = [] of Int32|String?
hash = {} of String => Int32|String?
alias A = Int32|String?
array_2 = [] of A