Skip to content

Instantly share code, notes, and snippets.

View skycocker's full-sized avatar

Michał Siwek skycocker

  • Kraków, Poland
View GitHub Profile
@skycocker
skycocker / factories_spec.rb
Created June 6, 2021 15:35
A simple rspec factory validator
require 'rails_helper'
FactoryBot.factories.each do |factory|
describe "The #{factory.name} factory" do
it 'is valid' do
expect(build(factory.name)).to be_valid
end
describe 'traits' do
factory.defined_traits.each do |trait|
@skycocker
skycocker / image_uploadable.rb
Last active March 3, 2020 17:35
Uploading images to a Rails API using Paperclip (via either base64 string-encoded image or a public HTTP image URL)
module ImageUploadable
extend ActiveSupport::Concern
private
def set_image_by_params_for(model, params)
image_uri = params[:image_uri]
image_base64 = params[:image_base64]
set_image_from_uri_for(model, image_uri) if image_uri.present?
@skycocker
skycocker / nginx-noscript.conf
Created August 10, 2018 17:51
Fixed version of the default nginx/apache-noscript.conf file, considering you might have something else than simply a filename in the matching string
[Definition]
failregex = ^<HOST> -.*GET(?!.*\?.*\=) .*(\.php|\.asp|\.exe|\.pl|\.cgi|\.scgi)
ignoreregex =
@skycocker
skycocker / passwords_controller.rb
Created July 2, 2018 12:14
Add Location header clone for Alamofire + devise_token_auth password reset flow
class Auth::PasswordsController < DeviseTokenAuth::PasswordsController
def edit
super
# Alamofire tends to ignore Location header in .allHeaderFields, blindly following its contents instead
# so we add a new header with the same value
# in order to parse it in mobile app
response.headers['Alamofire-Location'] = response.headers['Location']
end
end
@skycocker
skycocker / Gemfile
Last active March 30, 2024 13:32
Get basic user info from Google Oauth V2 api (since google is an extraordinary piece of shit when it comes to documenting their stuff) (or making admin consoles)
gem 'google-api-client'
@skycocker
skycocker / enable_swap.sh
Last active June 9, 2021 14:52
Enable 1G swap space on ubuntu (or pretty much any other linux distro) - useful on small Amazon/Digitalocean instances
sudo fallocate -l 1G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
sudo swapon --show
sudo cp /etc/fstab /etc/fstab.bak
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
sudo sysctl vm.swappiness=10
echo 'vm.swappiness=10' | sudo tee -a /etc/sysctl.conf
sudo sysctl vm.vfs_cache_pressure=50
<div id="the-basics">
<input class="typeahead" type="text" placeholder="States of USA">
</div>
@skycocker
skycocker / gist:7074415
Last active December 26, 2015 01:49
test_frontend.log
{"level":"info","message":"process type is test_frontend","timestamp":"2013-10-20T19:48:37.935Z"}
{"date":"Sun Oct 20 2013 21:48:37 GMT+0200 (CEST)","process":{"pid":10301,"uid":1000,"gid":1000,"cwd":"/home/skycocker/Desktop/browserid","execPath":"/usr/local/bin/node","version":"v0.10.21","argv":["node","/home/skycocker/Desktop/browserid/scripts/test_frontend"],"memoryUsage":{"rss":18509824,"heapTotal":15453568,"heapUsed":7987892}},"os":{"loadavg":[1.8203125,1.7841796875,1.77001953125],"uptime":3959.078639706},"trace":[{"column":11,"file":"child_process.js","function":"errnoException","line":980,"method":null,"native":false},{"column":34,"file":"child_process.js","function":"Process.ChildProcess._handle.onexit","line":771,"method":"ChildProcess._handle.onexit","native":false}],"stack":["Error: spawn ENOENT"," at errnoException (child_process.js:980:11)"," at Process.ChildProcess._handle.onexit (child_process.js:771:34)"],"level":"error","message":"uncaughtException: spawn ENOENT","timestamp":"2013-10-20
@skycocker
skycocker / whistle_analyser.js
Created October 7, 2013 20:36
Whistle.js analyser snippet
var frequencies = new Uint8Array(analyser.frequencyBinCount);
analyser.getByteFrequencyData(frequencies);
for(var i=25; i<=80; ++i) {
if(frequencies[i] > 250) document.dispatchEvent(whistleEvent);
}
@skycocker
skycocker / vim.rb
Created September 28, 2013 23:30
Chromebrew package file example
require 'package' # include package class file
class Vim < Package # name the package and make it a Package class instance
version '7.4' # software version
source_url 'ftp://ftp.vim.org/pub/vim/unix/vim-7.4.tar.bz2' # software source tarball url
source_sha1 '601abf7cc2b5ab186f40d8790e542f86afca86b7' # source tarball sha1 sum
depends_on 'ncurses' # software dependencies
def self.build # self.build contains commands needed to build the software from source