Skip to content

Instantly share code, notes, and snippets.

View dbagia's full-sized avatar
🐢

Dipen Bagia dbagia

🐢
  • Karma
  • Stockholm, Sweden
View GitHub Profile
@goude
goude / gist:b44b9d3938d3d30d8873f34fe2f92057
Created March 20, 2017 09:35
Generate and insert a UUID in vim
:r !uuidgen|sed 's/.*/"uid": "&",/'
// Bonfire: Where do I belong
// Author: @dbagia
// Challenge: http://www.freecodecamp.com/challenges/bonfire-where-do-i-belong?solution=function%20where(arr%2C%20num)%20%7B%0A%20%20%2F%2F%20Find%20my%20place%20in%20this%20sorted%20array.%0A%20%20arr.push(num)%3B%0A%20%20arr.sort(function(a%2Cb)%7B%0A%20%20%20%20return%20a%20-%20b%3B%0A%20%20%7D)%3B%0A%0A%20%20return%20arr.indexOf(num)%3B%0A%7D%0A%0Awhere(%5B2%2C%205%2C%2010%5D%2C%2015)%3B%0A
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function where(arr, num) {
// Find my place in this sorted array.
arr.push(num);
arr.sort(function(a,b){
return a - b;
// Bonfire: Chunky Monkey
// Author: @dbagia
// Challenge: http://www.freecodecamp.com/challenges/bonfire-chunky-monkey?solution=function%20chunk(arr%2C%20size)%20%7B%0A%20%20%2F%2F%20Break%20it%20up.%0A%20%20var%20rArr%20%3D%20%5B%5D%2C%20l%20%3D%20Math.ceil(arr.length%2Fsize)%3B%0A%0A%20%20for(var%20i%3D0%3B%20i%3Cl%3B%20i%2B%2B)%7B%0A%20%20%20%20rArr.push(arr.splice(0%2C%20size))%3B%0A%20%20%7D%0A%20%20return%20rArr%3B%0A%7D%0A%0Achunk(%5B%22a%22%2C%20%22b%22%2C%20%22c%22%2C%20%22d%22%5D%2C%202)%3B%0A
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function chunk(arr, size) {
// Break it up.
var rArr = [], l = Math.ceil(arr.length/size);
for(var i=0; i<l; i++){
// Bonfire: Repeat a string repeat a string
// Author: @dbagia
// Challenge: http://www.freecodecamp.com/challenges/bonfire-repeat-a-string-repeat-a-string?solution=function%20repeat(str%2C%20num)%20%7B%0A%20%20%2F%2F%20repeat%20after%20me%0A%20%20if(num%20%3C%201)%7B%0A%20%20%20%20return%20%22%22%3B%0A%20%20%7Delse%7B%0A%20%20%20%20return%20str.concat(repeat(str%2C%20num%20-%201))%3B%20%20%0A%20%20%7D%0A%20%20%0A%7D%0A%0Arepeat(%22abc%22%2C%203)%3B%0A
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function repeat(str, num) {
// repeat after me
if(num < 1){
return "";
}else{
// Bonfire: Confirm the Ending
// Author: @dbagia
// Challenge: http://www.freecodecamp.com/challenges/bonfire-confirm-the-ending?solution=function%20end(str%2C%20target)%20%7B%0A%20%20%2F%2F%20%22Never%20give%20up%20and%20good%20luck%20will%20find%20you.%22%0A%20%20%2F%2F%20--%20Falcor%0A%20%20%0A%20%20%0A%20%20return%20str.substr(-target.length)%20%3D%3D%3D%20target%3B%0A%7D%0A%0Aend(%22Bastian%22%2C%20%22n%22)%3B%0A
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function end(str, target) {
// "Never give up and good luck will find you."
// -- Falcor
// Bonfire: Return Largest Numbers in Arrays
// Author: @dbagia
// Challenge: http://www.freecodecamp.com/challenges/bonfire-return-largest-numbers-in-arrays?solution=function%20largestOfFour(arr)%20%7B%0A%20%20%2F%2F%20You%20can%20do%20this!%0A%20%20arr%20%3D%20arr.map(function(subarr)%7B%0A%20%20%20%20return%20subarr.sort(function(a%2Cb)%7B%0A%20%20%20%20%20%20return%20b%20-%20a%3B%0A%20%20%20%20%7D)%5B0%5D%3B%0A%20%20%7D)%3B%0A%20%20return%20arr%3B%0A%7D%0A%0AlargestOfFour(%5B%5B4%2C%205%2C%201%2C%203%5D%2C%20%5B13%2C%2027%2C%2018%2C%2026%5D%2C%20%5B32%2C%2035%2C%2037%2C%2039%5D%2C%20%5B1000%2C%201001%2C%20857%2C%201%5D%5D)%3B%0A
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function largestOfFour(arr) {
// You can do this!
arr = arr.map(function(subarr){
return subarr.sort(function(a,b){
return b - a;
@ericelliott
ericelliott / es7-class.md
Last active March 25, 2021 10:27
Let's fix `class` in ES7

Two Simple Changes to Simplify class

I'm not suggesting drastic action. I don't want to break backwards compatibility. I simply want to make the class feature more usable to a broader cross section of the community. I believe there is some low-hanging fruit that can be harvested to that end.

Imagine AutoMaker contained class Car, but the author wants to take advantage of prototypes to enable factory polymorphism in order to dynamically swap out implementation.

Stampit does something similar to this in order to supply information needed to inherit from composable factory functions, known as stamps.

This isn't the only way to achieve this, but it is a convenient way which is compatible with .call(), .apply(), and .bind().

@jcgregorio
jcgregorio / How_to_use.html
Last active July 17, 2023 14:44
HTML Templating using the HTML <template> element and exactly 100 lines of JS. A cleaned up version of this code is now available at https://github.com/jcgregorio/stamp/.
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8" />
<script src="templating.js" type="text/javascript" charset="utf-8"></script>
</head>
<body>
<template id=t>
@addyosmani
addyosmani / README.md
Last active July 24, 2024 10:54 — forked from 140bytes/LICENSE.txt
108 byte CSS Layout Debugger

CSS Layout Debugger

A tweet-sized debugger for visualizing your CSS layouts. Outlines every DOM element on your page a random (valid) CSS hex color.

One-line version to paste in your DevTools

Use $$ if your browser aliases it:

~ 108 byte version

@willurd
willurd / web-servers.md
Last active July 28, 2024 14:39
Big list of http static server one-liners

Each of these commands will run an ad hoc http static server in your current (or specified) directory, available at http://localhost:8000. Use this power wisely.

Discussion on reddit.

Python 2.x

$ python -m SimpleHTTPServer 8000