Skip to content

Instantly share code, notes, and snippets.

View Lokua's full-sized avatar
🐐
 

Joshua Kleckner Lokua

🐐
 
View GitHub Profile
@Lokua
Lokua / devToolsIgnoreStringRegExp.txt
Created February 6, 2017 22:06
Chrome DevTools regexp to ignore 404s #RegExp #ChromeDevTools
^((?!SOME_STRING).)*$
@Lokua
Lokua / isEventWithin.js
Created February 5, 2017 19:18
Detect if DOM event happened within a bounding box. Useful for outside click detection
export default function isEventWithin(e, element) {
const rect = element.getBoundingClientRect()
return (
rect.top <= e.clientY &&
e.clientY <= rect.top + rect.height &&
rect.left <= e.clientX &&
e.clientX <= rect.left + rect.width
)
}
@Lokua
Lokua / copy.js
Created February 5, 2017 19:15
browser programmatic text copy
export default function copy(text) {
const textArea = document.createElement(`textarea`)
textArea.value = text
textArea.style.width = `2em`
textArea.style.height = `2em`
textArea.style.background = `transparent`
document.body.appendChild(textArea)
textArea.select()
const success = document.execCommand(`copy`)
document.body.removeChild(textArea)
@Lokua
Lokua / index.html
Last active September 8, 2016 04:36
angular 1 pass promise to directive w/out isolate scope
<div ng-app="app" ng-controller="Controller as vm" directive="directive" promise="vm.promise"></div>
@Lokua
Lokua / quick-server.js
Created February 5, 2016 23:56
quickly serve index.html and and other static assets in a directory
'use strict'
const serve = require('koa-static')
new (require('koa'))()
.use(serve(`${__dirname}`))
.use(function* (next) {
return this.body = yield new Promise((resolve, reject) => {
require('fs').readFile(`${__dirname}/index.html`, 'utf8',
(err, body) => resolve(body))
@Lokua
Lokua / lsf.sh
Last active January 28, 2016 14:56
lsf
#!/bin/bash
alias lsfiles='for f in *; do [[ -f "$f" ]] && ls -- "$f"; done'
alias lsf=lsfiles
@Lokua
Lokua / random-string.js
Last active January 21, 2016 18:00
random string
export default n => Math.random().toString(35).slice(2, !n || n >= 1097 ? 1099 : n+2)
@Lokua
Lokua / qs.js
Last active January 19, 2016 11:58
query string script
export default {
/**
* Parse query string from path into POJO. If true is
* passed as 2nd argument, returns two member array
* of POJO and the query string portion
*
* @example
* ```js
* let path = 'http://foo.com/bar?a=1&b=2&c=3'
@Lokua
Lokua / ZipHelpers.java
Created December 17, 2015 03:07
zip helpers
package my.big.fucking.package;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
public class ZipHelpers {
/**
@Lokua
Lokua / JavaScript.tmLanguage
Created February 23, 2015 00:06
JavaScript.tmLanguage
<!-- fix regarding function params https://www.sublimetext.com/forum/viewtopic.php?f=3&t=6211 -->
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>comment</key>
<string>JavaScript Syntax: version 2.0</string>
<key>fileTypes</key>
<array>
<string>js</string>