Skip to content

Instantly share code, notes, and snippets.

@dariooddenino
dariooddenino / json.cljs
Last active October 4, 2015 10:51
Fetching JSONs and handling them in ClojureScript / Om
; A modified group-by for jsons.
; Eg. [{:id "id1" :title "one"} {:id "id2" :title "two"}]
; to, for example, this: {:id1 {:id "id1 :title "one"} :id2 {:id "id2" :title "two"}}
(defn group-json
[f coll]
(persistent!
(reduce
(fn [ret x]
(let [k (keyword (f x))]

#HTTP CODES


##2xx Success

200 OK Standard response for successful HTTP requests.

201 Created

@dariooddenino
dariooddenino / toggle_touchpad.sh
Created January 27, 2016 08:56
Dell 9350 Touchpad toggle on Ubuntu
#!/bin/bash
declare -i ID
ID=`xinput list | grep -Eo 'DLL0704:01\s06CB:76AE\sUNKNOWN\s*id\=[0-9]{1,2}' | grep -Eo '\=[0-9]{1,2}' | grep -Eo '[0-9]{1,2}'`
declare -i STATE
STATE=`xinput list-props $ID|grep 'Device Enabled'|awk '{print $4}'`
if [ $STATE -eq 1 ]
then
xinput disable $ID
echo "Touchpad disabled."
@dariooddenino
dariooddenino / post.purs
Created July 29, 2016 16:17
post request
data Post = Post { id :: Maybe Int
, title :: String
, body :: String
, userId :: Int
}
instance decodeJsonPost :: DecodeJson Post where
decodeJson json = do
obj <- decodeJson json
id <- obj .? "id"
// helpers.js
import * as R from 'ramda'
export const subObj = R.doSomestuff
// reasontest.re
type jsmodule;
@dariooddenino
dariooddenino / react-wrapper.re
Last active August 10, 2017 09:30
Trying to create a wrapper function in reason-react.
/**
I'm trying to create a wrapper function that takes a react component and injects Apollo queries as props.
I've got to the point where it works, but:
1) I have to pass all the queries in a single js object with no compiler check if there's corrispondence
between the queries used and the ones the wrapped component is expecting.
2) I can't pass additional props without stuffing all of them inside a single object in the wrapper and then
doing some ugly Js.Obj.assign stuff.
*/
/** This two functions injects all the queries as props in the component */
statusOk :: StatusCode -> Boolean
statusOk (StatusCode n) = n >= 200 && n < 300
_parseError = SProxy :: SProxy "parseError"
_badRequest = SProxy :: SProxy "badRequest"
_unAuthorized = SProxy :: SProxy "unAuthorized"
_forbidden = SProxy :: SProxy "forbidden"
_notFound = SProxy :: SProxy "notFound"
_methodNotAllowed = SProxy :: SProxy "methodNotAllowed"
_formatError = SProxy :: SProxy "formatError"
exports.addCardListenerImpl = function (card, fn) {
card.addEventListener('change', fn);
return null;
}
data PrefixProps sym = PrefixProps (SProxy sym)
instance prefixProps ::
( IsSymbol newsym
, Append presym sym newsym
, Row.Lacks newsym rb
, Row.Cons newsym a rb rc
) =>
FoldingWithIndex
(PrefixProps presym)
newtype StringTransform = StringTransform (String -> String)
class EnumReadForeign rep where
enumReadForeignImpl :: StringTransform -> Foreign -> F rep
-- | Reads sums
enumReadForeign :: forall a rep
. Generic a rep
=> EnumReadForeign rep
=> Foreign