Skip to content

Instantly share code, notes, and snippets.

View obahareth's full-sized avatar
🧭
Building Bousla

Omar Bahareth obahareth

🧭
Building Bousla
View GitHub Profile

Keybase proof

I hereby claim:

  • I am obahareth on github.
  • I am obahareth (https://keybase.io/obahareth) on keybase.
  • I have a public key whose fingerprint is CAB8 5952 5444 8B43 F4F2 0615 BFFD 1B8F 549C C61D

To claim this, I am signing this object:

@obahareth
obahareth / old_algolia_delete_by_query.rb
Created August 25, 2017 15:51
Old version of Algolia's Ruby Client delete_by_query method
#
# Delete all objects matching a query
#
# @param query the query string
# @param params the optional query parameters
#
def delete_by_query(query, params = nil)
raise ArgumentError.new('query cannot be nil, use the `clear` method to wipe the entire index') if query.nil? && params.nil?
params ||= {}
params.delete(:hitsPerPage)
@obahareth
obahareth / README.md
Created June 11, 2017 10:29
GitHub GraphQL API Starred Repositories With Pagination

GitHub GraphQL API Starred Repositories Examples With Pagination

You can play with the GraphQL API live here. It's pretty nice and has autocompletion based on the GraphQL schema.

The first example gets your first 3 starred repos, the cursor values can be used for pagination.

Here's an example response from the first query:

{
@obahareth
obahareth / Gemfile
Created January 26, 2017 21:05 — forked from goncalvesjoao/Gemfile
Changes you need to make in order to make Devise use JWT Header Authentication
# Add the "https://github.com/jwt/ruby-jwt" gem to your "Gemfile"
gem 'jwt'
@obahareth
obahareth / parse_and_index_pdf.rb
Last active January 3, 2021 13:47
Using Tika through Yomu to turn a PDF into nicely formatted HTML, parsing the HTML using Nokogiri, and then using Algolia to get the PDF contents indexed and searchable. See https://medium.com/@obahareth/indexing-pdf-or-other-file-contents-for-searching-b2499c23568f
require "nokogiri"
require "yomu"
require "algoliasearch"
def invalid_paragraph?(str)
disallowed_strings = [ "", " ", "\n", " \n" ]
disallowed_strings.include?(str)
end
def get_pdf_paragraphs(filename)
@obahareth
obahareth / Playing with NLTK and Stanford NER.md
Last active October 23, 2020 11:04
Playing around with NER using Stanford's NER and NLTK

Description

I'm playing around with NER (Named Entity Recognition) and the basic idea is that I can pass in multiple paragraphs and get recognized entities in a nicely formatted dictionary of lists.

I might look into running the Java servelet that stanford made to increase performance.

Example Output

{
  'organizations': ['Wall', 'Street', 'Journal', 'Apple', 'Inc.', 'Apple', 'TV', 'Apple', 'Mac', 'App', 'Store', 'Apple', 'Computer', ',', 'Inc.', 'Apple', 'Inc.', 'National', 'Hockey', 'League', 'Montreal', 'Canadiens', 'Stanley', 'Cups', 'Toronto', 'Blue', 'Jays'],
 'locations': ['France', 'Cupertino', 'California'],
@obahareth
obahareth / resizer.rb
Last active October 23, 2015 10:11
Resize Images Using MiniMagick While Preserving Subdirectory Structure
require 'fileutils'
require 'mini_magick'
# Get all files of any type within the 4x folder, within any subdirectory
sources = Dir.glob(File.join('**', '4x', '**', '*.png'))
# Create our target directories, and the size factor for that directory
target_directories = [
{ name: '2x', size_factor: 0.5 },
{ name: '1x', size_factor: 0.25 }
@obahareth
obahareth / speed_up_terminal_launch.sh
Last active March 17, 2024 00:30
Speed up launch of Terminal or iTerm 2
# Apparently Apple keeps system logs in this folder as .asl files. They're
# loaded into terminal sessions and can slow things down when there's a lot of
# them.
#
# Taken from:
# https://ariejan.net/2011/11/08/fixing-a-slow-starting-terminal-or-iterm2-on-mac-os-x/
sudo rm /private/var/log/asl/*.asl
@obahareth
obahareth / setup_os_x.sh
Last active June 28, 2025 04:51
A script to setup OS X with the apps and formulas I use.
# Install Homebrew
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew doctor
# Tap sources we need
brew tap homebrew/dupes
brew tap homebrew/versions
brew tap homebrew/homebrew-php
brew tap caskroom/versions
@obahareth
obahareth / 0_reuse_code.js
Created August 29, 2014 07:36
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console