Skip to content

Instantly share code, notes, and snippets.

View kumarharsh's full-sized avatar
🤹‍♂️
Juggling

Kumar Harsh kumarharsh

🤹‍♂️
Juggling
View GitHub Profile
@kumarharsh
kumarharsh / Mongo ObjectID to Timestamp
Created May 19, 2013 15:40
A snippet to convert Mongo ObjectID to javascript timestamps, and vice-versa
----- mongo to js ------
timeStamp = parseInt(Mongo.ObjectId().toString().substr(0,8), 16)*1000
date = new Date(timestamp)
-----------------------------
----- js to mongo -----
timestamp = new Date().getTime()/1000
mongoId = new ObjectID(timestamp.toString(16)+1e16)
@kumarharsh
kumarharsh / Select.jsx
Last active October 7, 2022 21:02
Shows how to use react-select with portals provided by react-overlay
import ReactSelect from 'react-select';
import Portal from 'react-overlays/lib/Portal';
import 'react-select/dist/react-select.css'; // I'm using css-modules, but you can use whatever you like
import css from './Select.css';
import defaultMenuRenderer from 'react-select/lib/utils/defaultMenuRenderer'; // this renders the actual menu - we can reuse the same component
class _SelectMenu extends React.Component {
props: { // flow types
selectProps: {},
@kumarharsh
kumarharsh / system-environment-snippets
Last active June 18, 2021 17:05
[Powershell] Update Environment Variable one-liner
# These snippets provide a quick way to update your environment variables
# directly from your powershell console. Just copy paste these lines, or
# even better, add it to your profile as functions.
# refreshing env in current shell
$env:path = [System.Environment]::GetEnvironmentVariable("Path", "Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path", "User")
# adding path to env
# set path in the $_newPath variable, and it'll get set to your user environment path and persisted.
$_newPath=""; [System.Environment]::SetEnvironmentVariable("Path", [System.Environment]::GetEnvironmentVariable("Path", "User") + ";${_newPath}", "User")
@kumarharsh
kumarharsh / upx.strace
Created February 13, 2019 07:50
WSL UPX strace
9669 execve("./upx64/upx", ["./upx64/upx"], 0x7fffda4bdab8 /* 21 vars */) = -1 ENOEXEC (Exec format error)
9669 write(2, "strace: exec: Exec format error\n", 32) = 32
9669 getpid() = 9669
9669 exit_group(1) = ?
9669 +++ exited with 1 +++
@kumarharsh
kumarharsh / git-repro.sh
Created November 21, 2017 07:37
Reproduce bug in Git Log using this script (git-for-windows)
#!/usr/bin/env bash
set -x
rm -rf test-repo
rm -rf test-submodule
mkdir test-submodule
pushd test-submodule
@kumarharsh
kumarharsh / update_schema.go
Created February 20, 2017 13:38
Build schema.json from Graphql mutations & queries using playlyfe/go-graphql
package main
import (
"flag"
"io/ioutil"
"github.com/playlyfe/go-graphql"
gql "github.com/your-project/your-graphql-mutations-and-queries"
)
@kumarharsh
kumarharsh / update_schema.go
Created February 20, 2017 13:38
Build schema.json from Graphql mutations & queries using playlyfe/go-graphql
package main
import (
"flag"
"io/ioutil"
"github.com/playlyfe/go-graphql"
gql "github.com/your-project/your-graphql-mutations-and-queries"
)
@kumarharsh
kumarharsh / gen-schema.js
Created February 10, 2017 10:14
Generate schema.js from .gql files
/* @flow */
import generate from '@playlyfe/gql/lib/tools/generate';
import path from 'path';
import fs from 'fs';
// This script reads in the schema files based off the configOptions.cwd folder
// and generates a schema.js (instead of schema.json) file and
// outputs it to the specified output folder
// Usually, you'd place this script just before running webpack,
@kumarharsh
kumarharsh / chai-as-promised-webdriver-test.js
Last active January 2, 2016 08:58
A gist to track down an error in selenium-webdriver tests using chai-as-promised + mocha
describe("test the UI", function() {
it('when the log is shown', function(next) {
var _this = this;
var promiseA, promiseB;
promiseA = Q.promise() // or whatever, to create a promise for this test
promiseB = Q.promise() // or whatever, to create a promise for this test
promiseA.then(function() { // promiseA and promiseB are Q promises
var fn;
fn = function(limit) {
return promiseB.then(function(data) {
@kumarharsh
kumarharsh / twitter-widgets.coffee
Last active August 29, 2015 14:21
Twitter Widgets in AngularJS
# A way to use twitter widgets with angularjs
YOUR_MODULE
.directive('plTwitterButton', ['$timeout', ($timeout) ->
replace: true
template: """
<a class="twitter-share-button"
href="{{ href }}"
data-url="{{ url }}"
data-text="{{ text }}"