Skip to content

Instantly share code, notes, and snippets.

@pshoukry
pshoukry / Dockerfile
Last active April 13, 2017 08:56
SSH-Tunnel to mysql ( RDS or normal mysql instance) from rails application
FROM buildpack-deps:jessie
ADD . /root/.ssh
RUN chown -R root:root /root/.ssh
RUN apt-get update
RUN apt-get install -y mysql-client socat
expose 3306
CMD socat tcp-l:3306,fork,reuseaddr tcp:127.0.0.1:3307 & ssh -N frontend
@pshoukry
pshoukry / api.js
Created March 6, 2017 14:18
React / Redux fetch from rails server with CSRF token
import _ from 'underscore';
import fetch from 'isomorphic-fetch'
class API {
getCSRFToken() {
return _.find(document.getElementsByTagName('meta'), (meta) => {
return meta.name === 'csrf-token'
}).content
}
class CB
def self.flatten(arr)
flat_array = []
arr.each do |e|
if e.is_a?(Array)
CB.flatten(e).each {|se| flat_array << se }
else
flat_array << e
end
end
@pshoukry
pshoukry / gist:df23697b747f3c4ca3cc
Last active October 26, 2015 19:29
Updates rails official docker image to latest gems
docker run --name rails_updated -v "$PWD":/usr/src/rp -w /usr/src/rp rails/updated gem install minitest:5.8.1 json:1.8.3 \
debug_inspector:0.0.2 binding_of_caller:0.7.2 byebug:6.0.2 coffee-script-source:1.9.1.1 execjs:2.6.0 coffee-script:2.4.1 \
coffee-rails:4.1.0 multi_json:1.11.2 jbuilder:2.3.2 jquery-rails:4.0.5 sass:3.4.19 tilt:2.0.1 sass-rails:5.0.4 sdoc:0.4.1 \
spring:1.4.0 sqlite3:1.3.11 turbolinks:2.5.3 uglifier:2.7.2
docker commit rails_updated rails/updated && docker rm rails_updated
@pshoukry
pshoukry / webcrawler.go
Last active August 29, 2015 14:11
golang - Go tour - exercise solution - webcrawler
package main
import (
"fmt"
)
type Fetcher interface {
Fetch(url string) (body string, urls []string, err error)
}