Skip to content

Instantly share code, notes, and snippets.

View mdebbar's full-sized avatar

Mouad Debbar mdebbar

View GitHub Profile
// USAGE:
//
// This script is supposed to be used with `jscodeshift`. Here is how you would invoke it:
// $ jscodeshift -t add-unit-true-to-ember-tests.js --fn=moduleForComponent path/to/unit/tests/
//
// The `--fn` argument above can be changed to `moduleFor`, `moduleForModel`, etc.
module.exports = function transform(file, api, options) {
var j = api.jscodeshift;
var fn = options.fn || 'moduleForComponent';
@mdebbar
mdebbar / FileInput.js
Last active January 23, 2017 04:32
Helper component for rendering custom file inputs.
import React, { Component, PropTypes as T } from 'react'
/**
* Helper component for rendering custom file inputs. It renders a label with an invisible
* file input. The given `className` will be applied to the label.
*/
export default class FileInput extends Component {
static propTypes = {
allowedTypes: T.array,
className: T.string,
@mdebbar
mdebbar / postcss-munge.js
Created March 15, 2017 08:16
PostCSS plugin to munge css class names
/**
* ./node_modules/.bin/postcss -c postcss.config.js -d munged/ prod/core/assets/*.css
*/
// postcss.config.js
module.exports = {
plugins: [
require('./munge'),
]
}
@mdebbar
mdebbar / launch.sh
Created November 12, 2017 06:56
Run a command and monitor its memory usage
#!/usr/bin/env bash
set -e
MEM_LIMIT=$1 # First argument
CMD=${@:2} # Everything else
echo "Memory limit set at: $MEM_LIMIT KB"
echo "Running and monitoring: '$CMD'"
eval "$CMD &"
CMD_PID=$!
@mdebbar
mdebbar / core.js
Created January 24, 2018 21:17
Idea for a MapReduce-inspired js bundler
import fs from 'fs'
// The symbols shouldn't be exported so that `module` remains an opaque object.
const MODULE_PATH = Symbol('module.path');
const MODULE_VIRTUAL_CONTENT = Symbol('module.virtualContent');
export function createModule(path) {
return { [MODULE_PATH]: path, [MODULE_VIRTUAL_CONTENT]: null };
}
// index.js
ReactDOM.render(<App />, root);
// components/app.js
class App extends Component {
render() {
return (
<>
<h1>My App</h1>
<ConverterForm />
import Ember from 'ember';
const { computed } = Ember;
export default Ember.Component.extend({
tagName: '',
text: computed.oneWay('todo.text'),
json: computed('todo.{id,text}', function() {
return JSON.stringify(this.get('todo'));
}),
@mdebbar
mdebbar / main.dart
Created April 3, 2019 19:36
Analyzer - switch exhaustiveness
enum MyEnum {
e1,
e2,
e3,
}
String getString(MyEnum value) {
switch (value) {
case MyEnum.e1:
return 'e1';
@mdebbar
mdebbar / main.dart
Created May 28, 2019 21:27
Repro for wrong runtimeType
void main() {
final double x = 10.0;
print(x.runtimeType); // Prints "int"
}
bool foo() {
Future.value(10).then((_) {
return true;
}).catchError((_) {
return false;
});
}
void main() {
print(foo());