This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.directive('sameAs', function () { | |
return { | |
require: 'ngModel', | |
link: function (scope, elm, attrs, ctrl) { | |
ctrl.$parsers.unshift(function (viewValue) { | |
if (viewValue === scope.user[attrs.sameAs]) { | |
ctrl.$setValidity('sameAs', true); | |
return viewValue; | |
} else { | |
ctrl.$setValidity('sameAs', false); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Make a file under: `project_root/lib/tasks/server.rake` | |
# Then paste the following code | |
namespace :server do | |
desc "Stop the running server by killing the PID" | |
task :kill do | |
STDOUT.puts "Enter port number: " | |
post_number = STDIN.gets.strip | |
system "pid=$(lsof -i:#{post_number.to_i} -t); kill -TERM $pid || kill -KILL $pid" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I need to convert the first JSON to the second JSON and feed it to an API Endpoint. | |
I wanted to ask you guys to see if there is any module in Elixir or Phoenix beside poison can help me to achieve this? | |
Or should I call the Parents from DB, and then children until I get to the end of line, and create the JSON gradually? | |
I am using arbor for traversing the tree. | |
{ | |
"data": [ | |
{ | |
"parent_id": null, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[%Db.Asset{__meta__: #Ecto.Schema.Metadata<:loaded, "assets">, | |
access_lists: #Ecto.Association.NotLoaded<association :access_lists is not loaded>, | |
archived: false, asset_name: "gear3", description: nil, id: 9598, | |
parent: #Ecto.Association.NotLoaded<association :parent is not loaded>, | |
parent_id: 9591]}, | |
%Db.Asset{__meta__: #Ecto.Schema.Metadata<:loaded, "assets">, | |
access_lists: #Ecto.Association.NotLoaded<association :access_lists is not loaded>, | |
archived: false, asset_name: "shaft2", description: nil, id: 9600, | |
parent: #Ecto.Association.NotLoaded<association :parent is not loaded>, | |
parent_id: 9598]}, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[%Db.Asset{__meta__: #Ecto.Schema.Metadata<:loaded, "assets">, | |
access_lists: #Ecto.Association.NotLoaded<association :access_lists is not loaded>, | |
archived: false, asset_name: "gear3", description: nil, id: 9598, | |
parent: #Ecto.Association.NotLoaded<association :parent is not loaded>, | |
parent_id: 9591]}, | |
%Db.Asset{__meta__: #Ecto.Schema.Metadata<:loaded, "assets">, | |
access_lists: #Ecto.Association.NotLoaded<association :access_lists is not loaded>, | |
archived: false, asset_name: "shaft2", description: nil, id: 9600, | |
parent: #Ecto.Association.NotLoaded<association :parent is not loaded>, | |
parent_id: 9598]}, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'base64' | |
require 'openssl' | |
require 'json' | |
require 'sinatra' | |
require 'logger' | |
require 'pry' | |
logger = Logger.new(STDOUT) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" don't bother with vi compatibility | |
set nocompatible | |
" enable syntax highlighting | |
syntax enable | |
" configure Vundle | |
filetype on " without this vim emits a zero exit status, later, because of :ft off | |
filetype off | |
set rtp+=~/.vim/bundle/Vundle.vim |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
%{ | |
finish: ~D[2019-04-08], | |
user: %{first_name: "Josh", hours: 1.0, id: 24, last_name: "Proud"} | |
}, | |
%{ | |
finish: ~D[2019-04-09], | |
user: %{first_name: "Josh", hours: 1.0, id: 24, last_name: "Proud"} | |
}, | |
%{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
238 - 128 = 110 | |
110 - 64 = 46 | |
46 - 32 = 14 | |
14 - 8 = 6 | |
6 - 4 = 2 | |
2 - 2 = 0 | |
""" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule AncientEgyptianMultiplication do | |
require Integer | |
def of(n, _, state) when n <= 1, do: state | |
def of(n, closest_number, state) do | |
pow_2 = :math.pow(2, closest_number) | |
case pow_2 < n do | |
true -> | |
state = state ++ [pow_2] |
OlderNewer