Skip to content

Instantly share code, notes, and snippets.

View ismailmechbal's full-sized avatar

Ismail Mechbal ismailmechbal

View GitHub Profile
@ismailmechbal
ismailmechbal / .rubocop.yml
Created June 8, 2017 21:27 — forked from jhass/.rubocop.yml
My preferred Rubocop config
AllCops:
RunRailsCops: true
# Commonly used screens these days easily fit more than 80 characters.
Metrics/LineLength:
Max: 120
# Too short methods lead to extraction of single-use methods, which can make
# the code easier to read (by naming things), but can also clutter the class
Metrics/MethodLength:
@ismailmechbal
ismailmechbal / ahoy_base.rb
Created June 19, 2017 15:21 — forked from jabbett/ahoy_base.rb
Setting up Ahoy models to use a separate datastore
module Ahoy
class AhoyBase < ActiveRecord::Base
establish_connection DB_STATS
self.abstract_class = true
end
end
@ismailmechbal
ismailmechbal / nginx-tuning.md
Created May 29, 2018 13:13 — forked from denji/nginx-tuning.md
NGINX tuning for best performance

NGINX Tuning For Best Performance

For this configuration you can use web server you like, i decided, because i work mostly with it to use nginx.

Generally, properly configured nginx can handle up to 400K to 500K requests per second (clustered), most what i saw is 50K to 80K (non-clustered) requests per second and 30% CPU load, course, this was 2 x Intel Xeon with HyperThreading enabled, but it can work without problem on slower machines.

You must understand that this config is used in testing environment and not in production so you will need to find a way to implement most of those features best possible for your servers.

@ismailmechbal
ismailmechbal / fbLinksGrabber.py
Created September 6, 2018 06:51 — forked from psychemedia/fbLinksGrabber.py
Grab likes et al for members of a Facebook group.
#This is a really simple script:
##Grab the list of members of a Facebook group (no paging as yet...)
#Lets you do things like http://blog.ouseful.info/2012/12/05/emergent-social-interest-mapping-red-bull-racing-facebook-group/
###For each member, try to grab their Likes
#USAGE
#> python fbLinksGrabber.py -group GROUPID -typ THING -FBTOKEN ETC
#THING is one of groups, likes, books etc
// PhantomJS Cheatsheet
$ brew update && brew install phantomjs // install PhantomJS with brew
phantom.exit();
var page = require('webpage').create();
page.open('http://example.com', function() {});
page.evaluate(function() { return document.title; });
@ismailmechbal
ismailmechbal / book.rb
Created March 7, 2019 14:30 — forked from sirupsen/book.rb
Script to import books from Instapaper to Airtable. Will not work out of the box.
class Book < Airrecord::Table
class Endorser < Airrecord::Table
self.base_key = ""
self.table_name = "Endorser"
end
self.base_key = ""
self.table_name = "Books"
has_many :endorsements, class: 'Book::Endorser', column: 'Endorsements'
@ismailmechbal
ismailmechbal / rails-jsonb-queries
Created March 23, 2019 15:19 — forked from mankind/rails-jsonb-queries
Rails-5 postgresql-9.6 jsonb queries
http://stackoverflow.com/questions/22667401/postgres-json-data-type-rails-query
http://stackoverflow.com/questions/40702813/query-on-postgres-json-array-field-in-rails
#payload: [{"kind"=>"person"}]
Segment.where("payload @> ?", [{kind: "person"}].to_json)
#data: {"interest"=>["music", "movies", "programming"]}
Segment.where("data @> ?", {"interest": ["music", "movies", "programming"]}.to_json)
Segment.where("data #>> '{interest, 1}' = 'movies' ")
Segment.where("jsonb_array_length(data->'interest') > 1")
@ismailmechbal
ismailmechbal / rails_webpacker_bootstrap_expose_jquery.md
Created March 24, 2019 06:09 — forked from andyyou/rails_webpacker_bootstrap_expose_jquery.md
Rails 5.2 with webpacker, bootstrap, stimulus starter

Rails 5.2 with webpacker, bootstrap, stimulus starter

This gist will collects all issues we solved with Rails 5.2 and Webpacker

Create Project

# Last few parameters(--skip-* part) is only my habbit not actully required
$ rails new <project_name> --webpack=stimulus --database=postgresql --skip-coffee --skip-test
@ismailmechbal
ismailmechbal / svenska_stader.json
Created August 21, 2019 15:57 — forked from timbillstrom/svenska_stader.json
Svenska städer organiserade i objekt för deras respektive län. (Vissa slugs är ej hela)
{
"blekinge": [
"Blekinge",
{
"name": "Karlshamn",
"slug": "karlshamn"
},
{
"name": "Karlskrona",
"slug": "karlskrona"
@ismailmechbal
ismailmechbal / example.rb
Created June 13, 2020 07:11 — forked from skunkworker/append_json_column_rails_5.rb
How to append to a json column array in Rails 5.
# assuming Model is your model and options is a json/jsonb column.
# This uses the Postgres json append || operator.
# And wraps the option inside an array.
# producing [{},{}] multiple hashes inside a top level json array.
# It is very important that the hash is [{}] NOT {} as not having the array on the
# outside will cause the hash to replace the contents instead of appending to them.
new_option = [{
name: option_name,