Skip to content

Instantly share code, notes, and snippets.

@nontone
nontone / 0_howto_install_phantomjs.md
Created May 13, 2018 18:01 — forked from julionc/00.howto_install_phantomjs.md
How to install PhantomJS on Debian/Ubuntu

How to install PhantomJS on Ubuntu

Version: 1.9.8

Platform: x86_64

First, install or update to the latest system software.

sudo apt-get update
sudo apt-get install build-essential chrpath libssl-dev libxft-dev
@nontone
nontone / blockchain.rb
Last active November 6, 2017 07:42 — forked from chrisallick/blockchain.rb
tiny blockchain in ruby
# https://medium.com/crypto-currently/lets-build-the-tiniest-blockchain-e70965a248b
# http://ruby-for-beginners.rubymonstas.org/writing_classes/self.html
# https://stackoverflow.com/questions/33768598/ruby-sha-256-hexidigest-values-are-different-from-what-python-generates
require 'rubygems'
require 'digest'
class Block
def initialize(index, timestamp, data, previous_hash)
@index = index
@nontone
nontone / ssh-git-config.rb
Last active July 24, 2017 14:00
ssh-git config
# ~/.ssh/config
Host bitbucket-apple
Hostname bitbucket.org
User git
IdentityFile ~/.ssh/apple
Host bitbucket-orange
Hostname github.com
User git
IdentityFile ~/.ssh/orange
# if-else
user = { age: 17, status: 'active' }
if user[:status] == 'active'
user[:age] >= 18 ? 'allowed' : 'not allowed'
else
user[:age] >= 18 ? 'ok' : 'no'
end
# hash
status = user[:status] == 'active' ? :active : :inactive
@nontone
nontone / form.js
Last active February 16, 2017 04:51
redux-form: FieldArray
import React, { Component } from 'react';
import { FieldArray, reduxForm } from 'redux-form';
import RenderItem from './render-item';
class Form extends Component {
renderItems = ({ fields }) => {
{
fields.map((field, i) =>
<RenderItem
key={`condition-${i}`}
@nontone
nontone / polymorph_belongs_to.rb
Last active November 11, 2016 12:03
Polymorphic nested with belongs_to
class Collection < ActiveRecord::Base
has_many :collectings
accepts_nested_attributes_for :collectings, allow_destroy: true
end
class Collecting < ActiveRecord::Base
COLLECTABLE = [:category, :product].freeze
belongs_to :collection
belongs_to :collectable, polymorphic: true
@nontone
nontone / facebook-init.coffee
Last active September 14, 2016 10:52
Rails Facebook login with Facebook Javascript SDK
# I got this script from turbolinks compatibility
#
# reed.github.io/turbolinks-compatibility
$ ->
loadFacebookSDK()
bindFacebookEvents() unless window.fbEventsBound
bindFacebookEvents = ->
$(document)
@nontone
nontone / simplifying_has_many_through.rb
Last active May 15, 2016 22:13 — forked from thomasklemm/simplifying_has_many_through.rb
Simplifying a has_many :through (ActiveRecord / Rails). Also a useful boilerplate sharing complex ActiveRecord scenarios.
# Run this script with `$ ruby has_much_fun.rb`
require 'sqlite3'
require 'active_record'
# Use `binding.pry` anywhere in this script for easy debugging
require 'pry'
# Connect to an in-memory sqlite3 database
ActiveRecord::Base.establish_connection(
adapter: 'sqlite3',
@nontone
nontone / application_controller.rb
Last active August 29, 2015 14:23
Devise sign in for two session
# controllers/admin/application_controller.rb
class Admin::ApplicationController < ApplicationController
before_action :authenticate_admin!
layout 'admin'
end
@nontone
nontone / gist:0ad63511a846369146b1
Created May 8, 2015 07:27
update ssl cert file and fix
# SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed
export $SSL_CERT_FILE=/usr/local/etc/openssl/cert.pem
curl http://curl.haxx.se/ca/cacert.pem -o $SSL_CERT_FILE
curl http://curl.haxx.se/ca/cacert.pem -o /usr/local/etc/openssl/cert.pem