Skip to content

Instantly share code, notes, and snippets.

View BenBals's full-sized avatar
🕴️

Ben BenBals

🕴️
View GitHub Profile
@BenBals
BenBals / gist:523660074ffe47a3de66
Last active March 25, 2016 20:08
Random number in JS
random = function(from, to) {return Math.floor((Math.random() * to) + from);};
@BenBals
BenBals / gist:b8299f36f20c882b7f36
Last active August 29, 2015 14:01
getJSON Template
var data;
$.getJSON("data.json", function (json) {
data = json;
});
@BenBals
BenBals / x.js
Last active August 29, 2015 14:14
x - Small jQuery like Thing that can only add and remove Classes 1346 Bytes (yes Bytes)
var x;x=function(e){var n,s;return s={},n=e,s.element=function(){return document.querySelector(n)},s.elements=function(){return document.querySelectorAll(n)},s.e=s.element,s.es=s.elements,s.addClass=function(e,t){var l,o,a,r,i;if(void 0===t)for(a=s.elements(),r=0,i=a.length;i>r;r++)l=a[r],l.className===l.className.split(e).join("")&&(""===l.className?l.className=e:l.className+=" "+e);else{if(t>=s.elements().length||0>t)return console.warn("You provided an index ("+t+") that is out of range to a x.addClass. The selector was "+n),null;o=s.elements()[t],""===o.className?o.className=e:o.className+=" "+e}return e},s.append=function(e,t){var l,o,a,r,i;if(void 0===t)for(a=s.es(),r=0,i=a.length;i>r;r++)l=a[r],l.innerHTML+=e;else{if(t>=s.elements().length||0>t)return console.warn("You provided an index ("+t+") that is out of range to a x.append. The selector was "+n),null;o=s.es()[t],o.innerHTML+=e}return e},s.html=function(e,t){var l,o,a,r,i;if(void 0!==e&&"number"!=typeof e){if(void 0===t)for(a=s.es(),r=0,i=a.length
@BenBals
BenBals / alleLektionen.json
Last active October 19, 2015 09:45
Actio.json
[
[
"Stammformen von agere",
"ago, egi, actum"
],
[
"Stammformen von audire",
"audio, audivi, auditum"
],
[
@BenBals
BenBals / vok5b.json
Last active August 29, 2015 14:21
Spanisch
{
"config": {
"random": "true"
},
"data": [
["telefonieren", "hablar por teléfono"],
["Ja, bitte? Anrede beim Telefonieren", "¿Diga?"],
["lassen", "dejar"],
["die Nachricht", "el recado"],
["Möchtest du ihm/ihr eine Nachricht hinterlassen", "¿Le quieres dejar un recado?"],
@BenBals
BenBals / test1.json
Last active August 29, 2015 14:22
karteikarten Test
{
"config": {
"random": "true"
},
"data": [
["Vorderseite 1", "Rückseite 1"],
["Vorderseite 2", "Rückseite 2"]
]
}
@BenBals
BenBals / resultA8A2.txt
Last active September 10, 2015 19:24
resultCheckNumber
[(0,0,Nothing),
(1,0,Nothing),
(2,20664,Nothing),
(3,537264,[14,13,12]),
(4,5372640,[14,13,12]),
(5,32029200,[16,15,14]),
(6,137725560,[42,41,40]),
(7,472709664,[43,42,41])]
@BenBals
BenBals / stuff.hs
Last active March 25, 2016 19:36
Add, Subtract, Multiply, Exponentiate
-- Ever wanted to add, subtract, multiply and exponentiate using all possible combinations of 1 and 2 with 3 and 4? No. Well thats how it's done in Haskell anyway. Jup just that single line.
[(+), (-), (*), (^)] <*> [1,2] <*> [3,4]
@BenBals
BenBals / kightsQuest.hs
Created March 26, 2016 09:52
Make a function that checks whether a knight can reach a certain position on a chess board from a given starting position within 3 moves. Position denoted as (Int,Int)
import qualified Control.Monad as M
type KnightPos = (Int,Int)
moveKnight :: KnightPos -> [KnightPos]
moveKnight (c,r) = do
(c',r') <- [(c+2,r-1),(c+2,r+1),(c-2,r-1),(c-2,r+1)
,(c+1,r-2),(c+1,r+2),(c-1,r-2),(c-1,r+2)
]
M.guard (c' `elem` [1..8] && r' `elem` [1..8])
@BenBals
BenBals / powerset.hs
Created March 26, 2016 16:02
how to get a powerset of any given list in Haskell. Mind = Blown
import Control.Monad
powerset :: [a] -> [[a]]
powerset = filterM (\n -> [True,False])