Skip to content

Instantly share code, notes, and snippets.

MAT_SIZE = 3
mat = [[0 for i in range(MAT_SIZE)] for j in range(MAT_SIZE)]
# >>> mat
# [[0, 0, 0], [0, 0, 0], [0, 0, 0]]
for i, j in [(i, j) for i in range(MAT_SIZE) for j in range(MAT_SIZE)]:
mat[i][j] = 10*i + j
# >>> mat
mat = [[11,12,13],[21,22,23],[31,32,33]]
vec = [mat[i][j] for i, j in [(i, j) for i in range(len(mat)) for j in range(len(mat[0]))]]
nums = [1, 1.0, complex(1, 1)]
for num in nums:
print(isinstance(num, (int, float, complex)))
# True
# True
# True
print(isinstance(nums, list))
# True
from collections import namedtuple
Point = namedtuple('Point3d', 'x y z')
point = Point(10,20,30)
>>> point
Point3d(x=10, y=20, z=30)
>>> print point.x, point.y, point.z
10 20 30
>>> print point[0], point[1], point[2]
@mu-777
mu-777 / loop.cpp
Created June 18, 2015 07:44
loop.cpp
#include <iostream>
using namespace std;
int main() {
// your code goes here
for(int cnt ; true ; cnt++){
if (cnt % 10 == 0) continue;
cout<<cnt<<endl;
if (cnt > 100) break;
}
@mu-777
mu-777 / swaps.cpp
Created June 18, 2015 09:44
swaps.cpp
#include <iostream>
#include <stdio.h>
#include <conio.h>
#include <string.h>
// プロトタイプ宣言
void swap1(int x, int y);
void swap2(int* x, int* y);
void swap3(int& x, int& y);
var Q = require('q'),
defered = Q.defer(),
promise = defered.promise;
function heavyProcess(defered){
setTimeout(function(){
console.log('finish!')
defered.resolve('end')
}, 5000);
}
function makeSameDayArr(targetDay, firstDate){
var targetDates = [],
targetDate = new Date(firstDate.getFullYear(),
firstDate.getMonth(),
1.0 + (7-(firstDate.getDay()-targetDay)%7)%7);
for(;targetDate.getMonth() == firstDate.getMonth();targetDate.setDate(targetDate.getDate()+7)){
targetDates.push(new Date(targetDate));
}
return targetDates;
range.getValues().forEach(function(arr, idx, mat){
if(arr[0] == ''){
range.splice(idx);
} else {
retNameDict[arr[0]] = {name: arr[1], mailAddress: arr[2]};
}
});
#!/bin/bash
sudo rm /etc/hosts
sudo cp /etc/hosts.normal /etc/hosts
rm ~/.bashrc
cp ~/.bashrc.normal ~/.bashrc
source ~/.bashrc