Skip to content

Instantly share code, notes, and snippets.

View AvnerCohen's full-sized avatar
🌍
Working from home

Avner Cohen AvnerCohen

🌍
Working from home
View GitHub Profile
@AvnerCohen
AvnerCohen / event_machine_sockets.rb
Created February 22, 2015 16:25
event machine + http event machine + em websocket, memory leaking like mad !!
require 'bundler'
require 'socket'
Bundler.require
WS_CLIENTS = {}
WS_CLIENTS_NAME_TO_SOCKET = {}
WS_HOST = Socket.ip_address_list.last.ip_unpack.first)
WS_PORT = 8090
HTTP_PORT = WS_PORT + 1
@AvnerCohen
AvnerCohen / deploy.sh
Last active August 29, 2015 14:18 — forked from remy/deploy.sh
#!/bin/bash
readonly ARGS="$@"
readonly DEPLOY_USER="www-data"
clone_repo_at_tag() {
local repo="$1"
local tag="$2"
local project_name="$3"
local repo_dirname="$project_name-$tag"
@AvnerCohen
AvnerCohen / html5.html
Created October 23, 2012 09:51
HTML5 starting point template
<!doctype html>
<html lang="en-us">
<head>
<title>
[your title]
</title>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge, chrome=1" />
<link rel="stylesheet" href="" />
<meta name="viewport" content="width=device-width">
@AvnerCohen
AvnerCohen / html5_in_zen
Created October 29, 2012 11:31
HTML5 boilerplate in zencoding
html:5>#wrapper>((header>((#logo>img)+h1+nav>ul>li*3))+(#body>header>h2+p)+(footer>p))*1
>> Now hit tab to get it to expand
@AvnerCohen
AvnerCohen / resque_control.sh
Created June 13, 2013 15:49
Control Resque via BASH / Shell / Command line, the various rake tasks out there does not seem to do the job clean enough run as, added code to specifically take advantage of the already present resque.yml configuration file: ./resque_control.sh start
#!/bin/bash
echo "Executing Resque Manager."
start() {
echo -n "Starting resque..."
RAILS_ENV="$TARGET_ENV" QUEUE="v2_processing" VERBOSE="1" nohup bundle exec rake environment resque:work --trace > ./log/resque.log &
return
}
stop() {
@AvnerCohen
AvnerCohen / append_to_set.js
Created July 25, 2013 08:41
Trying to understand how to create a Mongo document, in a nodeJS environment with upsert and $set in the same flow
var MongoClient = require('mongodb').MongoClient;
MongoClient.connect('mongodb://127.0.0.1:27017/inbox', function(err, db) {
if (err) throw err;
var collection = db.collection('test_insert');
var sample1 = { 'messages.82513': { body: '123\r\n456\r\n789\r\n', db_msg_id: '82513' } };
var sample2 = { 'messages.12': { body: '123\r\n456\r\n789\r\n', db_msg_id: '12'} };
var base_doc = { conv_hash: '711_34401', messages: {} };
//## FAILS ##
@AvnerCohen
AvnerCohen / doc.rb
Last active December 28, 2015 22:09
Read, Write and Upsert in mongoid, run: RACK_ENV=development ruby doc.rb
require 'mongoid'
Mongoid.load!("./mongoid.yml")
Mongoid.raise_not_found_error = false
class Doc
include Mongoid::Document
store_in collection: "testing123"
field :name, type: Integer
field :_id, type: Integer, default: ->{ name }
@AvnerCohen
AvnerCohen / git_aliases_setup.sh
Last active January 9, 2016 21:10
Random Git aliases and commands to
# Command: GLOG
# Description: alias that creates a nice and easy on eye history log with graph indication of merge commits and branches
git config --global alias.glog "\!git log --graph --pretty=format:'%Cred%h%Creset %an: %s - %Creset %C(yellow)%d%Creset %Cgreen(%cr)%Creset' --abbrev-commit --date=relative ; true"
# Run:
git glog
# Command: LASTWORKS
# Description: Lists the last 10 branches you worked on
git config --global alias.lastworks "for-each-ref --count=10 --sort=-committerdate refs/heads/"
@AvnerCohen
AvnerCohen / get_all_database_indexes_from_mongo.js
Created February 22, 2016 15:39
A script to print out all the indexes in all database of mongo
var db = db.getSiblingDB("admin");
var dbs = db.runCommand({ "listDatabases": 1 }).databases.sort();
dbs.forEach(function(database) {
db = db.getSiblingDB(database.name);
cols = db.getCollectionNames().sort();
cols.forEach(function(col) {
if (!db[col]) { return; }
db[col].getIndexes().sort().forEach(function(index) {
if ("_id_" !== index.name) {
print("at database: [" + database.name +"], db." + col + ".ensureIndex(" + tojson(index.key) + ")");
@AvnerCohen
AvnerCohen / delete_celery.js
Last active October 30, 2016 13:57
Mongo Query to Delete Celery succesfull entries on a large collection, slowly but surely.
var COUNTER = 900;
function deleteSome(count) {
var itemsToDel = db.tasks.find({status: "SUCCESS"}, {_id: 1}).sort({created_at: 1}).limit(count).toArray();
var IDs = itemsToDel.map(function(item){ return item["_id"]})
if (IDs.length > 0 ) {
db.tasks.remove({"_id": {"$in": IDs } });
sleep(5000);
} else {
COUNTER++;