Skip to content

Instantly share code, notes, and snippets.

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

Saroar Khandoker saroar

🏠
Working from home
View GitHub Profile
ActiveAdmin.register NutritionData do
menu false
form do |f|
f.inputs "Details" do
f.input :item_id, :as => :hidden
f.input :header, :input_html => {:rows => 5}
f.input :serving, :input_html => {:rows => 5}
f.input :calories
f.input :calories_from_fat
class CreateProjects < ActiveRecord::Migration[5.0]
def change
create_table :projects do |t|
t.string :name
t.timestamps
end
end
end
@saroar
saroar / deploying_phoenix_on_dokku.md
Created September 18, 2016 07:22 — forked from henrik/deploying_phoenix_on_dokku.md
Deploying Elixir's Phoenix Framework on Dokku.

Deploying Phoenix on Dokku

Worked 2015-09-08 for Phoenix 1.0.1 on Dokku 0.3.25.

These instructions assume you've set up Dokku. If not, go find a tutorial for that part. My notes for setting it up on Digital Ocean.

On your local machine, in the app's repo

Create a Dokku app:

@saroar
saroar / active-record-migration-expert.md
Created October 12, 2016 17:33 — forked from pyk/active-record-migration-expert.md
become active record migration expert (Rails 4.0.2)

become active record migration expert (Rails 4.0.2)

workflow:

create model

$ rails g model NameOfModel
    invoke  active_record
    create    db/migrate/YYYYMMDDHHMMSS_create_name_of_models.rb
@saroar
saroar / form_steps.rb
Created April 11, 2017 14:18 — forked from emk/form_steps.rb
Fill in multiline forms with Cucumber and Webrat
# Fill in multiple form fields using a table. Use it as follows:
#
# When I fill in the fields
# | Field 1 | Value 1 |
# | Field 2 | Value 2 |
When /^I fill in the fields$/ do |table|
table.rows_hash.each {|field, value| fill_in field, :with => value }
end
extension Route {
init<IN: Codable, OUT: Codable>(uri: String, _ handler: @escaping (IN) throws -> OUT) {
self.init(method: .post, uri: uri) {
req, resp in
do {
guard let body = req.postBodyBytes else {
throw DecodingError.dataCorrupted(.init(codingPath: [], debugDescription: "This request requires JSON input."))
}
let input = try JSONDecoder().decode(IN.self, from: Data(bytes: body))
resp.setBody(bytes: try JSONEncoder().encode(try handler(input)).map{$0})
@saroar
saroar / bitcoin-pay.rb
Created May 10, 2017 06:47 — forked from Sjors/bitcoin-pay.rb
This script demonstrates how a bitcoin transaction is created and signed. Just pass in your own address and private key and it will prepare a transaction for you. You can then copy & paste that transaction into a webservice like Blockchain to send it. I wrote this mostly to understand better how it works. I sometimes had to "cheat" and look at t…
#!/usr/bin/env ruby
require 'open-uri'
require 'JSON'
require 'digest/sha2'
require 'pry'
require 'bigdecimal'
require 'bitcoin' # Because I need to cheat every now and then
# Usage:
# gem install pry json ffi ruby-bitcoin
@saroar
saroar / SimpleClient.swift
Created May 16, 2018 21:12 — forked from sarpsolakoglu/SimpleClient.swift
Simple Swift 4 Rest Client that uses the Codable protocol for JSON conversion
//
// SimpleClient.swift
//
// Created by Sarp Solakoglu on 18/09/2017.
// Copyright © 2017 Sarp Solakoglu. All rights reserved.
//
import Foundation
enum RestMethod: String {
@saroar
saroar / gist:9dbc233d4f0d15ad4dfcccbe74490209
Created July 24, 2018 14:09 — forked from CristinaSolana/gist:1885435
Keeping a fork up to date

1. Clone your fork:

git clone git@github.com:YOUR-USERNAME/YOUR-FORKED-REPO.git

2. Add remote from original repository in your forked repository:

cd into/cloned/fork-repo
git remote add upstream git://github.com/ORIGINAL-DEV-USERNAME/REPO-YOU-FORKED-FROM.git
git fetch upstream
@saroar
saroar / P12toPEM.txt
Created March 3, 2019 20:03 — forked from shahdhiren/P12toPEM.txt
Convert P12 file for Push Notification to PEM format
Development Phase:
Step 1: Create Certificate .pem from Certificate .p12
Command: openssl pkcs12 -clcerts -nokeys -out apns-dev-cert.pem -in apns-dev-cert.p12
Step 2: Create Key .pem from Key .p12
Command : openssl pkcs12 -nocerts -out apns-dev-key.pem -in apns-dev-key.p12
Step 3: Optional (If you want to remove pass phrase asked in second step)
Command : openssl rsa -in apns-dev-key.pem -out apns-dev-key-noenc.pem