Skip to content

Instantly share code, notes, and snippets.

View werner's full-sized avatar
🏠
Working from home

Werner Echezuría werner

🏠
Working from home
View GitHub Profile
@nkpart
nkpart / merge_sort.rb
Created October 14, 2011 04:04 — forked from kimhunter/merge_sort.rb
Merge sort ruby
#!/usr/bin/env ruby
# 2011-10-10 20:57:53 +1000
def merge_sort(a)
return a if a.size <= 1
l, r = split_array(a)
result = combine(merge_sort(l), merge_sort(r))
end
@keeguon
keeguon / countries.json
Created April 5, 2012 11:11
A list of countries in JSON
[
{name: 'Afghanistan', code: 'AF'},
{name: 'Åland Islands', code: 'AX'},
{name: 'Albania', code: 'AL'},
{name: 'Algeria', code: 'DZ'},
{name: 'American Samoa', code: 'AS'},
{name: 'AndorrA', code: 'AD'},
{name: 'Angola', code: 'AO'},
{name: 'Anguilla', code: 'AI'},
{name: 'Antarctica', code: 'AQ'},
@andkerosine
andkerosine / raskell.rb
Created August 15, 2012 05:56
Haskell-like list comprehensions in Ruby
$stack, $draws = [], {}
def method_missing *args
return if args[0][/^to_/]
$stack << args.map { |a| a or $stack.pop }
$draws[$stack.pop(2)[0][0]] = args[1] if args[0] == :<
end
class Array
def +@
@hakisa-jerome
hakisa-jerome / ValidatorListener.php
Created September 23, 2012 08:12
Prevent invalid entities from being updated
<?php
namespace Acme\DemoBundle\EventListener;
use Symfony\Component\Validator\Validator;
use Doctrine\ORM\Event\LifecycleEventArgs;
/**
* Prevent invalid entities from being updated
*
@maxivak
maxivak / send_data-send_file-remote-images-download
Created January 1, 2013 23:34
Rails. Download remote image as attachment in browser
# in controller
# for local files
send_file '/path/to/file', :type => 'image/jpeg', :disposition => 'attachment'
# for remote files
require 'open-uri'
url = 'http://someserver.com/path/../filename.jpg'
data = open(url).read
send_data data, :disposition => 'attachment', :filename=>"photo.jpg"
@quchen
quchen / gist:4634782
Last active October 30, 2016 13:53
Deriving a Read instance from a Parsec parser
import Text.Parsec hiding ((<|>), many)
import Text.Parsec.String
import Text.Printf
import Control.Applicative
data MyType = Single Int
| Tuple MyType MyType
instance Show MyType where
show (Single x) = show x
@honza
honza / gist.md
Created June 30, 2013 23:03
Clojure vs Haskell

Haskell vs Clojure

The JSON data is in the following format

{
    "Genesis": {
        "1": {
            "1": "In the beginning..." ,
            "2": "..."
@mobilemind
mobilemind / git-tag-delete-local-and-remote.sh
Last active July 2, 2024 00:02
how to delete a git tag locally and remote
# delete local tag '12345'
git tag -d 12345
# delete remote tag '12345' (eg, GitHub version too)
git push origin :refs/tags/12345
# alternative approach
git push --delete origin tagName
git tag -d tagName
@arsatiki
arsatiki / Main.elm
Created January 23, 2014 06:54
Hack to load elm code into node.js. Requires path to Elm runtime file. Also included is an example file.
module Squarer where
import JavaScript as JS
foreign import jsevent "input"
(JS.fromInt 0)
inputs: Signal JS.JSNumber
foreign export jsevent "reply"
outputs: Signal JS.JSNumber
@dhoelzgen
dhoelzgen / base_controller.rb
Last active October 7, 2021 16:19
CORS in Rails 4 APIs
class API::V1::BaseController < ApplicationController
skip_before_filter :verify_authenticity_token
before_filter :cors_preflight_check
after_filter :cors_set_access_control_headers
def cors_set_access_control_headers
headers['Access-Control-Allow-Origin'] = '*'
headers['Access-Control-Allow-Methods'] = 'POST, GET, PUT, DELETE, OPTIONS'