Skip to content

Instantly share code, notes, and snippets.

@anurupr
anurupr / codeigniter
Created October 24, 2015 22:55
Convert code igniter db results to array
public function db_to_array($result,$toarray=TRUE){
$rows = array();
if($result->num_rows() > 0){
if($result->num_rows() > 1){
foreach($result->result_array() as $row){
$rows[] = $row;
}
}
else{
function dsfilter(arr, criteria) {
return arr.filter(function(obj) {
return Object.keys(criteria).every(function(c) {
return obj[c] == criteria[c];
});
});
}
@anurupr
anurupr / flac-to-mp3.bat
Created May 5, 2017 13:22 — forked from jshbrntt/flac-to-mp3.bat
Batch file to convert folder of .flac files to .mp3 using ffmpeg.
@ECHO OFF
FOR %%f IN (*.flac) DO (
echo Converting: %%f
ffmpeg -i "%%f" -ab 320k -map_metadata 0 "%%~nf.mp3"
)
echo Finished
PAUSE
@anurupr
anurupr / methods.js
Created June 2, 2017 10:52
javascript replace all method
// https://stackoverflow.com/a/17606289/839456
//Regular Expression Based Implementation
String.prototype.replaceAll = function(search, replacement) {
var target = this;
return target.replace(new RegExp(search, 'g'), replacement);
};
//Split and Join (Functional) Implementation
@anurupr
anurupr / useful_constants.js
Created June 3, 2017 22:41
Useful constants in javascript
// eslint rules -- package.json
"rules": {
"comma-dangle": 0,
"consistent-return": 0,
"no-param-reassign": 0,
"no-underscore-dangle": 0,
"no-shadow": 0,
"no-console": 0,
"no-plusplus": 0,
"no-var": 0,
@anurupr
anurupr / ListView to FlatList.diff
Created February 18, 2018 10:06 — forked from cooperka/ListView to FlatList.diff
Migrating from ListView to FlatList in React Native.
-import { Text, View, ListView } from 'react-native';
+import { Text, View, FlatList } from 'react-native';
import style from './styles';
import listData from './listData';
class App extends Component {
- constructor(props) {
- super(props);
@anurupr
anurupr / gist:a72d7774f6e5b42fe6a58dceab8e4e40
Created March 26, 2018 08:43 — forked from jagregory/gist:710671
How to move to a fork after cloning
So you've cloned somebody's repo from github, but now you want to fork it and contribute back. Never fear!
Technically, when you fork "origin" should be your fork and "upstream" should be the project you forked; however, if you're willing to break this convention then it's easy.
* Off the top of my head *
1. Fork their repo on Github
2. In your local, add a new remote to your fork; then fetch it, and push your changes up to it
git remote add my-fork git@github...my-fork.git
@anurupr
anurupr / switch-local-git-repo-to-fork.md
Created March 26, 2018 08:44 — forked from jpierson/switch-local-git-repo-to-fork.md
How to move to a fork after cloning

If you are like me you find yourself cloning a repo, making some proposed changes and then deciding to later contributing back using the GitHub Flow convention. Below is a set of instructions I've developed for myself on how to deal with this scenario and an explanation of why it matters based on jagregory's gist.

To follow GitHub flow you should really have created a fork initially as a public representation of the forked repository and the clone that instead. My understanding is that the typical setup would have your local repository pointing to your fork as origin and the original forked repository as upstream so that you can use these keywords in other git commands.

  1. Clone some repo (you've probably already done this step)

    git clone git@github...some-repo.git
@anurupr
anurupr / findLongRunningOp.js
Created May 7, 2018 22:00 — forked from kylemclaren/findLongRunningOp.js
Find and (safely) kill long running MongoDB ops
db.currentOp().inprog.forEach(
function(op) {
if(op.secs_running > 5) printjson(op);
}
)