Skip to content

Instantly share code, notes, and snippets.

View ismailmechbal's full-sized avatar

Ismail Mechbal ismailmechbal

View GitHub Profile
@ismailmechbal
ismailmechbal / rspec_model_testing_template.rb
Created November 30, 2020 12:44 — forked from SabretWoW/rspec_model_testing_template.rb
Rails Rspec model testing skeleton & cheat sheet using rspec-rails, shoulda-matchers, shoulda-callbacks, and factory_girl_rails. Pretty much a brain dump of examples of what you can (should?) test in a model. Pick & choose what you like, and please let me know if there are any errors or new/changed features out there. Reddit comment thread: http…
# This is a skeleton for testing models including examples of validations, callbacks,
# scopes, instance & class methods, associations, and more.
# Pick and choose what you want, as all models don't NEED to be tested at this depth.
#
# I'm always eager to hear new tips & suggestions as I'm still new to testing,
# so if you have any, please share!
#
# @kyletcarlson
#
# This skeleton also assumes you're using the following gems:
@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,
@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 / 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 / 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 / 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'
// 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 / 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
@ismailmechbal
ismailmechbal / nginx-tuning.md
Created May 29, 2018 13:13 — forked from denji/nginx-tuning.md
NGINX tuning for best performance

Moved to git repository: https://github.com/denji/nginx-tuning

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.