Skip to content

Instantly share code, notes, and snippets.

View itsmunim's full-sized avatar
💂‍♂️
Extension over Modification...please!

Md Abdul Munim itsmunim

💂‍♂️
Extension over Modification...please!
View GitHub Profile
function Greeting({greeting}) {
return <h1>{greeting}</h1>;
}
class LanguageGreeting extends React.Component {
constructor(props) {
super(props);
this.fetchGreetingsInDifferentLanguages();
}
import React from 'react';
import {shallow} from 'enzyme';
import SearchBox from './search.box.jsx';
describe('SearchBox', () => {
let wrapper, onSearchCallback = jest.fn();
let mountComponent = (promptText) => {
return shallow(
<SearchBox
import React from "react";
class SearchBox extends React.Component {
constructor(props) {
super(props);
this.state = {
query: ""
};
}
@itsmunim
itsmunim / views.py
Last active December 2, 2016 09:50
A simple paginated DJango view implementation
def chunks(data, n):
"""Yield successive n-sized chunks from data."""
for i in range(0, len(data), n):
yield data[i:i + n]
def get_page_number_from_request(request):
"""The `page` param will be from 1, 2, 3 ....so on, so we will have to translate it to
an index that makes sense for an array"""
page_no = request.GET.get('page') - 1
return page_no if page_no > 0 else 0
@itsmunim
itsmunim / storage.service.js
Created November 29, 2016 19:35
A simple angular service wrapper for $localStorage to make things more understandable and manageable.
(function () {
'use strict';
angular.module('storage.service', []);
angular.module('storage.service')
.factory('localStorageService', localStorageService);
function localStorageService($localStorage) {
function retrieve(key) {
return $localStorage.hasOwnProperty(key) ? $localStorage[key] : {};
var sceneObj = (function() {
"use strict";
Physijs.scripts.worker = "scripts/physijs_worker.js";
Physijs.scripts.ammo = "ammo.js";
var scene, camera, renderer
var physijsBox, physijsGround, spawnBox;
var render, _boxes = [],
# def ngrams(tokens, n):
# num_tokens = len(tokens)
# if n > num_tokens:
# return
# ngram_list = []
# for i in xrange(num_tokens):
# token_groups = []
# for j in xrange(i, i+n):
# if j < num_tokens:
# token_groups.append(tokens[j])

Some cool commands that will save your ass in need

Remove sensitive file from your git history

Usecase- There's a SSH file included in your repo; but you want to remove it. Removing it from current commit won't delete from all the history. This command will save your life.

git filter-branch --force --index-filter \
'git rm --cached --ignore-unmatch PATH-TO-YOUR-FILE-WITH-SENSITIVE-DATA' \
  • Start rabbit mq server: rabbitmq-server
  • Access the web admin at localhost:15672/ and login using u= guest/p= guest
  • Go to exchanges and click on add a new exchange- Give it a name(e.g. download-event), select fanout as type and durabilty to durable
  • Go to queues and click on add a new queue- Give a name(e.g. download-image-event) and durability as durable
  • Publish event message: {"taskId":"569b34d1f79eae72524b4e96","title":"Quick image posts from my_images on 17 January 2016 at 12:29 PM (DHK - GMT+6)","channel":"facebook","createdAt":"2016-01-17T06:30:25.524Z","publishDate":"2016-01-17T06:32:18.167Z","articleGuids":[],"imageGuids":["4d4011c6799da7562111787e4e5fed97"],"organization":"53b8ccedab75641ba57e87c4","ssoId":"53b8cbf01f1582af1a00000f"}
  • Download event message: {imageGuid: <GUID of image in ThePlatform>, organizationId: <PK of CMC organization>, organizationName: <Name of organization to show in the dashboard>, downloadedAt: <ISO date of download from CMC>}
  • Once you pub
- name: set up virtualenv
  shell: chdir={{ DIRECTORY }} if [ ! -d env ]; then virtualenv env; fi
- name: set up python requirements
  command: chdir={{ DIRECTORY }} env/bin/pip install -r requirements.txt