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 / glog.sh
Created October 16, 2012 16:13
Nicer and more compact view for "git log" command
alias glog="git log --graph --pretty=\"format:%C(yellow)%h%Cred%d%Creset %s %C(white) %C(cyan)%an%Creset, %C(green)%ar%Creset\""
@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 / npm-cheat-sheet.md
Last active July 9, 2023 09:14
Node.js - npm Cheat Sheet

Node.js - npm Cheat Sheet

(Full description and list of commands at - https://npmjs.org/doc/index.html)

List of less common (however useful) NPM commands

Prepand ./bin to your $PATH

Make sure to export your local $PATH and prepand relative ./node_modules/.bin/:

@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 / sorted_git_tags.md
Last active July 21, 2018 18:39
A sorted list of git tags - A simple way to create a git alias to a sorted list of tags, sorted by their creation date, and not alphanumerically.

Extract a sorted by creation list list of git repository tags:

The git command line:

git for-each-ref --format='%(*committerdate:raw)%(committerdate:raw) %(refname) %(*objectname) %(objectname)' refs/tags | sort -n | cut -d'/' -f 3 | cut -d' ' -f 1

Create a new git alias for it (stags - Sorted tags):

@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"