Skip to content

Instantly share code, notes, and snippets.

@LolWalid
LolWalid / rot_13.rb
Created December 13, 2017 20:59
Paris Workshop ROT 13
class EncryptionEngine
def self.encrypt(string)
results = ''
string.each_char do |l|
results += rot(l)
end
results
end
def self.decrypt(string)
@LolWalid
LolWalid / beer_song.rb
Created December 13, 2017 19:34
Solve Ruby Woskhop BeerSong
class BeerSong
def verse(nb_bottle)
s = "#{pluralize(nb_bottle, capitalize: true)} of beer on the wall, #{pluralize(nb_bottle)} of beer.\n"
s + if nb_bottle == 0
"Go to the store and buy some more, 99 bottles of beer on the wall.\n"
else
"Take #{it_or_one(nb_bottle - 1)} down and pass it around, #{pluralize(nb_bottle - 1)} of beer on the wall.\n"
end
end
@LolWalid
LolWalid / UserSearch.rb
Last active October 30, 2017 13:41
Elastic Search UserSearch, friends and full name
# See link below to know all possible filters
# https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl.html
class UserSearch
def initialize(user, string_query)
@user = user
@string_query = string_query
end
def search
@LolWalid
LolWalid / catchMemoryLeak.java
Last active August 29, 2017 12:18
Android Tricks
// https://medium.com/freenet-engineering/memory-leaks-in-android-identify-treat-and-avoid-d0b1233acc8
@LolWalid
LolWalid / complex_condition.md
Last active October 17, 2019 21:22
ElasticSearch queries

where (condition1 && condition2) || (condition3 && condition4)

Example: where (place.type = 'Restaurant' and place.kind = 'Chinese') or (place.type = 'Bar' and place.kind in ('beer','wine'))

{
  query: {
    bool: {
      should: [
        {

bool: {

@LolWalid
LolWalid / git_prune.md
Created June 23, 2017 11:30
Remove merged branch locally

Remove branch that are no longer being referenced

git remote prune origin

Remove merged branch

git branch --merged | egrep -v "(^\*|master|dev)" | xargs git branch -d

@LolWalid
LolWalid / controller.rb
Last active October 4, 2016 21:36
Mutiple model devise
# app/controllers/admin
class Admin::PostController < ActionController::Base
before_action :authenticate_admin!
def index
@posts = Post.all
end
def switch_user
@LolWalid
LolWalid / my_class.rb
Last active July 25, 2022 08:01
How to make private static method in ruby.
class MyClass
def self.public
"I'm public."
end
private # this is useless
def self.private
"I'm also public."
end
@LolWalid
LolWalid / main.rb
Created May 27, 2016 16:41
Sudoku Solver in ruby Langage
require 'sudoku'
require 'sudoku_solver'
data = [
[9, 3, 4, 1, 7, 2, 6, 8, 5],
[0, 0, 5, 0, 9, 0, 2, 0, 1],
[8, 0, 0, 0, 4, 0, 0, 0, 0],
[0, 0, 0, 0, 8, 0, 0, 0, 0],
[0, 0, 0, 7, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 2, 6, 0, 0, 9],
{
"detect_indentation": false,
"draw_white_space": "all",
"ensure_newline_at_eof_on_save": true,
"folder_exclude_patterns":
[
".svn",
".git",
".hg",
"CVS",