Skip to content

Instantly share code, notes, and snippets.

View Chocksy's full-sized avatar
🏠
Working from home

Ciocanel Razvan Chocksy

🏠
Working from home
View GitHub Profile
@Chocksy
Chocksy / nr_format.coffee
Created October 28, 2013 18:31
This is a simple angularjs filter that makes big numbers into short format. 1 milion becomes 1m and 1122 becomes 1.1k
@app = angular.module 'myApp', []
@app.filter "nrFormat", ->
(number) ->
if number!=undefined
console.log number
abs = Math.abs(number)
if abs >= Math.pow(10, 12)
# trillion
number = (number / Math.pow(10, 12)).toFixed(1)+"t"
else if abs < Math.pow(10, 12) and abs >= Math.pow(10, 9)
@Chocksy
Chocksy / mongo_to_sql.rb
Created January 6, 2015 10:06
Transfer MongoDB collection to SQL
# Taken from a rails app using mongoid and activrecord at the same time.
def transfer_mongo_to_sql(collection_name, fields=[])
ic = Mongoid.default_session.collections.select { |c| c.name==collection_name }.first
total_items = ic.find.count
per_batch = 1000
0.step(total_items, per_batch) do |offset|
to_fields = fields.map { |c| c[:to_name] }.join(', ')
insert_raw_sql = "INSERT INTO #{collection_name} (#{to_fields}) VALUES "
before = Time.now
@Chocksy
Chocksy / searchkick_reindex_resume.rb
Last active September 5, 2023 06:46
Searchkick reindex with resume
namespace :searchkick do
desc "maybe reindex without running out of memory?"
task :altindex, [:start_index, :batch_size, :new_index_name] => :environment do |t, args|
ActiveRecord::Base.logger = Logger.new(STDOUT)
count = Item.count
start = args[:start_index].to_i || 0
batch_size = args[:batch_size].to_i || 1000
# we create a new index or take one already present
if args[:new_index_name]
@Chocksy
Chocksy / touchscreen-debian-fix.sh
Last active August 15, 2020 05:54
Fix for Elo Touchscreen on debian
# Some interesting python script:
# https://raw.githubusercontent.com/adafruit/PiTFT_Extras/master/pitft_touch_cal.py
# > sudo add-apt-repository ppa:tias/xinput-calibrator-ppa
> sudo apt-get update && sudo apt-get install xinput-calibrator
> apt-get install xinput
> export DISPLAY=:0.0
> xinput list-props "EloTouchSystems,Inc Elo TouchSystems 2216 AccuTouch® USB Touchmonitor Interface"
> xinput set-prop "EloTouchSystems,Inc Elo TouchSystems 2216 AccuTouch® USB Touchmonitor Interface" "Evdev Axis Inversion" 0 1
# here touch the points on the screen in the corners
> xinput_calibrator --output-type xinput
@Chocksy
Chocksy / .1details.md
Last active April 9, 2020 16:26
Gemfile local that will allow for special gems only on local env

Differences between team gemfile and your preferences

The solution for the above problem is to have a different gemfile that you run your rails app against. It can be easily done by adding some terminal aliases to use a different gemfile file. I made that in the current configuration and it works well.

@Chocksy
Chocksy / track_spec.rb
Created July 13, 2016 17:51
Temporary disable verify_partial_doubles
it 'tracks and event', verify_partial_doubles: false do
expect_any_instance_of(Analytics).to receive(:track) do |_o, options|
expect(options).to include(event: 'invited user')
expect(options[:properties]).to include(organization: organization.name)
end
post_with owner, :create_invites, params
end
@Chocksy
Chocksy / precompile_assets.rb
Created September 7, 2016 11:40
Precompile js files in rails
# use this file in the rails app root directory and run it with
# ruby precompile_assets.rb to see if there is any error in your
# js file assets by using Uglifier. This would save you from running
# rake assets:precompile and using production as env var.
require './config/environment'
JS_PATH = 'app/assets/javascripts/**/*.js'.freeze
Dir[JS_PATH].each do |file_name|
puts "\n#{file_name}"
puts Uglifier.compile(File.read(file_name))
@Chocksy
Chocksy / details.md
Last active March 26, 2018 11:29
Atom Editor make linter-rubocop work.

In order for atom.io to work and use the linter-rubocop on all projects, you need to install rubocop in your global rvm gemset. This can be done by running sudo gem install rubocop in a folder where you don't have a gemset set for rvm.

After doing the above you can just use the following command to make rubocop work in any project:

rvm use 2.2.1@global rubocop do --config /Users/username/development/.rubocop.yml
@Chocksy
Chocksy / keybase.md
Created May 12, 2017 07:48
Keybase key

Keybase proof

I hereby claim:

  • I am chocksy on github.
  • I am chocksy (https://keybase.io/chocksy) on keybase.
  • I have a public key ASBvEeMzFwcVcTJuReETgNhjWE-ZwPxiU5Nl0hd1ewS8Two

To claim this, I am signing this object:

@Chocksy
Chocksy / insecure-markdown.md
Last active October 17, 2019 11:17
Insecure markdown examples that should be tested.