Skip to content

Instantly share code, notes, and snippets.

require 'base64'
# tools.ietf.org/html/rfc2397
# developer.mozilla.org/en/data_URIs
# "data:" + MIME type + ";base64," + base64-encoded content
def to_data_url(content, content_type)
outuri = 'data:' + content_type + ';base64'
content = Base64.encode64(content).gsub("\n", '')
outuri += ",#{content}"
'use strict';
angular.module('ngSvg', [])
.directive('usesvg', [function(){
return {
restrict : 'E',
replace: true,
controller : ['$scope', function($scope){
@arekbartnik
arekbartnik / scroll-manager.js
Created April 27, 2017 21:10 — forked from maddie927/scroll-manager.js
Scroll Manager for React Router v4
import React from 'react'
import { func, node, number, object, shape, string } from 'prop-types'
import { withRouter } from 'react-router'
import debounceFn from 'lodash/debounce'
class ScrollManager extends React.Component {
static propTypes = {
children: node.isRequired,
history: shape({
action: string.isRequired,
@arekbartnik
arekbartnik / git-bash.sh
Created October 7, 2017 09:26 — forked from gyandeeps/git-bash.sh
Bash alias for git
# Global variables
re='^[0-9]+$'
# Will create a new branch with name ($1) from master
# it will also make sure master is up to date from origin
workstart() {
if ! [[ $1 =~ $re ]]
then
val=$1
else
@arekbartnik
arekbartnik / cron.md
Created December 23, 2017 20:54 — forked from evancz/cron.md
Cron job to remind myself to stretch

Type crontab -l to see your cron jobs. Type crontab -e to edit them. You have to use Vim apparently.

Add a line like this:

0,30	*	*	*	*	/Users/YOURNAME/Documents/scripts/stretch.sh

That is on every 0th and 30th minute of the hour. Make sure all the separators in there are tabs!

@arekbartnik
arekbartnik / react-image-objectfit-fallback.js
Created December 24, 2017 09:02 — forked from vincentriemer/react-image-objectfit-fallback.js
Image React Component with `object-fit` Fallback
// @flow
import * as React from "react";
import getStyleProp from "desandro-get-style-property";
const supportsObjectFit = !!getStyleProp("objectFit");
type Props = React.ElementProps<"img">;
export default class Image extends React.Component<Props> {
@arekbartnik
arekbartnik / ResizeObservable.js
Created December 24, 2017 09:04 — forked from vincentriemer/ResizeObservable.js
React Component prototype that provides element query functionality via ResizeObserver
// @flow
import * as React from "react";
import ResizeObserver from "resize-observer-polyfill";
import invariant from "invariant";
type Entry = {
+contentRect: {
+width: number,
+height: number
// handy method to create a Higher Order Component out of a
// Render Prop Component (like a Context.Consumer).
// handles, statics, displayName, refs, and value forwarding
function createHOCFromRenderProp({prop, Consumer}) {
return Component => {
function Wrapper(props, ref) {
return (
<Consumer>
{value => <Component {...{...props, [prop]: value, ref}} />}
@arekbartnik
arekbartnik / figma-project-stats.js
Created June 21, 2018 19:20 — forked from rsms/figma-project-stats.js
Script that generates statistics for a Figma project, like number of files, frames, versions etc
//
// Figma project stats
// Pulls statistics like number of files, frames, versions etc for a project.
//
// Usage:
// export FIGMA_API_ACCESS_TOKEN='your-token'
// node figma-project-stats.js <project-id>
//
// You can generate tokens in your account settings or at
// https://www.figma.com/developers/explorer#personal-access-token
let UserContext = React.createContext();
class App extends React.Component {
state = {
user: null,
setUser: user => {
this.setState({ user });
}
};