Skip to content

Instantly share code, notes, and snippets.

View BitOfUniverse's full-sized avatar

Alexey Nikolaev BitOfUniverse

View GitHub Profile
@soheilhy
soheilhy / nginxproxy.md
Last active May 7, 2024 14:55
How to proxy web apps using nginx?

Virtual Hosts on nginx (CSC309)

When hosting our web applications, we often have one public IP address (i.e., an IP address visible to the outside world) using which we want to host multiple web apps. For example, one may wants to host three different web apps respectively for example1.com, example2.com, and example1.com/images on the same machine using a single IP address.

How can we do that? Well, the good news is Internet browsers

@hopsoft
hopsoft / db.rake
Last active May 6, 2024 14:00
Rails rake tasks for dump & restore of PostgreSQL databases
# lib/tasks/db.rake
namespace :db do
desc "Dumps the database to db/APP_NAME.dump"
task :dump => :environment do
cmd = nil
with_config do |app, host, db, user|
cmd = "pg_dump --host #{host} --username #{user} --verbose --clean --no-owner --no-acl --format=c #{db} > #{Rails.root}/db/#{app}.dump"
end
puts cmd
@philfreo
philfreo / gist:0a4d899de4257e08a000
Created August 22, 2014 21:38
4 different ways to save a Highcharts chart as a PNG (with and without a server)
// Method 1: simply use Highcharts built-in functionality (SVG -> Highcharts server -> PNG)
// Downside: won't work in webview native apps that don't handle the form response
highcharts.exportChart({
filename: filename
});
@imranismail
imranismail / queue.ex
Created April 10, 2017 08:24
Elixir Wrapper for Erlang Queue module
defmodule Queue do
def insert(queue, item), do: :queue.in(item, queue)
def insert_last(queue, item), do: :queue.in_r(item, queue)
def member?(queue, item), do: :queue.member(item, queue)
def filter(queue, fun), do: :queue.filter(fun, queue)
def split(queue, n) do
@basti
basti / application.rb
Last active March 1, 2021 10:42 — forked from keighl/application.rb
Local Rails 4 assets precompilation using Capistrano 3 and rsync
# Speed things up by not loading Rails env
config.assets.initialize_on_precompile = false
@nanne007
nanne007 / loop.ex
Created July 22, 2016 15:34
loop, while,break construct in elixir
defmodule Loop do
defmacro while(predicate, do: block) do
quote do
try do
for _ <- Stream.cycle([:ok]) do
if unquote(predicate) do
unquote(block)
else
throw :break
end
@henrik
henrik / application_controller.rb
Last active December 19, 2017 11:39
Convenient `locals` renderer for Rails. Don't use ivars if you can help it. http://thepugautomatic.com/2013/05/locals/
class ApplicationController < ActionController::Base
# stuff
private
# These groups are equivalent:
#
# render action: :new, locals: { item: x }
# render :new, locals: { item: x }