Skip to content

Instantly share code, notes, and snippets.

View houmanka's full-sized avatar

Houman Kargaran houmanka

View GitHub Profile
@houmanka
houmanka / directives.js
Last active August 29, 2015 14:17
Angular Lib
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);
@houmanka
houmanka / server.rake
Last active August 29, 2015 14:22
Rake task for stopping a rails server when you don't have access to it.
# 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"
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,
[%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]},
[%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]},
@houmanka
houmanka / xero_hook.rb
Created February 2, 2018 15:13
xero_hook.rb
require 'rubygems'
require 'base64'
require 'openssl'
require 'json'
require 'sinatra'
require 'logger'
require 'pry'
logger = Logger.new(STDOUT)
@houmanka
houmanka / .vimrc
Last active April 3, 2018 22:48
.vimrc
" 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
[
%{
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"}
},
%{
@houmanka
houmanka / AEM_Step1.exs
Last active March 18, 2020 12:14
Crude Recursion
"""
238 - 128 = 110
110 - 64 = 46
46 - 32 = 14
14 - 8 = 6
6 - 4 = 2
2 - 2 = 0
"""
@houmanka
houmanka / AEM_Step2.exs
Created March 19, 2020 09:02
A bit more intelligent
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]