Skip to content

Instantly share code, notes, and snippets.

Cezar Halmagean chalmagean

Block or report user

Report or block chalmagean

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View Backup docker named volume
# Here's how to back up a named volume
# 1. Using a `ubuntu` image, we mount the named volume (`myproj_dbdata`) to a `/dbdata` folder inside the `ubuntu` container.
# 2. Then, we create a new folder inside the `ubuntu` container named `/backup`.
# 3. We then create an archive containing the contents of the `/dbdata` folder and we store it inside the `/backup` folder (inside the container).
# 4. We also mount the `/backup` folder from the container to the docker host (your local machine) in a folder named `/backups` inside the current directory.
docker run --rm -v myproj_dbdata:/dbdata -v $(pwd)/backups:/backup ubuntu tar cvf /backup/db_data_"$(date '+%y-%m-%d')".tar /dbdata
View pre-push
#!/bin/sh
echo "Loading the test enviromnment..."
source .env.test
RAILS_ENV=test bundle exec rspec
if [[ $? != 0 ]]; then
echo "RSpec tests have failures. Push rejected."
exit 1
@chalmagean
chalmagean / pre-push
Created Jul 8, 2015
Pre-Push git hook to run specs before pushing
View pre-push
#!/bin/sh
# Put it in .git/hooks/pre-push
branch=`git rev-parse --abbrev-ref HEAD`
exit_code=$(bundle exec rspec --fail-fast --out /dev/null --format progress > /dev/null 2>/dev/null )$?
if [ $exit_code -gt 0 ]
then echo "Did not push because of failing tests"
fi
@chalmagean
chalmagean / link_to_onclick
Last active May 31, 2018
link_to onclick
View link_to_onclick
@chalmagean
chalmagean / onSelect.elm
Last active Dec 22, 2016
Elm onSelect decoder
View onSelect.elm
-- Assuming we have a list of items in the model (type alias Model = { items : List Item }
-- where Item is a record like { id : Int, name : String }
-- this goes in the view and generates an html dropdown
select
[ onSelect ValueSelectedMsg ]
(List.map (\item -> option [ value (toString item.id) ] [ text item.name ]) model.items)
targetSelectedIndex : Json.Decoder Int
@chalmagean
chalmagean / model_uniqueness_constraint.exs
Last active Dec 8, 2016
Testing uniqueness constraints for models
View model_uniqueness_constraint.exs
defmodule Example.User do
use Example.Web, :model
schema "users" do
field :email, :string
timestamps()
end
@doc """
@chalmagean
chalmagean / enc.ex
Last active Nov 2, 2016
RC4 encryption/decryption in Elixir/Erlang
View enc.ex
# Install https://github.com/rubencaro/cipher first
require Cipher.Helpers, as: H
defmodule Enc do
@random_key H.env(:keyphrase) |> Cipher.Digest.generate_key
def stream_encrypt(xml) do
{_, result} =
:crypto.stream_init(:rc4, @random_key)
|> :crypto.stream_encrypt(xml)
View gist:d0e80a1b58204c937e15886087256898
# Purge merged branches
git branch --merged | grep -v "\*" | grep -v master | grep -v staging | grep -v develop | xargs -n 1 git branch -d
@chalmagean
chalmagean / Main.elm
Created Jun 23, 2016
elm_validated_form
View Main.elm
module Main exposing (..)
import Html.App as Html
import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (..)
import Form exposing (Form)
import Form.Validate as Validate exposing (..)
import Form.Input as Input
View gist:5f77692037eaef9dc41590bd9fc25701
type Action
= NoOp
| UpdateProtein String
view : Signal.Address Action -> Model -> Html
view address model =
div [] [
div [] [
input
[ type' "text"
You can’t perform that action at this time.