Skip to content

Instantly share code, notes, and snippets.

View patriciojofre's full-sized avatar
🇨🇱

Pato Jofre patriciojofre

🇨🇱
View GitHub Profile
@chadwilken
chadwilken / async_reindex_status.rb
Created June 23, 2022 14:56
Searchkick Async Workflow
module Searchkick
class AsyncReindexStatus
include Redis::Objects
def id
'searchkick-async-reindex-status'
end
list :currently_reindexing
end
@Jswizzy
Jswizzy / InstallingSwift.md
Last active February 26, 2024 12:04
Swift Install Instruction 20.04

Installing Swift on Ubuntu 20.04

1. Install Depencies

“clang”[ˈklæŋ] is the compiler based on LLVM for C, C++, Objective-C, and Objective-C++. clang is needed to install in order to Swift. Run the following code in Ubuntu terminal.

Before installing swift “libpython2.7” and “libpython2.7-dev” are needed to get Swift running. Run the following code.

@jcrisp
jcrisp / handle_bad_encoding_middleware.rb
Last active June 10, 2020 14:43
HandleBadEncodingMiddleware
class HandleBadEncodingMiddleware
def initialize(app)
@app = app
end
def call(env)
begin
Rack::Utils.parse_nested_query(env['QUERY_STRING'].to_s)
rescue Rack::Utils::InvalidParameterError
env['QUERY_STRING'] = ''
@Chocksy
Chocksy / kill_sidekiq_job.rb
Last active April 25, 2024 14:07
Kill sidekiq jobs by process id for busy jobs and by jid for other sets.
# FOR BUSY JOBS
# take the process_id from the /busy page in sidekiq and kill the longest running one.
workers = Sidekiq::Workers.new
long_process_id = 'integration.3:4:71111aaa111' # Eg: 'integration.3:4:71d1d7f4ef5a'
workers.each do |process_id, thread_id, work|
process = Sidekiq::Process.new('identity' => process_id)
process.stop! if process_id == long_process_id
end
# FOR SCHEDULED JOBS
@satoruk
satoruk / app.rb
Last active May 13, 2022 02:26
Custom logger on Sinatra
class App < Sinatra::Base
configure do
set :logger_level, :warn
set :logger_log_file, File.join(root, 'log', "#{environment}.log")
end
configure :development do
set :logger_level, :debug
end
@riggaroo
riggaroo / MainActivity.java
Last active July 15, 2020 12:30
Online Presence with Firebase and Android based off article https://firebase.googleblog.com/2013/06/how-to-build-presence-system.html . Read the article as it explains the whole .onDisconnect().removeValue() nicely.
private void initialiseOnlinePresence() {
final DatabaseReference onlineRef = databaseReference.child(".info/connected");
final DatabaseReference currentUserRef = databaseReference.child("/presence/" + userId);
onlineRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(final DataSnapshot dataSnapshot) {
Log.d(TAG, "DataSnapshot:" + dataSnapshot);
if (dataSnapshot.getValue(Boolean.class)){
currentUserRef.onDisconnect().removeValue();
currentUserRef.setValue(true);
@pboling
pboling / PhantomJS Install.md
Last active July 23, 2019 17:54
How to install old PhantomJS 1.8.2 on Mac OS X
@deanhume
deanhume / fetch-api-post.js
Created August 19, 2015 10:48
A simple POST request using the fetch API
fetch(url, {
method: 'POST',
headers: {
'auth': '1234'
},
body: JSON.stringify({
name: 'dean',
login: 'dean',
})
})
@JeffBelback
JeffBelback / docker-destroy-all.sh
Last active December 12, 2023 17:47
Destroy all Docker Containers and Images
#!/bin/bash
# Stop all containers
containers=`docker ps -a -q`
if [ -n "$containers" ] ; then
docker stop $containers
fi
# Delete all containers
containers=`docker ps -a -q`
if [ -n "$containers" ]; then
docker rm -f -v $containers
@oojikoo-gist
oojikoo-gist / STI.md
Created April 17, 2015 03:20
rails: STI(Single Table Inheritance)

Single Table inheritance

reference: blog.thirst.co

In a nutshell, STI allows you to create subclasses of a particular database table. Using a single table, you can cast rows to specific objects that extend the base model.

how to create STI relationships in Rails

Lets say we have a model Computer