Skip to content

Instantly share code, notes, and snippets.

@ayal
ayal / robot.clj
Created September 21, 2009 14:52 — forked from avital/robot.clj
(ns we
(:require clojure.contrib.json.read)
(:require clojure.contrib.json.write)
(:require clojure.set)
(:use clojure.contrib.json.read)
(:use clojure.contrib.json.write)
(:use clojure.set)
(:use compojure))
; db is a map between replocs and blipData (= the event json we get from wave)
(defn-log match-rep-loc
"in this context rep-op is the incoming rep-op, rep-loc is what is for comparison from the rep-class from rep-rules"
[rep-op rep-class]
(for [rep-loc rep-class
:when
(cond
(and (:blip-id rep-loc)
(= (:rep-loc rep-op) rep-loc))
false
var i = 0;
var len = object.length;
objects.forEach(function() {
if (something) {
doSomethingAsync(function(data) {
doSomethingWithData(data);
if (i === len - 1) {
returnResponseToClient();
}
i++;
autologin = function(){
var state = Meteor.uuid();
$.get('/_oauth/facebook?close&state=' + state +
'&access_token=' +
FB.getAccessToken(), function() {
Meteor.call('login', {oauth: {state: state}}, function(e, result) {
Accounts._makeClientLoggedIn(result.id, result.token);
@ayal
ayal / haaretz.js
Last active June 6, 2019 22:13
cleans haaretz articles
javascript:void(
function(){
document.head.innerHTML = '';
var jsCode=document.createElement('script');
jsCode.setAttribute('src','https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js');
document.body.appendChild(jsCode);
setTimeout(()=>{
var art = $('.article');
if (art.length === 0) {
@ayal
ayal / app.js
Created October 27, 2019 17:30
offer class preferences code
//var prefs = [[2,3],[1,3],[1,2],[5,6],[4,6],[4,5],[8,9],[7,9],[7,8],[11,12],[10,12],[10,11],[14,15],[13,15],[13,14],[17,18],[16,18],[16,17]];
var perfstr = `1 13 16
2 13 18
3 7 10
4 11 16
5 6 9
6 13 5
7 5 6
8 -1 -1
@ayal
ayal / app.js
Created October 28, 2019 09:38
oren split airbnb bills
var amount = 1000;
var billDays = 1000 ;
var yesGuestDays = 1000;
///
var noGuestDays = billDays - yesGuestDays;
var amountPerDay = amount / billDays;
var orenPay = (amountPerDay / 2) * noGuestDays + (amountPerDay / 3) * yesGuestDays;
var ayalPay = amount - orenPay;
console.log(`Oren: ${orenPay.toFixed(0)}, (${((orenPay / amount)*100).toFixed(0)}%)
Ayal: ${ayalPay.toFixed(0)}, (${((ayalPay / amount)*100).toFixed(0)}%)`);
@ayal
ayal / balance.js
Created February 14, 2020 12:07
balance
var userSums = [{name: 'ayal', sum: 400}, {name: 'tomer', sum: 300}, {name: 'guy', sum: 250}, {name: 'ronni', sum: 0}, {name: 'max', sum: 0}];
var sum = userSums.reduce((acc,u)=>acc+u.sum,0);
var usum = sum / userSums.length;
userSums.map(x=>(x.balance = x.sum - usum) && (x.gotgave = 0));
var balanceUsers = (u1,u2)=> {
if (u1.balance < 0 && u2.balance > 0) {
// u1 pays u2
@ayal
ayal / child.js
Last active November 3, 2020 16:38
killing forked children after setrawmode(true -> false)
var cp = require("child_process");
console.log('hi from child', process.stdin.isRaw)
setInterval(() => {
console.log('hi from child', process.stdin.isRaw);
}, 1000);
var child2 = cp.fork('child2.js', []);
console.log('child 2 pid', child2.pid);
@ayal
ayal / shortcodes_inverse.json
Last active October 17, 2021 13:24
shortcodes inverse
{\"0⃣\":[\"0\",\"keycap\",\"number\",\"zero\"],\"1⃣\":[\"1\",\"number\",\"one\"],\"🕐\":[\"1\",\"00\",\"1:00\",\"clock\",\"one\",\"one o’clock\",\"o’clock\",\"time\"],\"🕜\":[\"1\",\"30\",\"1:30\",\"clock\",\"one\",\"one-thirty\",\"thirty\",\"time\"],\"🕑\":[\"2\",\"00\",\"2:00\",\"clock\",\"o’clock\",\"time\",\"two\",\"two o’clock\"],\"2⃣\":[\"2\",\"number\",\"two\"],\"🕝\":[\"2\",\"30\",\"2:30\",\"clock\",\"thirty\",\"time\",\"two\",\"two-thirty\"],\"🕒\":[\"3\",\"00\",\"3:00\",\"clock\",\"o’clock\",\"three\",\"three o’clock\",\"time\"],\"🕞\":[\"3\",\"30\",\"3:30\",\"clock\",\"thirty\",\"three\",\"three-thirty\",\"time\"],\"3⃣\":[\"3\",\"keycap\",\"number\",\"three\"],\"🕓\":[\"4\",\"00\",\"4:00\",\"clock\",\"four\",\"four o’clock\",\"o’clock\",\"time\"],\"🍀\":[\"4\",\"clover\",\"four\",\"four leaf clover\",\"irish\",\"leaf\",\"lucky\",\"plant\"],\"🕟\":[\"4\",\"30\",\"4:30\",\"clock\",\"four\",\"four-thirty\",\"thirty\",\"time\"],\"4⃣\":[\"4\",\"four\",\"number\"],\"🕠\":[\"5\",\"30\",\"5:30\",\"clock\",\"five\",\