Skip to content

Instantly share code, notes, and snippets.

@low-ghost
low-ghost / client.py
Last active September 23, 2024 01:34
Simple Python to Javascript 2 way unix socket
"""Creates a python socket client that will interact with javascript."""
import socket
socket_path = '/tmp/node-python-sock'
# connect to the unix local socket with a stream type
client = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
client.connect(socket_path)
# send an initial message (as bytes)
client.send(b'python connected')
# start a loop
@low-ghost
low-ghost / Enum.ts
Last active June 18, 2016 12:48
quick ts/js enum using symbols and class getters
import { forEach, set } from 'lodash';
export class Enum <T>{
constructor(...values) {
forEach(values, (value) => set(this, value, Symbol(value));
}
get (value: T): Symbol {
@low-ghost
low-ghost / SassMeister-input.scss
Created February 17, 2015 17:13
Generated by SassMeister.com.
// ----
// Sass (v3.4.12)
// Compass (v1.0.3)
// ----
@function to-string($value) {
@return inspect(#{$value});
}
// general string replace functionality! what's next, regex?
@low-ghost
low-ghost / Utils.js
Last active August 29, 2015 14:15
Utils
(function(window) {
var Utils = window.Utils || function() { /* no need to set initial params as of yet */ };
Utils.prototype = {
ajaxGet: function(url, cb, passVar) {
var request = new XMLHttpRequest();
request.open('GET', url, true);
request.onreadystatechange = function() {
if (this.readyState === 4) {
@low-ghost
low-ghost / Utils, Async handling and Brightcove
Last active August 29, 2015 14:15
Vanilla JS utils and example usage with the Brightcove API for IE 8 compatibility
//borrowed this indexOf polyfill from MDN
if (!Array.prototype.indexOf){
Array.prototype.indexOf = function(elt /*, from*/){
var len = this.length >>> 0;
var from = Number(arguments[1]) || 0;
from = (from < 0) ? Math.ceil(from) : Math.floor(from);
if (from < 0)
from += len;
for (; from < len; from++){
if (from in this && this[from] === elt)
@low-ghost
low-ghost / transitioner.js
Last active August 29, 2015 14:14
transitioner.js is an es6 solution to jquery addClass w/ callbacks and default to css transitions
/*
TODO build non-jquery dependent class manipulations in utils and allow passing
in a custom animation function / library
*/
class Transitioner {
constructor(){
this.fake = document.createElement("fake")
//call set end() with transition object
this.end = {
@low-ghost
low-ghost / _transitioner.scss
Last active August 29, 2015 14:14
Organizing Sass Transitions by Class with Transitioner
// Organizing Sass Transitions with Transitioner
//
// transitioner creates
//
// .root .selector { ...transition rules... }
// .selector.classNameToBeAnimated { ...properties to be transitioned... }
//
// great for organizing multiple transitions when adding a single class via js
// feed it classes in quotes, anything else can go either way
// write "extend #id-name" as 2nd arg to extend previous transition rules