Skip to content

Instantly share code, notes, and snippets.

View rupakraj's full-sized avatar

Rupak Raj Ghimire rupakraj

View GitHub Profile
@rupakraj
rupakraj / Datatable->LINQ
Last active November 26, 2015 07:06
C# System.Data.DataTable ->List<Object>
Using Select(): a power of LINQ for casting datatable into List of Object
List<Student> target = dt.AsEnumerable()
.Select(row => new Student
{
// assuming column 0's type is Nullable<long>
StudentID = row.Field<long?>(0).GetValueOrDefault(),
StudentName = String.IsNullOrEmpty(row.Field<string>(1)),
}).ToList();
@rupakraj
rupakraj / notify.js
Created January 24, 2016 08:18
Use node-gcm using npm
var gcm = require('node-gcm');
var notify = exports;
notify.send = function(msg, reg_id) {
var message = new gcm.Message();
message.addData('msg', msg);
// get token here
// TODO
//var regTokens = ['APA91bFiJx52Iq2_LwyXPUWeO0Vg-9DmrWW6E6BmjwNUtTIrWRNOIDzaCmOidzndjZE3zWvL248GtqBYIV7YsD9q37M0urFz3FD6DvYkOaVqJqV3V9CciPletqzbJqvEm-54cpwMNcxP'];
@rupakraj
rupakraj / django-db-reset
Created February 2, 2016 16:13
Django migration reset
WARNING: its hard reset, means all the data or log will be removed
To reset the django migration to initial follow following order
* Remove database
* Remove all the contents of django app's migrations folder except __init__.py file.
* The remaining migrations folder should be something like
myapp
├── migrations
│   │   ├── __init__.py
@rupakraj
rupakraj / RDM630.c
Created February 11, 2016 16:38
Used to read and verify data from RDM630 RFID Reader (Serial).
// Found somewhere in website, and updated.
#include <SoftwareSerial.h>
SoftwareSerial RFID(2, 3); // RX and TX
int data1 = 0;
int ok = -1;
int yes = 13;
int no = 12;
@rupakraj
rupakraj / DJangoTemplate
Created February 11, 2016 16:41
Handy tags and blocks for Django. Useful for the programmer
# DJango Template Tags Cheat Sheet
## Inheritance and Inclusion
{% extends "base.html "%}
{% block content %} ... {% endblock %} or {% block content %} ... {% endblock content %}
{% include "foo/bar.html" %}
{% ssi /home/html/ljworld.com/includes/right_generic.html %}
## Filters and Tags
@rupakraj
rupakraj / timer
Last active February 25, 2016 05:18
Android - contineous call to function
private void Timer(){
final Handler ha=new Handler();
ha.postDelayed(new Runnable() {
@Override
public void run() {
Debug.Log("Calling data");
// call your function
ha.postDelayed(this, 20*1000);
}
@rupakraj
rupakraj / png-fix-android
Created February 25, 2016 08:54
PNG fixes: iCCP: Not recognizing known sRGB profile that has been edited
SRC: http://pmt.sourceforge.net/pngcrush/
Issue fixes for : #AAPT: *.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
Use pngcrush to remove the incorrect sRGB profile from the png file:
pngcrush -ow -rem allb -reduce file.png
-ow will overwrite the input file
-rem allb will remove all ancillary chunks except tRNS and gAMA
-reduce does lossless color-type or bit-depth reduction
@rupakraj
rupakraj / last-lastb
Created February 26, 2016 09:19
Handy Shell Commands for checking SSH Access using last, lastb, sed
# lastb : Unsuccessful attempts
# last : Successful attempts
sudo lastb | sed 's/ \+/ /g'| cut -d' ' -f3 | sort | uniq -c | sort -n
sudo last | sed 's/ \+/ /g'| cut -d' ' -f3 | sort | uniq -c | sort -n
@rupakraj
rupakraj / Making USB stick bootable using winusb
Created October 26, 2016 12:09
Making USB stick bootable using winusb
If we need to make usb stick bootable of windows ISO follow the steps
```
$ sudo apt-get install winusb
```
run winusb comand with appropiate parameters
```
$ sudo winusb --format <ISO file> <desk>
```
Example
```
@rupakraj
rupakraj / Configuring vps for first time
Last active May 21, 2017 10:42
Configuring vps for first time (reference ubuntu)
# OS: Ubuntu
## Basic Configuration
-- login using ssh
# ssh root@IP
-- Update latest updates/security patches
-- set timezone
# timedatectl set-ntp true
# dpkg-reconfigure tzdata
-- Add new user -