Skip to content

Instantly share code, notes, and snippets.

@vbedegi
vbedegi / react-sortable-hoc-in-reagent.cljs
Last active November 29, 2017 15:50
using react-sortable-hoc in reagent
(def react-sortable-hoc (aget js/window "deps" "react-sortable-hoc"))
(defn make-sortable-element-component [wrapped-component]
(let [sortable-element-factory (.-SortableElement react-sortable-hoc)]
(-> wrapped-component
r/reactify-component
sortable-element-factory
r/adapt-react-class)))
(defn make-sortable-container-component [wrapped-component]
@vbedegi
vbedegi / elm.cljs
Last active April 29, 2019 08:15
elm in cljs
; util
(defn tag-dispatch [dispatch tag]
(fn [msg]
(let [tagged (if (vector? tag)
(conj tag msg)
[tag msg])]
(dispatch tagged))))
; counter
open System
open System.IO
let gravity = 9.81
let angleOfReach speed distance = 0.5 * Math.Asin((gravity * distance) / Math.Pow(speed, 2.0))
let distanceTravelled speed angle = Math.Pow(speed, 2.0) * Math.Sin(2.0 * angle) / gravity
let angle x y = Math.Atan(y / x)
open System
let ratio = (1.0 + Math.Sqrt(5.0)) / 2.0
let inputInt (prompt: String) =
Console.WriteLine(prompt)
int (Console.ReadLine())
let inputFloat (prompt: String) =
Console.WriteLine(prompt)
open System
let rec queryForNonNegativeInt msg =
printf msg
let parsed, number = Int32.TryParse(Console.ReadLine());
if parsed then
if number < 0 then queryForNonNegativeInt msg
else number
else queryForNonNegativeInt msg
@vbedegi
vbedegi / handler.clj
Created September 28, 2014 17:45
Qarth sample with Ring
(ns qartoy.handler
(:require [clojure.tools.logging :as log]
[ring.util.response :refer [redirect]]
[compojure.core :refer :all]
[compojure.handler :as handler]
[compojure.route :as route]
[qarth.oauth :as oauth]
[qarth.impl.facebook :refer :all]
[qarth.impl.google :refer :all]
[qarth.impl.github :refer :all]
@vbedegi
vbedegi / Main.sublime-menu
Created January 18, 2014 11:00
SublimeRepl user config for Clojure C:\Users\your-user-name\AppData\Roaming\Sublime Text 3\Packages\User\SublimeREPL\config\Clojure\Main.sublime-menu
[
{
"id": "tools",
"children":
[{
"caption": "SublimeREPL",
"mnemonic": "r",
"id": "SublimeREPL",
"children":
[
(use 'clojure.core.async)
;this is the function you want to use
(defn lazy-channels [chs]
(lazy-seq (cons (let [ [v _] (alts!! chs)] v) (lazy-channels chs))))
;now for the tesging
(def chs [ (chan) (chan) (chan) ]) ; the channels can come from anywhere, here we are using three channels for testing
@vbedegi
vbedegi / Example1.cs
Created March 5, 2012 21:04
A transactional, concurrent queue for .Net
var queue = new TransactionalConcurrentQueue<int>();
using (var scope = new TransactionScope())
{
queue.Enqueue(1);
// won't happen
queue.Dequeue(x => Console.WriteLine(x));
scope.Complete();
@vbedegi
vbedegi / some.cs
Created January 5, 2012 17:12
decompiled lambda expression
IQueryable<<>f__AnonymousType0<string>> <>f_AnonymousType0s = Expression[] expressionArray = new Expression[1].Select<string,<>f__AnonymousType0<string>>(Expression.Lambda<Func<string, <>f__AnonymousType0<string>>>(Expression.New(expressionArray[0] = parameterExpression, expressionArray, new MethodInfo[] { (MethodInfo)MethodBase.GetMethodFromHandle(Name, <>f__AnonymousType0<string>) }), new ParameterExpression[] { parameterExpression }));