Skip to content

Instantly share code, notes, and snippets.

@javidjamae
javidjamae / .powrc
Last active August 29, 2015 14:25
Use this .powrc file to get pow to play nicely with rvm
if [ -f "$rvm_path/scripts/rvm" ] && [ -f ".ruby-version" ] && [ -f ".ruby-gemset" ]; then
source "$rvm_path/scripts/rvm"
rvm use `cat .ruby-version`@`cat .ruby-gemset`
fi
@javidjamae
javidjamae / Vagrantfile
Created August 10, 2015 23:18
Vagrantfile for bringing up an Windows / IE virtual server from modern.ie
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Got this file from: https://gist.github.com/andreptb/57e388df5e881937e62a
Vagrant.configure(2) do |config|
config.vm.box = "win7-ie9"
config.vm.box_url = "http://aka.ms/vagrant-win7-ie9"
config.vm.boot_timeout = 500
config.vm.network "forwarded_port", guest: 3389, host: 3389, id: "rdp", auto_correct: true
@javidjamae
javidjamae / last_month.sql
Last active September 2, 2015 17:35
Select all records created in the last month (MySQL)
select *
from records
where PERIOD_ADD(DATE_FORMAT(NOW(),'%Y%m'), -1) = DATE_FORMAT(created_at,'%Y%m')
@javidjamae
javidjamae / javascript_dependency_injector.js
Last active October 2, 2015 00:32
Javascript Dependency Injector
(function() {
window.JDI = window.JDI || {};
/*
JDI.register - register a module on the "JDI" global
Usage:
with a namespace: JDI.register("foo", {bar: myFunc}) => JDI.foo.bar = myFunc
without a namespace: JDI.register({bar: myFunc}) => JDI.bar = myFunc
*/
JDI.register = function(){
@javidjamae
javidjamae / pry.rb
Created January 4, 2016 21:33
How to configure pry to show the environment name in the prompt
# This file would go in config/initializers/pry.rb in a Rails project
old_prompt = Pry.config.prompt
env_str = "#{Rails.application.class.parent}-#{Rails.env}".upcase
if Rails.env.production?
# Can't do this because it messes with bash history for some reason
# env = Pry::Helpers::Text.red(env_str)
env = "\001\e[0;31m\002#{env_str}\001\e[0m\002"
else
# Can't do this because it messes with bash history for some reason
# env = Pry::Helpers::Text.green(env_str)
@javidjamae
javidjamae / wait_while.rb
Last active March 31, 2016 18:42
Ruby: #wait_while
# Original source - https://coderwall.com/p/bkrg8a/ruby-wait_while
# Public: Wait while block returns false by repeatedly
# calling the block until it returns true.
#
# Useful to wait for external systems to do something.
# Like launching daemons in integration tests. Which
# you're not actually doing right? >_<
#
# timeout - Integer specifying how many seconds
# to wait for.
@javidjamae
javidjamae / selenium_using_sauce_labs.rb
Created April 5, 2016 23:21
Set up Selenium to use Sauce Labs without a gem
capabilities_config = {
:version => "43",
:browserName => "firefox",
:platform => "OS X 10.9",
:name => "Whatever name I want"
}
sauce_username = ENV['SAUCE_LABS_USERNAME']
sauce_api_key = ENV['SAUCE_LABS_API_KEY']
sauce_url = "http://#{sauce_username}:#{sauce_api_key}@ondemand.saucelabs.com:80/wd/hub".strip
@javidjamae
javidjamae / App.js
Created August 21, 2017 17:20
React Native issue with TabNavigator and form autoFocus
import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
import { TabNavigator } from 'react-navigation'
import TheListView from './TheListView'
import TheFormView from './TheFormView'
export default class App extends React.Component {
render() {
return (
<AppNavigator />
@javidjamae
javidjamae / lodashify.js
Created September 9, 2017 22:05 — forked from khalilovcmd/lodashify.js
to import lodash into chrome dev tools console
var el = document.createElement('script');
// el.src = "https://raw.githubusercontent.com/lodash/lodash/3.10.1/lodash.min.js";
// el.src = "https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.15.0/lodash.min.js";
el.src = "//cdnjs.cloudflare.com/ajax/libs/lodash.js/4.15.0/lodash.min.js";
el.type = "text/javascript";
document.head.appendChild(el)
@javidjamae
javidjamae / jest_textinput_mock.js
Created September 27, 2017 08:05
Mocking out a TextInput with jest
jest.mock( 'TextInput', () => {
const RealComponent = require.requireActual( 'TextInput' )
const React = require( 'React' )
class TextInput extends React.Component {
render() {
delete this.props.autoFocus
return React.createElement( 'TextInput', this.props, this.props.children )
}
}
TextInput.propTypes = RealComponent.propTypes